feature

package
v0.0.0-...-4655955 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFeature     = errors.New("invalid feature spec")
	ErrNoFeature          = errors.New("no such feature")
	ErrUnknownFeatureType = errors.New("unknown feature type")
)
View Source
var ErrEmptyConfig = errors.New("empty config file")

Functions

func Get

func Get(name string, parameters map[string]interface{}) (bool, error)

Get returns whether a feature is enabled or not.

func Init

func Init(m map[string]*Feature)

func InitFromFile

func InitFromFile(path string) error

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

func RegisterServer(s *grpc.Server)

RegisterServer adds the global feature server instance to the given gRPC server.

func Watch

func Watch(ctx context.Context, path string) error

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

type Feature struct {
	*featurepb.Feature
	// contains filtered or unexported fields
}

Feature wraps an underlying Feature protobuf message.

func (*Feature) IsEnabled

func (f *Feature) IsEnabled() (bool, error)

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

func (f *Feature) IsEnabledForParameters(parameters map[string]interface{}) (bool, error)

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

func (f *Feature) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Feature. It marshals only the underlying protobuf message.

func (*Feature) UnmarshalJSON

func (f *Feature) UnmarshalJSON(data []byte) error

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.

func (*Feature) Validate

func (f *Feature) Validate() (bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL