github.com/searKing/golang/go@v1.2.117/log/slog/value.go (about)

     1  // Copyright 2023 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package slog
     6  
     7  import "log/slog"
     8  
     9  // isEmptyGroup reports whether v is a group that has no attributes.
    10  func isEmptyGroup(v slog.Value) bool {
    11  	if v.Kind() != slog.KindGroup {
    12  		return false
    13  	}
    14  	// We do not need to recursively examine the group's Attrs for emptiness,
    15  	// because GroupValue removed them when the group was constructed, and
    16  	// groups are immutable.
    17  	return len(v.Group()) == 0
    18  }
    19  
    20  // countEmptyGroups returns the number of empty group values in its argument.
    21  func countEmptyGroups(as []slog.Attr) int {
    22  	n := 0
    23  	for _, a := range as {
    24  		if isEmptyGroup(a.Value) {
    25  			n++
    26  		}
    27  	}
    28  	return n
    29  }