Documentation
¶
Index ¶
- Constants
- func DefaultJSONMarshal(v interface{}) ([]byte, error)
- func ParseDurations(component string, args ...*DurationOpt) error
- func SetIfNotDefault(src interface{}, dest interface{})
- type ComponentConfig
- type DurationOpt
- type Manager
- func (cfg *Manager) Default() error
- func (cfg *Manager) LoadJSON(bs []byte) error
- func (cfg *Manager) LoadJSONFromFile(path string) error
- func (cfg *Manager) RegisterComponent(t SectionType, ccfg ComponentConfig)
- func (cfg *Manager) SaveJSON(path string) error
- func (cfg *Manager) Shutdown()
- func (cfg *Manager) ToJSON() ([]byte, error)
- func (cfg *Manager) Validate() error
- type Saver
- type Section
- type SectionType
Constants ¶
const ( Cluster = iota Consensus API IPFSConn State PinTracker Monitor Allocator Informer )
These are the component configuration types supported by the Manager.
Variables ¶
This section is empty.
Functions ¶
func DefaultJSONMarshal ¶
DefaultJSONMarshal produces pretty JSON with 2-space indentation
func ParseDurations ¶ added in v0.3.5
func ParseDurations(component string, args ...*DurationOpt) error
ParseDurations takes a time.Duration src and saves it to the given dst.
func SetIfNotDefault ¶
func SetIfNotDefault(src interface{}, dest interface{})
SetIfNotDefault sets dest to the value of src if src is not the default value of the type. dest must be a pointer.
Types ¶
type ComponentConfig ¶
type ComponentConfig interface {
// Returns a string identifying the section name for this configuration
ConfigKey() string
// Parses a JSON representation of this configuration
LoadJSON([]byte) error
// Provides a JSON representation of this configuration
ToJSON() ([]byte, error)
// Sets default working values
Default() error
// Allows this component to work under a subfolder
SetBaseDir(string)
// Checks that the configuration is valid
Validate() error
// Provides a channel to signal the Manager that the configuration
// should be persisted.
SaveCh() <-chan struct{}
}
The ComponentConfig interface allows components to define configurations which can be managed as part of the ipfs-cluster configuration file by the Manager.
type DurationOpt ¶ added in v0.3.5
type DurationOpt struct {
// The duration we need to parse
Duration string
// Where to store the result
Dst *time.Duration
// A variable name associated to it for helpful errors.
Name string
}
DurationOpt provides a datatype to use with ParseDurations
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager represents an ipfs-cluster configuration which bundles different ComponentConfigs object together. Use RegisterComponent() to add a component configurations to the object. Once registered, configurations will be parsed from the central configuration file when doing LoadJSON(), and saved to it when doing SaveJSON().
func NewManager ¶
func NewManager() *Manager
NewManager returns a correctly initialized Manager which is ready to accept component configurations.
func (*Manager) Default ¶
Default generates a default configuration by generating defaults for all registered components.
func (*Manager) LoadJSON ¶
LoadJSON parses configurations for all registered components, In order to work, component configurations must have been registered beforehand with RegisterComponent.
func (*Manager) LoadJSONFromFile ¶
LoadJSONFromFile reads a Configuration file from disk and parses it. See LoadJSON too.
func (*Manager) RegisterComponent ¶
func (cfg *Manager) RegisterComponent(t SectionType, ccfg ComponentConfig)
RegisterComponent lets the Manager load and save component configurations
func (*Manager) Shutdown ¶ added in v0.3.0
func (cfg *Manager) Shutdown()
Shutdown makes sure all configuration save operations are finished before returning.
type Saver ¶
type Saver struct {
BaseDir string
// contains filtered or unexported fields
}
Saver implements common functionality useful for ComponentConfigs
func (*Saver) NotifySave ¶
func (sv *Saver) NotifySave()
NotifySave signals the SaveCh() channel in a non-blocking fashion.
func (*Saver) SaveCh ¶
func (sv *Saver) SaveCh() <-chan struct{}
SaveCh returns a channel which is signaled when a component wants to persist its configuration
func (*Saver) SetBaseDir ¶
SetBaseDir is a setter for BaseDir and implements part of the ComponentConfig interface.
type Section ¶
type Section map[string]ComponentConfig
Section is a section of which stores component-specific configurations.
type SectionType ¶
type SectionType int
SectionType specifies to which section a component configuration belongs.