Documentation ¶
Index ¶
- Variables
- func Get(name string, parameters map[string]interface{}) (bool, error)
- func Init(m map[string]*Feature)
- func InitFromFile(path string) error
- func ParseType(s string) (featurepb.Feature_Type, error)
- func RegisterServer(s *grpc.Server)
- func Watch(ctx context.Context, path string) error
- type Feature
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidFeature = errors.New("invalid feature spec") ErrNoFeature = errors.New("no such feature") ErrUnknownFeatureType = errors.New("unknown feature type") )
var ErrEmptyConfig = errors.New("empty config file")
Functions ¶
func InitFromFile ¶
func ParseType ¶
func ParseType(s string) (featurepb.Feature_Type, error)
ParseType converts a string into a featurepb.Feature_Type enum, returning an error if the lowercased input name is not in the enum mapping.
func RegisterServer ¶
RegisterServer adds the global feature server instance to the given gRPC server.
func Watch ¶
Watch watches the given path for changes and reloads the global feature config.
In reality, Watch watches the directory of the given path, rather than the actual filepath, to handle cases where the file is deleted. Filesystem events in that directory unrelated to the particular filepath are ignored.
When the config path is modified, Watch uses InitFromFile to read the file, ensure it is non-empty, unmarshal it from json, and validate the feature specs before swapping in the config.
The watch continues until the watcher closes either the Events or Errors channels, or until the context is cancelled or expired.
Types ¶
type Feature ¶
Feature wraps an underlying Feature protobuf message.
func (*Feature) IsEnabled ¶
IsEnabled returns whether the given feature is enabled. It returns an error either if the feature has an unknown type, or if it is an EXPRESSION feature and an error was encountered during expression evaluation.
This function is equivalent to calling f.IsEnabledForParameters(nil).
func (*Feature) IsEnabledForParameters ¶
IsEnabled returns whether the given feature is enabled for the given parameters. It returns an error either if the feature has an unknown type, or if it is an EXPRESSION feature and an error was encountered during expression evaluation.
func (*Feature) MarshalJSON ¶
MarshalJSON implements json.Marshaler for Feature. It marshals only the underlying protobuf message.
func (*Feature) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler for Feature. It unmarshals the underlying protobuf message, and, if the Feature is an EXPRESSION type, parses the expression string as well.