Documentation ¶
Index ¶
- Constants
- Variables
- type ChangeType
- type ConfigChangedHandler
- type ConfigFile
- func (cf *ConfigFile) AddChangeHandler(handler ConfigChangedHandler) HandlerID
- func (cf *ConfigFile) AddPriorityChangeHandler(handler ConfigChangedHandler, priority int) HandlerID
- func (cf *ConfigFile) Delete() error
- func (cf *ConfigFile) Exists() (bool, error)
- func (cf *ConfigFile) Path() string
- func (cf *ConfigFile) Read() ([]byte, error)
- func (cf *ConfigFile) Refresh() ([]byte, error)
- func (cf *ConfigFile) RemoveAllHandlers()
- func (cf *ConfigFile) RemoveChangeHandler(id HandlerID) bool
- func (cf *ConfigFile) Stat() (*storage.StorageInfo, error)
- func (cf *ConfigFile) Write(data []byte) error
- type ConfigFileManager
- type ConfigFileManagerOpts
- type HandlerID
Constants ¶
const DefaultHandlerPriority int = 1000
DefaultHandlerPriority is used as the priority for any handlers added via AddChangeHandler
Variables ¶
var NoBackingStore error = errors.New("Backing storage does not exist.")
NoBackingStore error is used when the config file's backing storage is missing
Functions ¶
This section is empty.
Types ¶
type ChangeType ¶
type ChangeType string
ChangeType is used to specifically categorize the change that was made on a ConfigFile
const ( ChangeTypeCreated ChangeType = "created" ChangeTypeModified ChangeType = "modified" ChangeTypeDeleted ChangeType = "deleted" )
ChangeType constants contain the different types of updates passed through the ConfigChangedHandler
type ConfigChangedHandler ¶
type ConfigChangedHandler func(ChangeType, []byte)
ConfigChangedHandler is the func handler used to receive change updates about the config file. Both ChangeTypeCreated and ChangeTypeModified yield a valid []byte, while ChangeTypeDeleted yields a nil []byte.
type ConfigFile ¶
type ConfigFile struct {
// contains filtered or unexported fields
}
ConfigFile is representation of a configuration file that can be written to, read, and watched for updates
func NewConfigFile ¶
func NewConfigFile(store storage.Storage, file string) *ConfigFile
NewConfigFile creates a new ConfigFile instance using a specific storage.Storage and path relative to the storage.
func (*ConfigFile) AddChangeHandler ¶
func (cf *ConfigFile) AddChangeHandler(handler ConfigChangedHandler) HandlerID
AddChangeHandler accepts a ConfigChangedHandler function which will be called whenever the implementation detects that a change has been made. A unique HandlerID is returned that can be used to remove the handler if necessary.
func (*ConfigFile) AddPriorityChangeHandler ¶
func (cf *ConfigFile) AddPriorityChangeHandler(handler ConfigChangedHandler, priority int) HandlerID
AddPriorityChangeHandler allows adding a config change handler with a specific priority. By default, any handlers added via AddChangeHandler have a default priority of 1000. The lower the priority, the sooner in the handler execution it will be called.
func (*ConfigFile) Delete ¶
func (cf *ConfigFile) Delete() error
Delete removes the file from storage permanently.
func (*ConfigFile) Exists ¶
func (cf *ConfigFile) Exists() (bool, error)
Exists returns true if the file exist. If an error other than a NotExist error is returned, the result will be false with the provided error.
func (*ConfigFile) Path ¶
func (cf *ConfigFile) Path() string
Path returns the fully qualified path of the config file.
func (*ConfigFile) Read ¶
func (cf *ConfigFile) Read() ([]byte, error)
Read will read the binary data from the file and return it. If an error is returned, the byte array will be nil.
func (*ConfigFile) Refresh ¶
func (cf *ConfigFile) Refresh() ([]byte, error)
Refresh allows external callers to force reload the config file from internal storage. This is particularly useful when there exist no change listeners on the config, which would prevent the data cache from automatically updating on change
func (*ConfigFile) RemoveAllHandlers ¶
func (cf *ConfigFile) RemoveAllHandlers()
RemoveAllHandlers removes all added handlers
func (*ConfigFile) RemoveChangeHandler ¶
func (cf *ConfigFile) RemoveChangeHandler(id HandlerID) bool
RemoveChangeHandler removes the change handler with the provided identifier if it exists. True is returned if the handler was removed (it existed), false otherwise.
func (*ConfigFile) Stat ¶
func (cf *ConfigFile) Stat() (*storage.StorageInfo, error)
Stat returns the StorageStats for the file.
func (*ConfigFile) Write ¶
func (cf *ConfigFile) Write(data []byte) error
Write will write the binary data to the file.
type ConfigFileManager ¶
type ConfigFileManager struct {
// contains filtered or unexported fields
}
ConfigFileManager is a fascade for a central API used to create and watch config files.
func NewConfigFileManager ¶
func NewConfigFileManager(opts *ConfigFileManagerOpts) *ConfigFileManager
NewConfigFileManager creates a new backing storage and configuration file manager
func (*ConfigFileManager) ConfigFileAt ¶
func (cfm *ConfigFileManager) ConfigFileAt(path string) *ConfigFile
ConfigFileAt returns an existing configuration file for the provided path if it exists. Otherwise, a new instance is created and returned. Note that the path does not have to exist in order for the instance to be created. It can exist as a potential file path on the storage, and be written to later
type ConfigFileManagerOpts ¶
type ConfigFileManagerOpts struct { // BucketStoreConfig is the local file location for the configuration used to // write and read configuration data to/from the bucket. The format of this // configuration file should be compatible with storage.NewBucketStorage BucketStoreConfig string // LocalConfigPath provides a backup location for storing the configuration // files LocalConfigPath string }
ConfigFileManagerOpts describes how to configure the ConfigFileManager for serving configuration files
func DefaultConfigFileManagerOpts ¶
func DefaultConfigFileManagerOpts() *ConfigFileManagerOpts
DefaultConfigFileManagerOpts returns the default configuration options for the config file manager
func (*ConfigFileManagerOpts) IsBucketStorageEnabled ¶
func (cfmo *ConfigFileManagerOpts) IsBucketStorageEnabled() bool
IsBucketStorageEnabled returns true if bucket storage is enabled.