github.com/grafana/pyroscope@v1.18.0/pkg/util/fieldcategory/overrides.go (about)

     1  // SPDX-License-Identifier: AGPL-3.0-only
     2  
     3  package fieldcategory
     4  
     5  import "fmt"
     6  
     7  type Category int
     8  
     9  const (
    10  	// Basic is the basic field category, and the default if none is defined.
    11  	Basic Category = iota
    12  	// Advanced is the advanced field category.
    13  	Advanced
    14  	// Experimental is the experimental field category.
    15  	Experimental
    16  )
    17  
    18  func (c Category) String() string {
    19  	switch c {
    20  	case Basic:
    21  		return "basic"
    22  	case Advanced:
    23  		return "advanced"
    24  	case Experimental:
    25  		return "experimental"
    26  	default:
    27  		panic(fmt.Sprintf("Unknown field category: %d", c))
    28  	}
    29  }
    30  
    31  // Fields are primarily categorized via struct tags, but this can be impossible when third party libraries are involved
    32  // Only categorize fields here when you can't otherwise, since struct tags are less likely to become stale
    33  var overrides = map[string]Category{}
    34  
    35  func AddOverrides(o map[string]Category) {
    36  	for n, c := range o {
    37  		overrides[n] = c
    38  	}
    39  }
    40  
    41  func GetOverride(fieldName string) (category Category, ok bool) {
    42  	category, ok = overrides[fieldName]
    43  	return
    44  }
    45  
    46  func VisitOverrides(f func(name string)) {
    47  	for override := range overrides {
    48  		f(override)
    49  	}
    50  }