{"modulePath":"github.com/AlaudaDevops/pkg","version":"v0.14.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package config\n\nPackage config stores katanomi configuration manager which watch configmap and work immediately if configmap changed\n\n## Constants\n\n```go\nconst (\n\t// PprofEnabledKey indicates the configuration key of the /debug/pprof debugging api/\n\tPprofEnabledKey = \"pprof.enabled\"\n)\n```\n\n## Functions\n\n```go\nfunc ConfigFilter(ctx context.Context, manager *Manager, configKey string, expectedKeyValueFunc ConfigKeyExpectedValueFunc) func(*restful.Request, *restful.Response, *restful.FilterChain)\n```\nConfigFilter adds a restful filter to manager to watch configmap and and custom validation according a specific key value pair.\n\n```go\nfunc ConfigFilterNotFoundWhenNotTrue(ctx context.Context, req *restful.Request, key string, value FeatureValue) (err error)\n```\nConfigFilterNotFoundWhenNotTrue is a helper ConfigKeyExpectedValue implementation that checks if the value is a boolean true value, if not true will return a standard 404 not found error\n\n```go\nfunc GetDurationConfig(ctx context.Context, key string, defaultDuration time.Duration) time.Duration\n```\nGetDurationConfig return duration configuration store in manager and return default if not exist\n\n```go\nfunc Name() string\n```\nName return config name for configuration\n\n```go\nfunc WithKatanomiConfigManager(ctx context.Context, manager *Manager) context.Context\n```\nWithKatanomiConfigManager sets a Config Manager instance into a context\n\n## Types\n\n```go\ntype Config struct {\n\tData map[string]string\n}\n```\nConfig store katanomi configuration\n\n```go\nfunc (c Config) GetBool(key string) (*bool, error)\n```\nGetBool will parse value in Config.Data\\[\"key\"] to bool if the key not exist, it will return nil if the value is not a valid bool string, it will return error\n\n```go\nfunc (c Config) GetObject(key string, object interface{}) error\n```\nGetObject will parse value in Config.Data\\[\"key\"] to object it expects the value should be yaml content\n\n```go\ntype ConfigKeyExpectedValueFunc func(ctx context.Context, req *restful.Request, key string, value FeatureValue) (err error)\n```\nConfigKeyExpectedValueFunc is a helper function to check if configmap has expected value If the value is not as expected, an error is expected to be returned\n\n```go\ntype FeatureFlags struct {\n\tData map[string]string\n}\n```\nFeatureFlags holds the features configurations\n\n```go\nfunc (f *FeatureFlags) FeatureValue(flag string) FeatureValue\n```\nFeatureValue returns the value of the implemented feature flag, or the default if not found.\n\n```go\ntype FeatureValue string\n```\nFeatureValue definition of FeatureValue feature value\n\n```go\nconst (\n\t// True represents the value \"true\" for the feature switch.\n\tTrue FeatureValue = \"true\"\n\n\t// False represents the value \"false\" for the feature switch.\n\tFalse FeatureValue = \"false\"\n\n\t// DefaultPprofEnabled stores the default value \"false\" for the \"pprof.enabled\" /debug/pprof debugging api.\n\t// If the corresponding key does not exist, the default value is returned.\n\tDefaultPprofEnabled FeatureValue = False\n)\n```\n\n```go\nfunc (f FeatureValue) AsBool() (bool, error)\n```\nAsBool returns as a Bool, or false if the conversion fails.\n\n```go\nfunc (f FeatureValue) AsDuration() (time.Duration, error)\n```\nAsBool returns as a Duration, or 0 if the conversion fails.\n\n```go\nfunc (f FeatureValue) AsInt() (int, error)\n```\nAsInt returned as an integer, or -1 if the conversion fails.\n\n```go\nfunc (f FeatureValue) String() string\n```\nString returned as a string\n\n```go\ntype HasFeatureChangedFunc func(new *FeatureFlags, old *FeatureFlags) bool\n```\nHasFeatureChangedFunc check whether the function switch of interest has changed.\n\n```go\ntype ListByFeatureFlagChanged func(ctx context.Context) []metav1.Object\n```\nListByFeatureFlagChanged when the function switch is changed, get the object function that triggers reconile.\n\n```go\ntype Manager struct {\n\tInformer watcher.DefaultingWatcherWithOnChange\n\tLogger   *zap.SugaredLogger\n\n\t*Config\n\t// contains filtered or unexported fields\n}\n```\nManager will manage katanomi configuration and store in Config\n\n```go\nfunc KatanomiConfigManager(ctx context.Context) *Manager\n```\nKatanomiConfigManager returns a Config Manager, returns nil if not found\n\n```go\nfunc NewManager(informer watcher.DefaultingWatcherWithOnChange, logger *zap.SugaredLogger, cmName string) *Manager\n```\nNewManager will instantiate a manager that watch configmap for core component configuration\n\n```go\nfunc (manager *Manager) AddWatcher(w Watcher)\n```\nAddWatcher add a watcher to manager the watcher will be called when the configmap is changed\n\n```go\nfunc (manager *Manager) GetConfig() *Config\n```\nGetConfig will return the config of manager\n\n```go\nfunc (manager *Manager) GetFeatureFlag(flag string) FeatureValue\n```\nGetFeatureFlag get the function switch data, if the function switch is not set, return the default value of the switch.\n\n```go\nfunc (manager *Manager) GetFeatureFlagByClient(ctx context.Context, flag string) FeatureValue\n```\nGetFeatureFlagByClient get the config configuration by requesting configmap from the client. prioritize the use of GetFeatureFlag, and use the current function in scenarios that require high real-time data.\n\n```go\ntype ManagerInterface interface {\n\tGetConfig() *Config\n\tGetFeatureFlag(flag string) FeatureValue\n}\n```\n\n```go\ntype WatchFunc func(*Config)\n```\nWatchFunc is the callback function for config watcher\n\n```go\ntype Watcher interface {\n\tWatch(config *Config)\n}\n```\nWatcher describes the interface for config watcher\n\n```go\nfunc NewConfigWatcher(cb WatchFunc) Watcher\n```\nNewConfigWatcher constructs a new config watcher please note that the callback should be processed quickly and should not block\n\n","path":"github.com/AlaudaDevops/pkg/config","name":"config","synopsis":"Package config stores katanomi configuration manager which watch configmap and work immediately if configmap changed","isRedistributable":true}
