config

package
v0.0.0-...-b553abb Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package config, abbrev. cfg, handles the configuration and its scopes.

A configuration holds many path.Paths which contains a route, a scope and a scope ID.

A route is defined as a minimum 3 level deep string separated by a slash. For example catalog/product/enable_flat.

ScopePerm are default, website, group and store. Scope IDs are stored in the core_website, core_group or core_store tables for M1 and store_website, store_group and store for M2.

Underlying storage can be a simple in memory map (default), MySQL table core_config_data itself (package config/db) or etcd (package config/etcd) or consul (package todo) or ...

If you use any other configuration storage engine besides config/db package all values gets bi-directional automatically synchronized (todo).

Elements

The package config/element contains more detailed information.

Scope Values

To get a value from the configuration Service via any type method you have to provide a path.Path. If you use the ScopedGetter via function makeScoped() you can only provide a path.Route to the type methods String(), Int(), Float64(), etc.

The examples show the overall best practices.

Package cfgpath handles the configuration paths.

It contains two main types: Path and Route:

+-------+ +-----+ +----------+ +-----+ +----------------+
|       | |     | |          | |     | |                |
| Scope | |  /  | | Scope ID | |  /  | | Route/to/Value |
|       | |     | |          | |     | |                |
+-------+ +-----+ +----------+ +-----+ +----------------+

+                                      +                +
|                                      |                |
| <--------------+ Path +-----------------------------> |
|                                      |                |
+                                      + <- Route ----> +

Scope

A scope can only be default, websites or stores. Those three strings are defined by constants in package store/scope.

Scope ID

Refers to the database auto increment ID of one of the tables core_website and core_store for M1 and store_website plus store for M2.

Type Path

A Path contains always the scope, its scope ID and the route. If scope and ID haven't been provided they fall back to scope "default" and ID zero (0). Configuration paths are mainly used in table core_config_data.

Type Route

A route contains bytes and does not know anything about a scope or an ID. In the majority of use cases a route contains three parts to package config/element types for building a hierarchical tree structure:

element.Section.ID / element.Group.ID / element.Field.ID

To add little bit more confusion: A route can either be a short one like aa/bb/cc or a fully qualified path like

scope/scopeID/element.Section.ID/element.Group.ID/element.Field.ID

But the route always consists of a minimum of three parts.

A route can have only three groups of [a-zA-Z0-9_] characters split by '/'. The limitation to [a-zA-Z0-9_] is a M1/M2 thing and can be maybe later removed. Minimal length per part 2 characters. Case sensitive.

The route parts are used as an ID in element.Section, element.Group and element.Field types. See following text.

The following diagram shows the tree structure:

+---------+
| Section |
+---------+
|
|   +-------+
+-->+ Group |
|   +-------+
|   |
|   |    +--------+
|   +--->+ Field  |
|   |    +--------+
|   |
|   |    +--------+
|   +--->+ Field  |
|   |    +--------+
|   |
|   |    +--------+
|   +--->+ Field  |
|        +--------+
|
|   +-------+
+-->+ Group |
|   +-------+
|   |
|   |    +--------+
|   +--->+ Field  |
|   |    +--------+
|   |
|   |    +--------+
|   +--->+ Field  |
|   |    +--------+
|   |
|   |    +--------+
|   +--->+ Field  |
|        +--------+
|
http://asciiflow.com/

The three elements Section, Group and Field represents front-end configuration fields and more important default values and their permissions. A permission is of type scope.Perm and defines which of elements in which scope can be shown.

Those three elements represents the tree in function NewConfigStructure() which can be found in any package.

Unclear: Your app which includes the cs must merge all "PackageConfiguration"s into a single slice. You should submit all default values (interface config.Sectioner) to the config.Service.ApplyDefaults() function.

The JSON encoding of the three elements Section, Group and Field are intended to use on the backend REST API and for debugging and testing. Only used in non performance critical parts.package config

Index

Examples

Constants

View Source
const (
	EventOnBeforeSet uint8 = iota // must start with zero
	EventOnAfterSet
	EventOnBeforeGet
	EventOnAfterGet
)

Event constants defines where and when a specific blocking event gets dispatched. The concrete value of a constant may change without notice.

View Source
const CSVColumnSeparator = ','

CSVColumnSeparator separates CSV values. Default value.

View Source
const DefaultOSEnvVariableName = `CS_ENV`

DefaultOSEnvVariableName default name of the OS environment variable.

View Source
const EnvNamePlaceHolder = `{CS_ENV}`

EnvNamePlaceHolder replaces in a file name or pattern argument applied to a WithFiles, WithFile or WithGlob function with the current environment name of *config.Service. You can load environment dependent configuration files.

View Source
const PathLevels = 3

PathLevels defines how many parts are at least in a path. Like a/b/c for 3 parts. And 5 for a fully qualified path.

View Source
const PathSeparator = '/'

PathSeparator used in the database table core_config_data and in config.Service to separate the path parts.

Variables

This section is empty.

Functions

func MakeEvent

func MakeEvent(name string) (event uint8, err error)

MakeEvent creates a new validated event from one of the four possible event names: before_set, before_get, after_set and after_get.

Types

type FakeService

type FakeService struct {

	// GetFn can be set optionally. If set then Storage will be ignored.
	// Must return a guaranteed non-nil Value.
	GetFn func(p *Path) (v *Value)

	SubscribeFn      func(string, MessageReceiver) (subscriptionID int, err error)
	SubscribeInvokes int32
	// contains filtered or unexported fields
}

FakeService used for testing. Contains functions which will be called in the appropriate methods of interface Getter. Field DB has precedence over the applied functions.

func NewFakeService

func NewFakeService(s Storager) *FakeService

NewFakeService creates a new mocked Service for testing usage. Initializes a simple in memory key/value storage.

func (*FakeService) AllInvocations

func (s *FakeService) AllInvocations() invocations

AllInvocations returns all called paths and increases the counter for duplicated paths.

func (*FakeService) Get

func (s *FakeService) Get(p *Path) *Value

Get looks up a configuration value for a given path.

func (*FakeService) Invokes

func (s *FakeService) Invokes() invocations

Invokes returns statistics about invocations

func (*FakeService) Scoped

func (s *FakeService) Scoped(websiteID, storeID int64) Scoped

Scoped creates a new ScopedReader which uses the underlying mocked paths and values.

func (*FakeService) Subscribe

func (s *FakeService) Subscribe(path string, mr MessageReceiver) (subscriptionID int, err error)

Subscribe returns the before applied SubscriptionID and SubscriptionErr Does not start any underlying Goroutines.

type FakeWrite

type FakeWrite struct {
	// WriteError gets always returned by FakeWrite
	WriteError error
	// ArgPath will be set after calling write to export the config path.
	// Values you enter here will be overwritten when calling FakeWrite
	ArgPath string
	// ArgValue contains the written data
	ArgValue []byte
}

FakeWrite used for testing when writing configuration values. deprecated no replacement

func (*FakeWrite) Set

func (w *FakeWrite) Set(p *Path, value []byte) error

Set writes to a black hole, may return an error

type Field

type Field struct {
	// ID unique ID and NOT merged with others. 3rd and final part of the path.
	ID string
	// ConfigRoute if provided defines the storage path and overwrites the path from
	// section.id + group.id + field.id. ConfigRoute can be nil.
	ConfigRoute string `json:",omitempty"`
	// Type is used for the front end on how to display a Field
	Type FieldType `json:",omitempty"`
	// Label a short label of the field
	Label string `json:",omitempty"`
	// Comment can contain HTML
	Comment string `json:",omitempty"`
	// Tooltip used for frontend and can contain HTML
	Tooltip string `json:",omitempty"`
	// SortOrder in ascending order
	SortOrder int `json:",omitempty"`
	// Visible used for configuration settings which are not exposed to the user.
	Visible bool `json:",omitempty"`
	// CanBeEmpty only used in HTML forms for multiselect fields
	CanBeEmpty bool `json:",omitempty"`
	// Scopes defines the max allowed scope. Some paths or values can only act
	// on default, website or store scope. So perm checks if the provided
	// path has a scope equal or lower than defined in perm.
	Scopes scope.Perm `json:",omitempty"`
	// Default can contain any default config value: float64, int64, string,
	// bool. An empty string is equal to NULL. A default gets requests if the
	// value for a path cannot be retrieved from Level1 or Level2 storage.
	Default string `json:",omitempty"`
}

Field contains the final path element of a configuration. Includes several options.

func (*Field) Update

func (f *Field) Update(new *Field) *Field

Update applies the data from the new Field to the old field and returns the updated Field. Only non-empty values will be copied and byte slices gets cloned. The returned Field allows modifications.

type FieldMeta

type FieldMeta struct {
	Events [eventMaxCount]observers
	// Route defines the route or storage key, e.g.: customer/address/prefix_options
	Route string
	// WriteScopePerm sets the permission to allow setting values to this route.
	// For example WriteScopePerm equals scope.PermStore can be set from
	// default, website and store. If you restrict WriteScopePerm to
	// scope.PermDefault, the route and its value can only be set from default
	// but not from websites or stores. It is only allowed to set WriteScopePerm
	// when ScopeID is zero or scope.DefaultTypeID.
	WriteScopePerm scope.Perm
	// ScopeID defines the scope ID for which a default value is valid. Scope
	// type can only contain three scopes (default,websites or stores). ID
	// relates to the corresponding website or store ID.
	ScopeID      scope.TypeID
	Default      string
	DefaultValid bool
	// contains filtered or unexported fields
}

FieldMeta sets meta data for a field into the config.Service object. The meta data defines scope access restrictions and default values for different scopes. Intermediate type for function WithFieldMeta

type FieldType

type FieldType uint8

FieldType used in constants to define the frontend and input type

const (
	TypeButton FieldType = iota + 1 // must be + 1 because 0 is not set
	TypeCustom
	TypeLabel
	TypeHidden
	TypeImage
	TypeObscure
	TypeMultiselect
	TypeSelect
	TypeText
	TypeTextarea
	TypeTime
	TypeDuration
	TypeZMaximum
)

Type* defines the type of the front end user input/display form

func (FieldType) MarshalJSON

func (i FieldType) MarshalJSON() ([]byte, error)

MarshalJSON implements marshaling into a human readable string. @todo UnMarshal

func (FieldType) String

func (i FieldType) String() string

type Fields

type Fields []*Field

Fields contains a set of Fields, the final configuration value.

func MakeFields

func MakeFields(fs ...*Field) Fields

MakeFields wrapper to create a new Fields

func (Fields) Append

func (fs Fields) Append(f ...*Field) Fields

Append adds *Field (variadic) to the Fields. Not thread safe.

func (Fields) Find

func (fs Fields) Find(id string) (_ *Field, index int)

Find returns a Field pointer or index is -1 if field not found. Route must be a single part. E.g. if you have path "a/b/c" route would be in this case "c". 2nd argument int contains the slice index of the field.

func (Fields) Len

func (fs Fields) Len() int

func (Fields) Less

func (fs Fields) Less(i, j int) bool

func (Fields) Merge

func (fs Fields) Merge(fields ...*Field) Fields

Merge copies the data from a Field into this slice and returns the new slice. Appends if ID is not found in this slice otherwise overrides struct fields if not empty. Not thread safe.

func (Fields) Sort

func (fs Fields) Sort() Fields

Sort convenience helper. Not thread safe.

func (Fields) Swap

func (fs Fields) Swap(i, j int)

type Group

type Group struct {
	// ID unique ID and merged with others. 2nd part of the path.
	ID      string
	Label   string `json:",omitempty"`
	Comment string `json:",omitempty"`
	// Scopes: bit value eg: showInDefault="1" showInWebsite="1" showInStore="1"
	Scopes    scope.Perm `json:",omitempty"`
	SortOrder int        `json:",omitempty"`

	HelpURL  string `json:",omitempty"`
	MoreURL  string `json:",omitempty"`
	DemoLink string `json:",omitempty"`

	Fields Fields `json:",omitempty"`
}

Group defines the layout of a group containing multiple Fields.

type Groups

type Groups []*Group

Groups contains a set of Groups.

func MakeGroups

func MakeGroups(gs ...*Group) Groups

MakeGroups wrapper function, for now.

func (Groups) Find

func (gs Groups) Find(id string) (_ *Group, index int)

Find returns a Group pointer or index -1 if group not found. Route must be a single part. E.g. if you have path "a/b/c" route would be in this case "b".

func (Groups) Len

func (gs Groups) Len() int

func (Groups) Less

func (gs Groups) Less(i, j int) bool

func (Groups) Merge

func (gs Groups) Merge(groups ...*Group) Groups

Merge copies the data from a groups into this slice and returns the new slice. Appends if ID is not found in this slice otherwise overrides struct fields if not empty. Not thread safe.

func (Groups) Sort

func (gs Groups) Sort() Groups

Sort convenience helper. Not thread safe.

func (Groups) Swap

func (gs Groups) Swap(i, j int)

type LoadDataOption

type LoadDataOption struct {
	// contains filtered or unexported fields
}

LoadDataOption allows other storage backends to pump their data into the config.Service during or after initialization via an OS signal and hot reloading.

func MakeLoadDataOption

func MakeLoadDataOption(fn func(*Service) error) LoadDataOption

MakeLoadDataOption a wrapper helper function.

func WithApplySections

func WithApplySections(sections ...*Section) LoadDataOption

WithApplySections sets the default values and permissible scopes for specific routes. This function option cannot handle a default value for a specific website/store scope. Storage level and sort order are not supported. Because of using FieldMeta, it supports hierarchical fall back to the parent scope for default values.

func WithFieldMeta

func WithFieldMeta(fms ...*FieldMeta) LoadDataOption

WithFieldMeta sets immutable default values and scope restrictions into the service for specific routes. Storage level and sort order are not supported. FieldMeta data gets only set once. Reloading is not possible. Synchronous version.

func WithFieldMetaGenerator

func WithFieldMetaGenerator(fmGenerator func(*Service) (<-chan *FieldMeta, <-chan error)) LoadDataOption

WithFieldMetaGenerator sets immutable default values and scope restrictions into the service for specific routes. Storage level and sort order are not supported. FieldMeta data gets only set once. Reloading is not possible. Supports hierarchical fall back to the parent scope for default values. See cfgfile.WithLoadFieldMetaYAML to load this data via a YAML file. This functional options supports stream based processing. fmGenerator function must close both channels once the process finishes.

func (LoadDataOption) WithSortOrder

func (o LoadDataOption) WithSortOrder(sortOrderPosition int) LoadDataOption

WithSortOrder sets the order/position while loading the data in config.Service.

func (LoadDataOption) WithUseStorageLevel

func (o LoadDataOption) WithUseStorageLevel(level int) LoadDataOption

WithUseStorageLevel executes the current Load function in storage level one. Argument level can either be 1 or 2. Any other integer value falls back to 2, for now.

type MessageReceiver

type MessageReceiver interface {
	// MessageConfig when a configuration value will be written this function
	// gets called to allow you to listen to changes. Path is never empty. Path
	// may contains up to three levels. For more details see the Subscriber
	// interface of this package. If an error will be returned, the subscriber
	// gets unsubscribed/removed.
	MessageConfig(Path) error
}

MessageReceiver allows you to listen to write actions. The order of calling each subscriber is totally random. If a subscriber panics, it gets securely removed without crashing the whole system. This interface should be implemented in other packages. The Subscriber interface requires the MessageReceiver interface.

type Observer

type Observer interface {
	// Observe must always return the rawData argument or an error.
	// Observer can transform and modify the raw data in any case.
	Observe(p Path, rawData []byte, found bool) (newRawData []byte, err error)
}

Observer gets called when an event gets dispatched. Not all events support modifying the raw data argument. For example the EventOnAfterGet allows to decrypt encrypted data. Or check if some one is allowed to read or write a special path with its value. Or validate data for correctness.

type ObserverRegisterer

type ObserverRegisterer interface {
	RegisterObserver(event uint8, route string, eo Observer) error
	DeregisterObserver(event uint8, route string) error
}

ObserverRegisterer adds or removes observers for different events and theirs routes. Extracted for testability in other packages. Type *Service implements this interface.

type Options

type Options struct {
	// Level1 defines a usually short lived cached like an LRU or TinyLFU or a
	// storage with un-resetble data (locked data). It can be set optionally.
	// Level1 only gets called for Set operation when a value is requested in
	// Level2 via Get.
	Level1       Storager
	Log          log.Logger
	EnablePubSub bool
	// OSEnvVariableName loads a string from an applied environment variable to
	// use it as a prefix for the Path type and when loading configuration files
	// as part of their filename or path (see cfgfile.EnvNamePlaceHolder). For
	// example different payment gateways and access credentials for a payment
	// method on STAGING or PRODUCTION systems.
	OSEnvVariableName string
	// EnvName defines the current name of the environment directly instead of
	// loading it from an operating system environment variable. It gets used as
	// a prefix for the Path type or as part of the directory or filename when
	// loading configuration files (see cfgfile.EnvNamePlaceHolder).
	EnvName string

	// EnableHotReload if the Service receives an OS signal, it triggers a hot
	// reload of the cached functions of type LoadDataOption. Errors during hot
	// reloading do not trigger an exit of the config.Service.
	EnableHotReload bool
	// HotReloadSignals specifies custom signals to listen to. Defaults to
	// syscall.SIGUSR2
	HotReloadSignals []os.Signal
}

Options applies configurations to the NewService function. Used mainly by external packages for providing different storage engines.

type Path

type Path struct {

	// ScopeID a route is bound to this Scope and its ID.
	ScopeID scope.TypeID

	// UseEnvSuffix if enabled the Path has environment awareness. An
	// environment comes from the *Service type and defines for example
	// PRODUCTION, TEST, CI or STAGING. The final path will use this suffix to
	// distinguish between the environments. Environment awareness should be
	// added to Paths for e.g. payment credentials or order export access data.
	// Paths which are marked for environment awareness must have stored their
	// values for each environment. For example: a route can be
	// carriers/dhl/password and an integration has three environments set:
	// PRD,TEST,DEV. The final paths for the default value would be:
	//		default/0/carriers/dhl/password/PRD
	//		default/0/carriers/dhl/password/TEST
	//		default/0/carriers/dhl/password/DEV
	// The path for PRD can also be default/0/carriers/dhl/password when there
	// would be no OS environment variable present.
	UseEnvSuffix bool

	// Expires defines a time when a key becomes inactive and hence expires. The
	// expiration is only supported when writing a value via interface
	// Setter.Set. The same path can have different expiration dates and values.
	// This feature depends on the underlying storage engine.
	Expires time.Time
	// contains filtered or unexported fields
}

Path represents a configuration path bound to a scope. A Path is not safe for concurrent use. Bind* method receivers always return a new copy of a path.

Example
package main

import (
	"fmt"

	"github.com/corestoreio/pkg/config"
	"github.com/corestoreio/pkg/store/scope"
)

func main() {
	p := config.MustNewPath("system/smtp/host")

	fmt.Println(p.String())
	fmt.Println(p.BindWebsite(1).String())
	// alternative way
	fmt.Println(p.BindWebsite(1).String())

	fmt.Println(p.BindStore(3).String())
	// alternative way
	fmt.Println(p.BindStore(3).String())
	// Group is not supported and falls back to default
	fmt.Println(p.Bind(scope.Group.WithID(4)).String())

	p, err := config.NewPath("system/smtp/host")
	if err != nil {
		fmt.Printf("%s\n", err)
	}
	fmt.Println(p.String())

	routes := config.MustNewPath("dev/css/merge_css_files")
	rs, err := routes.Split()
	if err != nil {
		fmt.Printf("%s\n", err)
	}
	fmt.Println("dev/css/merge_css_files => ", rs[0], rs[1], rs[2])

}
Output:

default/0/system/smtp/host
websites/1/system/smtp/host
websites/1/system/smtp/host
stores/3/system/smtp/host
stores/3/system/smtp/host
default/0/system/smtp/host
default/0/system/smtp/host
dev/css/merge_css_files =>  dev css merge_css_files

func MustNewPath

func MustNewPath(route string) *Path

MustNewPath same as NewPath but panics on error.

func MustNewPathWithScope

func MustNewPathWithScope(scp scope.TypeID, route string) *Path

MustNewPathWithScope creates a new validate Path with a custom scope but panics on error. E.g. invalid path.

func NewPath

func NewPath(route string) (*Path, error)

NewPath makes a new validated Path. Scope is assigned to Default.

func NewPathWithScope

func NewPathWithScope(scp scope.TypeID, route string) (*Path, error)

NewPathWithScope creates a new validate Path with a custom scope.

func (*Path) AppendFQ

func (p *Path) AppendFQ(buf *bytes.Buffer) error

AppendFQ validates the Path and appends it to the buffer.

func (Path) Bind

func (p Path) Bind(s scope.TypeID) *Path

Bind binds a path to a new scope with its scope ID. Returns a new Path pointer and does not apply the changes to the current Path. Fluent API design.

func (Path) BindDefault

func (p Path) BindDefault() *Path

BindDefault binds a path to the default scope. Returns a new Path pointer and does not apply the changes to the current Path. Convenience helper function. Fluent API design.

func (Path) BindStore

func (p Path) BindStore(id int64) *Path

BindStore binds a path to a store scope and its ID. Returns a new Path pointer and does not apply the changes to the current Path. Convenience helper function. Fluent API design.

func (Path) BindWebsite

func (p Path) BindWebsite(id int64) *Path

BindWebsite binds a path to a website scope and its ID. Returns a new Path pointer and does not apply the changes to the current Path. Convenience helper function. Fluent API design.

func (*Path) Equal

func (p *Path) Equal(b *Path) bool

Equal compares the scope and the route

func (*Path) EqualRoute

func (p *Path) EqualRoute(b *Path) bool

EqualRoute compares only the route.

func (Path) ExpireIn

func (p Path) ExpireIn(d time.Duration) Path

ExpireIn sets the current time with the default time zone and adds the duration. It returns a copy of the path with the new expiration value.

func (*Path) FQ

func (p *Path) FQ() (string, error)

FQ returns the fully qualified route. Safe for further processing of the returned byte slice. If scope is equal to scope.DefaultID and ID is not zero then ID gets set to zero. Error behaviour: NotValid, Empty or WriteFailed

func (*Path) Hash64

func (p *Path) Hash64() uint64

Hash64 computes the HighwayHash-64 checksum of data. Returns zero in case of an error. Usage as map key.

func (*Path) Hash64ByLevel

func (p *Path) Hash64ByLevel(depth int) uint64

Hash64ByLevel same as Level() but returns a HighwayHash-64 checksum of data. Usage as map key.

func (*Path) IsEmpty

func (p *Path) IsEmpty() bool

IsEmpty returns true if the underlying route is empty.

func (*Path) IsValid

func (p *Path) IsValid() error

IsValid checks for valid configuration path. Returns nil on success. Configuration path attribute can have only three groups of [a-zA-Z0-9_] characters split by '/'. Minimal length per part 2 characters. Case sensitive.

Error behaviour: NotValid or Empty

func (*Path) Level

func (p *Path) Level(depth int) (string, error)

Level returns a hierarchical based route depending on the depth. The depth argument defines the depth of levels to be returned. Depth 1 will return the first part like "a", Depth 2 returns "a/b" Depth 3 returns "a/b/c" and so on. Level -1 gives you all available levels. Does generate a fully qualified path.

func (*Path) MarshalBinary

func (p *Path) MarshalBinary() (data []byte, err error)

MarshalBinary implements interface encoding.BinaryMarshaler.

func (*Path) MarshalText

func (p *Path) MarshalText() (text []byte, err error)

MarshalText implements interface encoding.TextMarshaler.

func (Path) NewValue

func (p Path) NewValue(data []byte) *Value

NewValue creates a new value with an assigned path. Guarantees not to return nil.

func (*Path) Parse

func (p *Path) Parse(routeOrFQPath string) (err error)

Parse takes a route or a fully qualified path and splits it into its parts with final validation. Input: stores/5/catalog/frontend/list_allow_all or just catalog/frontend/list_allow_all to use default scope.

=>
	scope: 		stores
	scopeID: 	5
	route: 		catalog/frontend/list_allow_all

Zero allocations to memory. Useful to reduce allocations by reusing Path pointer because it calls internally Reset.

func (*Path) ParseStrings

func (p *Path) ParseStrings(scp, id, route string) error

ParseStrings parses the arguments into a valid path. scp must be a valid scope string as defined in stores/scope package. id must be a stringified uint value.

func (*Path) Part

func (p *Path) Part(pos int) (string, error)

Part returns the route part on the desired position. The Route gets validated before extracting the part. Does not run Validate()

Have Route: general/single_store_mode/enabled
Pos<1 => ErrIncorrectPosition
Pos=1 => general
Pos=2 => single_store_mode
Pos=3 => enabled
Pos>3 => ErrIncorrectPosition

The returned Route slice is owned by Path. For further modifications you must copy it via Route.Copy().

func (*Path) Reset

func (p *Path) Reset() *Path

Reset sets all fields to the zero value for pointer reuse.

func (*Path) RouteHasPrefix

func (p *Path) RouteHasPrefix(route string) bool

RouteHasPrefix returns true if the Paths' route starts with the argument route

func (*Path) ScopeRoute

func (p *Path) ScopeRoute() (scope.TypeID, string)

ScopeRoute returns the assigned scope and its ID and the route.

func (*Path) Separators

func (p *Path) Separators() (count int)

Separators returns the number of separators

func (*Path) Split

func (p *Path) Split(ret ...string) (_ []string, err error)

Split splits the route into its three parts and appends it to the slice `ret`. Does not run Validate() Example:

routes := cfgpath.MakeRoute("aa/bb/cc")
rs, err := routes.Split()
rs[0].String() == "aa"
rs[1].String() == "bb"
rs[2].String() == "cc"

Error behaviour: NotValid

func (*Path) String

func (p *Path) String() string

String returns a fully qualified path. Errors get logged if debug mode is enabled. String starts with `[config] Error:` on error. Error behaviour: NotValid, Empty or WriteFailed

func (*Path) UnmarshalBinary

func (p *Path) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes input bytes into a valid Path. Implements encoding.BinaryUnmarshaler.

func (*Path) UnmarshalText

func (p *Path) UnmarshalText(txt []byte) error

UnmarshalText transforms the text into a route with performed validation checks. Implements encoding.TextUnmarshaler. Error behaviour: NotValid, Empty.

func (*Path) WithEnvSuffix

func (p *Path) WithEnvSuffix() *Path

WithEnvSuffix enables that this Path has environment awareness. An environment comes from the *Service type and defines for example PRODUCTION, TEST, CI or STAGING. The final path will use this prefix to distinguish between the environments. Environment awareness should be added to Paths for e.g. payment credentials or order export access data.

type PathSlice

type PathSlice []*Path

PathSlice represents a collection of Paths

func (PathSlice) Contains

func (ps PathSlice) Contains(p *Path) bool

Contains return true if the Path p can be found within the slice. It must match ID, Scope and Route.

func (PathSlice) Len

func (ps PathSlice) Len() int

func (PathSlice) Less

func (ps PathSlice) Less(i, j int) bool

Less sorts by scope, id and route

func (PathSlice) Sort

func (ps PathSlice) Sort()

Sort is a convenience method to sort stable.

func (PathSlice) Swap

func (ps PathSlice) Swap(i, j int)

type Route

type Route string

Route defines a string with at least two Separators denoting a route to the configuration value in a hierarchical manner. A Route does not contain any information about a scope. The purpose of Route should be to transfer a constant string later into a type Path.

func (Route) Bind

func (r Route) Bind(s scope.TypeID) *Path

Bind creates a new Path and binds it to a new scope with its scope ID.

func (Route) BindDefault

func (r Route) BindDefault() *Path

BindDefault creates a new Path and binds it to the default scope.

func (Route) BindStore

func (r Route) BindStore(id int64) *Path

BindStore creates a new Path and binds it to a store scope and its ID.

func (Route) BindWebsite

func (r Route) BindWebsite(id int64) *Path

BindWebsite creates a new Path and binds it to a website scope and its ID.

func (Route) IsValid

func (r Route) IsValid() error

IsValid returns an error if the route is not valid.

func (Route) Separators

func (r Route) Separators() (count int)

Separators returns the number of separators

func (Route) String

func (r Route) String() string

String implements fmt.Stringer

type Scoped

type Scoped struct {
	// contains filtered or unexported fields
}

Scoped is equal to Getter but not an interface and the underlying implementation takes care of providing the correct scope: default, website or store and bubbling up the scope chain from store -> website -> default if a value won't get found in the desired scope. The Path for each primitive type represents always a path like "section/group/element" without the scope string and scope ID.

To restrict bubbling up you can provide a second argument scope.Scope. You can restrict a configuration path to be only used with the default, website or store scope. See the examples. This second argument will mainly be used by the cfgmodel package to use a defined scope in a config.Structure. If you access the ScopedGetter from a store.Store, store.Website type the second argument must already be internally pre-filled.

WebsiteID and StoreID must be in a relation like enforced in the database tables via foreign keys. Empty storeID triggers the website scope. Empty websiteID and empty storeID are triggering the default scope.

func (Scoped) Get

func (ss Scoped) Get(restrictUpTo scope.Type, route string) (v *Value)

Get traverses through the scopes store->website->default to find a matching byte slice value. The argument `restrictUpTo` scope.Type restricts the bubbling. For example a path gets stored in all three scopes but argument `restrictUpTo` specifies only website scope, then the store scope will be ignored for querying. If argument `restrictUpTo` has been set to zero aka. scope.Absent, then all three scopes are considered for querying. Returns a guaranteed non-nil Value.

func (Scoped) IsValid

func (ss Scoped) IsValid() bool

IsValid checks if the object has been set up correctly.

func (Scoped) ParentID

func (ss Scoped) ParentID() scope.TypeID

ParentID tells you the parent underlying scope and its ID. Store falls back to website and website falls back to default.

func (Scoped) ScopeID

func (ss Scoped) ScopeID() scope.TypeID

ScopeID tells you the current underlying scope and its ID to which this configuration has been bound to.

func (Scoped) ScopeIDs

func (ss Scoped) ScopeIDs() scope.TypeIDs

ScopeIDs returns the hierarchical order of the scopes containing ScopeID() on position zero and ParentID() on position one. This function guarantees that the returned slice contains at least two entries.

type Scoper

type Scoper interface {
	Scoped(websiteID, storeID int64) Scoped
}

Scoper creates a hierarchy based configuration retriever based on website and its store ID. Scoper gets used in other packages to attach the config.Service type or mocked version of it.

type Section

type Section struct {
	// ID unique ID and merged with others. 1st part of the path.
	ID    string
	Label string `json:",omitempty"`
	// Scopes: bit value eg: showInDefault="1" showInWebsite="1" showInStore="1"
	// Scopes can contain multiple Scope but no more than Default, Website and
	// Store.
	Scopes    scope.Perm `json:",omitempty"`
	SortOrder int        `json:",omitempty"`
	// Resource TODO some kind of ACL if someone has the right to view,access and/or modify.
	Resource uint   `json:",omitempty"`
	Groups   Groups `json:",omitempty"`
}

Section defines the layout for the configuration section which contains groups and fields. Thread safe for reading but not for modifying.

type Sections

type Sections []*Section

Sections contains a set of Sections. Some nifty helper functions exists. Thread safe for reading. A section slice can be used in many goroutines. It must remain lock-free.

func MakeSections

func MakeSections(s ...*Section) Sections

MakeSections wrapper function, for now.

func MakeSectionsMerged

func MakeSectionsMerged(sections ...*Section) (Sections, error)

MakeSectionsMerged creates a new validated Sections with a three level configuration. Before validation, slices are all merged together. Panics if a path is redundant. Only use this function if your package elements really has duplicated entries.

func MakeSectionsValidated

func MakeSectionsValidated(sections ...*Section) (Sections, error)

MakeSectionsValidated creates a new validated Sections with a three level configuration.

func MustMakeSectionsMerged

func MustMakeSectionsMerged(sections ...*Section) Sections

MustMakeSectionsMerged same as MakeSectionsMerged but panics on error.

func MustMakeSectionsValidate

func MustMakeSectionsValidate(sections ...*Section) Sections

MustMakeSectionsValidate same as MakeSectionsValidated but panics on error.

func (Sections) Append

func (ss Sections) Append(s ...*Section) Sections

Append adds 0..n Section. Not thread safe.

func (Sections) AppendFields

func (ss Sections) AppendFields(r string, fs ...*Field) (_ Sections, index int)

AppendFields adds 0..n *Fields. Path must have at least two path parts like a/b more path parts gets ignored. Returns as index the new length of the FieldSlice or a negative value on error.

func (Sections) Find

func (ss Sections) Find(id string) (_ *Section, index int)

Find returns a Section pointer or -1 if section not found. Route must be a single part. E.g. if you have path "a/b/c" route would be in this case "a". 2nd return parameter contains the position of the Section within the Sections or -1 if not found.

func (Sections) FindField

func (ss Sections) FindField(r string) (_ *Field, index int)

FindField searches for a field using all path segments. Route must have the format a/b/c. 2nd return parameter contains the position of the Field within the FieldSlice of a Section/Group or -1 if not found.

func (Sections) FindGroup

func (ss Sections) FindGroup(r string) (_ *Group, index int)

FindGroup searches for a group using the first two path segments. Route must have the format a/b/c. 2nd return parameter contains the position of the Group within the GroupSlice of a Section or -1 if not found.

func (Sections) Len

func (ss Sections) Len() int

func (Sections) Less

func (ss Sections) Less(i, j int) bool

func (Sections) Merge

func (ss Sections) Merge(sections ...*Section) Sections

Merge merges n Sections into the current slice. Behaviour for duplicates: Last item wins. Not thread safe.

func (Sections) MergeMultiple

func (ss Sections) MergeMultiple(sSlices ...Sections) Sections

MergeMultiple merges n SectionSlices into the current slice. Behaviour for duplicates: Last item wins. Not thread safe.

func (Sections) Sort

func (ss Sections) Sort() Sections

Sort convenience helper. Not thread safe.

func (Sections) SortAll

func (ss Sections) SortAll() Sections

SortAll recursively sorts all slices. Not thread safe.

func (Sections) Swap

func (ss Sections) Swap(i, j int)

func (Sections) TotalFields

func (ss Sections) TotalFields() (fs int)

TotalFields calculates the total amount of all fields

func (Sections) UpdateField

func (ss Sections) UpdateField(r string, nf *Field) (index int)

UpdateField searches for a field using all three path segments and updates the found field with the new field data. Returns the field position within the GroupSlice or a negative index in case a route part can't be found.

func (Sections) Validate

func (ss Sections) Validate() error

Validate checks for duplicated configuration paths in all three hierarchy levels. Error behaviour: NotValid

type Service

type Service struct {
	Log log.Logger
	// contains filtered or unexported fields
}

Service main configuration provider. Please use the NewService() function. Safe for concurrent use. Allows multi level storage backend for e.g. LRU cache or immutable data. Hot reloading enables a devops engineer to apply new configuration changes via kill signal.

Example
package main

import (
	"fmt"

	"github.com/corestoreio/pkg/config"
	"github.com/corestoreio/pkg/config/storage"
)

func main() {
	// We focus here on type String() other primitive types are of course also available.
	p := config.MustNewPath("scope/test/string") // panics on incorrect argument.

	// Default storage engine with build-in in-memory map.
	// the NewService gets only instantiated once during app start up.
	configSrv := config.MustNewService(storage.NewMap(), config.Options{})

	// now add some configuration values with different scopes.
	// normally these config values will be loaded from the core_config_data table
	// via function ApplyCoreConfigData()
	// The scope is default -> website (ID 3) -> group (ID 1) -> store (ID 2).
	// The IDs are picked randomly here. Group config values are officially not
	// supported, but we do ;-)

	// scope default:
	if err := configSrv.Set(p, []byte("DefaultGopher")); err != nil {
		fmt.Printf("Write Error: %s", err)
		return
	}

	// scope website. The number 3 is made up and comes usually from DB table
	// (M1) core_website or (M2) store_website.
	if err := configSrv.Set(p.BindWebsite(3), []byte("WebsiteGopher")); err != nil {
		fmt.Printf("Write Error: %s", err)
		return
	}

	// scope store. The number 2 is made up and comes usually from DB table
	// (M1) core_store or (M2) store.
	if err := configSrv.Set(p.BindStore(2), []byte("StoreGopher")); err != nil {
		fmt.Printf("Write Error: %s", err)
		return
	}

	// Default Scope1
	val, ok, err := configSrv.Get(p.BindDefault()).Str()
	if err != nil {
		fmt.Printf("srvString Error: %s", err)
		return
	}
	fmt.Println("Scope1:", ok, val)

	// Website Scope2
	val, ok, err = configSrv.Get(p.BindWebsite(3)).Str()
	if err != nil {
		fmt.Printf("srvString Error: %s", err)
		return
	}
	fmt.Println("Scope2:", ok, val)

	// Store Scope3
	val, ok, err = configSrv.Get(p.BindStore(2)).Str()
	if err != nil {
		fmt.Printf("srvString Error: %s", err)
		return
	}
	fmt.Println("Scope3:", ok, val)

	// Store Scope4
	_, ok, err = configSrv.Get(p.BindStore(3)).Str() // different scope ID
	if err != nil {
		fmt.Printf("Scope4a: srvString Error: %s\n", err)
		fmt.Printf("Scope4b: srvString Error: %v\n", err) // Use %+v to show the full route! :-)
	}
	fmt.Printf("Scope4: Is Key ok: %t\n", ok)

}
Output:

Scope1: true DefaultGopher
Scope2: true WebsiteGopher
Scope3: true StoreGopher
Scope4: Is Key ok: false

func MustNewService

func MustNewService(level2 Storager, o Options, fns ...LoadDataOption) *Service

MustNewService same as NewService but panics on error. Use only in testing or during boot process.

func NewService

func NewService(level2 Storager, o Options, fns ...LoadDataOption) (s *Service, err error)

NewService creates the main new configuration for all scopes: default, website and store. Default Storage is a simple map[string]interface{}. A new go routine will be startet for the publish and subscribe feature. Level2 is the required underlying data holding provider.

func (*Service) Close

func (s *Service) Close() error

Close closes and terminates the internal goroutines and connections.

func (*Service) DeregisterObserver

func (s *Service) DeregisterObserver(event uint8, route string) error

DeregisterObserver removes all observers for a specific route or route prefix. Event argument is one of the constants starting with `EventOn...`.

func (*Service) EnvName

func (s *Service) EnvName() string

EnvName returns the environment name to which this service is bound to.

func (*Service) Flush

func (s *Service) Flush() error

Flush flushes the internal caches. Write operation also flushes the entry for the given key. If a Storage service implements

type flusher interface {
	Flush() error
}

then it can flush its internal caches.

func (*Service) Get

func (s *Service) Get(p *Path) (v *Value)

Get returns a configuration value from the Service, ignoring the scope hierarchy/fallback logic using a direct match. Safe for concurrent use. Example usage:

// Default Scope
dp := config.MustNewPath("general/locale/timezone")

// Website Scope
// 3 for example comes from store_website database table
ws := dp.Bind(scope.WebsiteID, 3)

// Store Scope
// 6 for example comes from store database table
ss := p.Bind(scope.StoreID, 6)

It queries first the Level1 cache, if not found, then Level2. If the value cannot be found eventually it accesses the default configuration and tries to get the value. If path meta data has been set, it checks also the permission if a path is allowed to access a specific scope.

Returns a guaranteed non-nil value.

func (*Service) RegisterObserver

func (s *Service) RegisterObserver(event uint8, route string, eo Observer) error

RegisterObserver appends a blocking observer for a route or route prefix. Multiple observers can be added to a route. Event argument is one of the constants starting with `EventOn...`.

func (*Service) ReplaceEnvName

func (s *Service) ReplaceEnvName(str string) string

ReplaceEnvName replaces the occurrence of the value of constant EnvNamePlaceHolder with the current configured environment name. If no environment name has been defined it returns the argument unchanged.

func (*Service) Scoped

func (s *Service) Scoped(websiteID, storeID int64) Scoped

Scoped creates a new scope base configuration reader which has the implemented fall back hierarchy.

func (*Service) Set

func (s *Service) Set(p *Path, v []byte) (err error)

Set puts a value back into the Service. Safe for concurrent use. Example usage:

// Default Scope
p, err := config.MakeByString("currency/option/base") // or use config.MustMakeByString( ... )
err := Write(p, "USD")

// Website Scope
// 3 for example comes from core_website/store_website database table
err := Write(p.Bind(scope.WebsiteID, 3), "EUR")

// Store Scope
// 6 for example comes from core_store/store database table
err := Write(p.Bind(scope.StoreID, 6), "CHF")

func (*Service) Subscribe

func (s *Service) Subscribe(path string, mr MessageReceiver) (subscriptionID int, err error)

Subscribe adds an asynchronous Subscriber to be called when a write event happens. See interface Subscriber for a detailed description. Path can be any kind of level and can contain StrScope and Scope ID. Valid paths can be for example:

  • StrScope/ID/currency/options/base
  • StrScope/ID/currency/options
  • StrScope/ID/currency
  • currency/options/base
  • currency/options
  • currency

Events are running asynchronously.

func (*Service) Unsubscribe

func (s *Service) Unsubscribe(subscriptionID int) error

Unsubscribe removes a subscriber with a specific ID.

type Setter

type Setter interface {
	// Write writes a configuration entry and may return an error
	Set(p *Path, value []byte) error
}

Setter thread safe storing of configuration values under different paths and scopes.

type Storager

type Storager interface {
	// Set sets a key with a value and returns on success nil or
	// ErrKeyOverwritten, on failure any other error
	Setter
	// Get returns the raw value `v` on success and sets `found` to true
	// because the value has been found. If the value cannot be found for the
	// desired path, return value `found` must be false. A nil value `v`
	// indicates also a value and hence `found` is true, if found.
	Get(p *Path) (v []byte, found bool, err error)
}

Storager is the underlying data storage for holding the keys and its values. Implementations can be spf13/viper or MySQL backed. Default Storager is a simple mutex protected in memory map[string]string. Storager must be safe for concurrent use.

type Subscriber

type Subscriber interface {
	// Subscribe subscribes a MessageReceiver to a fully qualified path. Path
	// allows you to filter to which path or part of a path you would like to
	// listen. A path can be e.g. "system/smtp/host" to receive messages by
	// single host changes or "system/smtp" to receive message from all smtp
	// changes or "system" to receive changes for all paths beginning with
	// "system". A path is equal to a topic in a PubSub system. Path cannot be
	// empty means you cannot listen to all changes. Returns a unique identifier
	// for the Subscriber for later removal, or an error.
	Subscribe(fqPath string, mr MessageReceiver) (subscriptionID int, err error)
}

Subscriber represents the overall service to receive subscriptions from MessageReceiver interfaces. This interface is at the moment only implemented by the config.Service.

type Value

type Value struct {

	// Path optionally assigned to, to know to which path a value belongs to and to
	// provide different converter behaviour.
	Path Path
	// CSVColumnSep defines the CSV column separator, default a comma.
	CSVReader *csv.Reader
	CSVComma  rune
	// contains filtered or unexported fields
}

Value represents an immutable value returned from the configuration service. A value is meant to be only for reading and not safe for concurrent use.

Example

ExampleValue shows how to use the Value type to convert the raw byte slice value to the appropriate final type.

package main

import (
	"fmt"

	"github.com/corestoreio/pkg/config"
	"github.com/corestoreio/pkg/config/storage"
	"github.com/corestoreio/pkg/store/scope"
)

func panicIfErr(errs ...error) {
	for _, err := range errs {
		if err != nil {
			panic(fmt.Sprintf("%+v", err))
		}
	}
}

func main() {
	// Default storage engine with build-in in-memory map.
	// the NewService gets only instantiated once during app start up.
	configSrv := config.MustNewService(storage.NewMap(), config.Options{})

	const (
		routeCountries      = "carriers/freeshipping/specificcountry"
		routeListingCount   = "catalog/frontend/list_per_page_values"
		routeCookieLifetime = "web/cookie/cookie_lifetime"
	)

	routesVals := []struct {
		route string
		data  string
	}{
		{routeCountries, `CH,LI,DE`},
		{routeListingCount, `5,10,15,20,25`},
		{routeCookieLifetime, `7200s`},
	}
	p := new(config.Path)
	for _, pv := range routesVals {
		panicIfErr(
			p.Parse(pv.route),
			configSrv.Set(p, []byte(pv.data)),
		)
	}

	// This instance of makeScoped gets created somewhere deep in the program.
	// The numbers 1 and 2 are chosen here randomly.
	scpd := configSrv.Scoped(1, 2)
	cntryVal := scpd.Get(scope.Default, routeCountries)

	countries, err := cntryVal.Strs()
	panicIfErr(err)
	fmt.Printf("%s: %#v\n", routeCountries, countries)
	fmt.Printf("%s: %q\n", routeCountries, cntryVal.UnsafeStr())

	listingCount, err := scpd.Get(scope.Default, routeListingCount).Ints()
	panicIfErr(err)
	fmt.Printf("%s: %#v\n", routeListingCount, listingCount)

	keksLifetime, ok, err := scpd.Get(scope.Default, routeCookieLifetime).Duration()
	panicIfErr(err)
	fmt.Printf("%s: found: %t %#v\n", routeCookieLifetime, ok, keksLifetime)

}
Output:

carriers/freeshipping/specificcountry: []string{"CH", "LI", "DE"}
carriers/freeshipping/specificcountry: "CH,LI,DE"
catalog/frontend/list_per_page_values: []int{5, 10, 15, 20, 25}
web/cookie/cookie_lifetime: found: true 7200000000000

func NewValue

func NewValue(data []byte) *Value

NewValue makes a new non-pointer value type.

func (*Value) Bool

func (v *Value) Bool() (val bool, ok bool, err error)

Bool converts the underlying converted data into the final type.

func (*Value) CSV

func (v *Value) CSV(ret ...[]string) (_ [][]string, err error)

CSV reads a multiline CSV data value and appends it to ret.

func (*Value) ConstantTimeCompare

func (v *Value) ConstantTimeCompare(data []byte) bool

ConstantTimeCompare compares in a constant time manner data with the underlying value retrieved from the config service. Useful for passwords and other hashes.

func (*Value) Duration

func (v *Value) Duration() (d time.Duration, ok bool, err error)

Duration converts the underlying converted data into the final type. Uses internally time.ParseDuration

func (*Value) Equal

func (v *Value) Equal(v2 *Value) bool

Equal compares if current object is fully equal to v2 object. Path and data must be equal. Nil safe.

func (*Value) EqualData

func (v *Value) EqualData(v2 *Value) bool

EqualData compares if the data part of the current value is equal to v2. Nil safe. Does not use constant time for byte comparison, not secure for passwords.

func (*Value) Error

func (v *Value) Error() string

Error implements error interface and returns the last error.

func (*Value) Float64

func (v *Value) Float64() (val float64, ok bool, err error)

Float64 converts the underlying converted data into the final type.

func (*Value) Float64s

func (v *Value) Float64s(ret ...float64) (_ []float64, err error)

Float64s splits the converted data using the CSVComma and appends it to `ret`.

func (*Value) Int

func (v *Value) Int() (val int, ok bool, err error)

Int converts the underlying converted data into the final type.

func (*Value) Int64

func (v *Value) Int64() (_ int64, ok bool, err error)

Int64 converts the underlying converted data into the final type.

func (*Value) Int64s

func (v *Value) Int64s(ret ...int64) (_ []int64, err error)

Int64s converts the underlying byte slice into an int64 slice using v.CSVComma as a separator. The result gets append to argument `ret`.

func (*Value) Ints

func (v *Value) Ints(ret ...int) (_ []int, err error)

Ints converts the underlying byte slice into an int64 slice using v.CSVComma as a separator. The result gets append to argument `ret`.

func (*Value) IsEmpty

func (v *Value) IsEmpty() bool

IsEmpty returns true when its length is equal to zero.

func (*Value) IsEqual

func (v *Value) IsEqual(d []byte) bool

IsEqual does a constant time comparison of the underlying data with the input data `d`. Useful for passwords. Only equal when no error occurs.

func (*Value) IsValid

func (v *Value) IsValid() bool

IsValid returns the last error or in case when a Path is really not valid, returns an error with kind NotValid.

func (*Value) Str

func (v *Value) Str() (_ string, ok bool, err error)

Str returns the underlying value as a string. Ok is true when data slice bytes are not nil. Whereas function String implements fmt.Stringer and returns something different.

func (*Value) String

func (v *Value) String() string

String implements fmt.Stringer and returns the textual representation and Go syntax escaped of the underlying data. It might print the error in the string.

func (*Value) Strs

func (v *Value) Strs(ret ...string) (_ []string, err error)

Strs splits the converted data using the CSVComma and appends it to `ret`.

func (*Value) Time

func (v *Value) Time() (t time.Time, ok bool, err error)

Time parses a MySQL/MariaDB like time format: "2006-01-02 15:04:05.999999999 07:00" up to 35 places supports. Minimal format must be a year, e.g. 2006. time.UTC location gets used.

func (*Value) Times

func (v *Value) Times(ret ...time.Time) (t []time.Time, err error)

Times same as Time but parses the CSVComma separated list.

func (*Value) Uint64

func (v *Value) Uint64() (_ uint64, ok bool, err error)

Uint64 converts the underlying converted data into the final type.

func (*Value) Uint64s

func (v *Value) Uint64s(ret ...uint64) (_ []uint64, err error)

Uint64s converts the underlying byte slice into an int64 slice using v.CSVComma as a separator. The result gets append to argument `ret`.

func (*Value) UnmarshalBinaryTo

func (v *Value) UnmarshalBinaryTo(tu encoding.BinaryUnmarshaler) error

UnmarshalBinaryTo wrapper to use encoding.BinaryUnmarshaler for decoding the binary bytes. Useful for custom types.

func (*Value) UnmarshalTextTo

func (v *Value) UnmarshalTextTo(tu encoding.TextUnmarshaler) error

UnmarshalTextTo wrapper to use encoding.TextUnmarshaler for decoding the textual bytes. Useful for custom types.

func (*Value) UnmarshalTo

func (v *Value) UnmarshalTo(fn func([]byte, interface{}) error, vPtr interface{}) (err error)

UnmarshalTo decodes the value into the final type. vPtr must be a pointer. The function signature for `fn` matches e.g. json.Unmarshal, xml.Unmarshal and many others.

func (*Value) UnsafeBool

func (v *Value) UnsafeBool() (val bool)

UnsafeBool same as Bool but ignores errors.

func (*Value) UnsafeDuration

func (v *Value) UnsafeDuration() (d time.Duration)

UnsafeDuration same as Duration but ignores all errors.

func (*Value) UnsafeFloat64

func (v *Value) UnsafeFloat64() (val float64)

UnsafeFloat64 same as Float64 but ignores errors.

func (*Value) UnsafeInt

func (v *Value) UnsafeInt() (val int)

UnsafeInt same as Int but ignores all errors.

func (*Value) UnsafeInt64

func (v *Value) UnsafeInt64() (val int64)

UnsafeInt64 same as Int64 but ignores all errors

func (*Value) UnsafeStr

func (v *Value) UnsafeStr() (s string)

UnsafeStr same as Str but ignores errors.

func (*Value) UnsafeTime

func (v *Value) UnsafeTime() (t time.Time)

UnsafeTime same as Time but ignores all errors.

func (*Value) UnsafeUint64

func (v *Value) UnsafeUint64() (val uint64)

UnsafeUint64 same as Uint64 but ignores all errors.

func (*Value) WriteTo

func (v *Value) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the converted raw data to w. WriterTo is the interface that wraps the WriteTo method.

WriteTo writes data to w until there's no more data to write or when an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

Directories

Path Synopsis
Package deprecated source provides a slice type for handling config sources to be used in config/models.
Package deprecated source provides a slice type for handling config sources to be used in config/models.
Package observer provides validators and modifiers for configuration values.
Package observer provides validators and modifiers for configuration values.
Package storage provides the available storage engines for level 1 and level 2 caches.
Package storage provides the available storage engines for level 1 and level 2 caches.

Jump to

Keyboard shortcuts

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