Documentation
¶
Index ¶
- func CombineJSONFiles(files fs.FS) ([]byte, error)
- func CombineTOMLFiles(files fs.FS) ([]byte, error)
- func InitConfig(a any) error
- type Getter
- type Registry
- type Scope
- type Setting
- func Duration(defaultValue time.Duration) Setting[time.Duration]
- func Float32(defaultValue float32) Setting[float32]
- func Float64(defaultValue float64) Setting[float64]
- func Int(defaultValue int) Setting[int]
- func Int16(defaultValue int16) Setting[int16]
- func Int32(defaultValue int32) Setting[int32]
- func Int64(defaultValue int64) Setting[int64]
- func Int8(defaultValue int8) Setting[int8]
- func MarshaledText[T encoding.TextUnmarshaler](defaultValue T) Setting[T]
- func NewSetting[T any](defaultValue T, parse func(string) (T, error)) Setting[T]
- func Rate(defaultLimit rate.Limit, defaultBurst int) Setting[config.Rate]
- func Size(defaultValue config.Size) Setting[config.Size]
- func URL(defaultValue *url.URL) Setting[*url.URL]
- func Uint16(defaultValue uint16) Setting[uint16]
- func Uint32(defaultValue uint32) Setting[uint32]
- func Uint64(defaultValue uint64) Setting[uint64]
- func Uint8(defaultValue uint8) Setting[uint8]
- type Update
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CombineJSONFiles ¶
CombineJSONFiles reads a set of JSON config files and combines them in to one file. The expected inputs are:
- global.json
- org/*.json
- owner/*.json
- workflow/*.json
The directory and file names translate to keys in the JSON structure, while the file extensions are discarded. For example: owner/0x1234.json:Foo.Bar becomes owner.0x1234.Foo.Bar
func CombineTOMLFiles ¶
CombineTOMLFiles reads a set of TOML config files and combines them in to one file. The expected inputs are:
- global.toml
- org/*.toml
- owner/*.toml
- workflow/*.toml
The directory and file names translate to keys in the TOML structure, while the file extensions are discarded. For example: owner/0x1234.toml:Foo.Bar becomes owner.0x1234.Foo.Bar
func InitConfig ¶
InitConfig accepts a pointer to a config struct and iterates over all the fields, initializing any Setting fields with a full-qualified, dot-separated key. Every field must either be a Setting or a nested struct following the same rules.
Types ¶
type Getter ¶
type Getter interface {
// GetScoped returns the value for key, including checking for any Scope based overrides up to scope.
// The tenant for each scope is based on the contexts.CRE in the ctx.
GetScoped(ctx context.Context, scope Scope, key string) (value string, err error)
}
Getter fetches scoped settings by key.
func NewJSONGetter ¶
NewJSONGetter returns a static Getter backed by the given JSON. TODO https://smartcontract-it.atlassian.net/browse/CAPPL-775 NewJSONRegistry with polling & subscriptions
func NewTOMLGetter ¶
NewTOMLGetter returns a static Getter backed by the given TOML. TODO https://smartcontract-it.atlassian.net/browse/CAPPL-775 NewTOMLRegistry with polling & subscriptions
type Registry ¶
type Registry interface {
Getter
// SubscribeScoped returns a channel for updates as an efficient alternative to polling.
// Stop must be closed to terminate the subscription.
SubscribeScoped(ctx context.Context, scope Scope, key string) (updates <-chan Update[string], stop func())
}
Registry extends Getter with subscriptions.
type Scope ¶
type Scope int
Scope represents the levels at which settings can be overridden and applied.
func ParseScope ¶
func (Scope) IsTenantRequired ¶
type Setting ¶
type Setting[T any] struct { Key string DefaultValue T Scope Scope Parse func(string) (T, error) `json:"-" toml:"-"` Unit string }
Setting holds a key, default value, and parsing function for a particular setting. Use Setting.GetOrDefault with a Getter to look up settings. Use Setting.Subscribe with a Registry to have updates pushed over a channel.
func MarshaledText ¶
func MarshaledText[T encoding.TextUnmarshaler](defaultValue T) Setting[T]
func (*Setting[T]) GetOrDefault ¶
GetOrDefault gets the setting from the Getter for the given Scope, or returns the default value with an error.
func (Setting[T]) MarshalText ¶
func (*Setting[T]) UnmarshalText ¶ added in v0.9.4
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cresettings contains configurable settings definitions for nodes in the CRE.
|
Package cresettings contains configurable settings definitions for nodes in the CRE. |
|
Package limits helps enforce request-scoped, multi-tenant limits with three kinds of Limiter:
|
Package limits helps enforce request-scoped, multi-tenant limits with three kinds of Limiter: |