Documentation ¶
Index ¶
- Constants
- Variables
- func BoolValue(key string) (val bool, err error)
- func BoolValueD(key string, defaultVal bool) bool
- func Dump() map[string]string
- func FromKey(key string) (typ, name string)
- func HasValue(key string) bool
- func IntValue(key string) (val int, err error)
- func IntValueD(key string, defaultVal int) int
- func Key(typ, name string) string
- func Objects() map[string]Object
- func ReloadObjects()
- func Value(key string) (string, error)
- func ValueD(key, defaultVal string) string
- func WithObject(descr Descriptor)
- type CfgFile
- type Descriptor
- type Endpoint
- func (e *Endpoint) Fields() map[string]string
- func (e *Endpoint) Get(field string) (val string, err error)
- func (e *Endpoint) GetClientTLSConfig() (*tls.Config, error)
- func (e *Endpoint) GetServerTLSConfig() (*tls.Config, error)
- func (e *Endpoint) GrpcClientConn(ctx context.Context, options ...grpc.DialOption) (*grpc.ClientConn, error)
- func (e *Endpoint) GrpcServerListener(allInterfaces bool, options ...grpc.ServerOption) (*grpc.Server, net.Listener, error)
- func (e *Endpoint) HTTPClientConnInfo(name string) (client *http.Client, u url.URL, err error)
- func (e *Endpoint) HTTPServerListener(allInterfaces bool) (*http.Server, net.Listener, error)
- func (e *Endpoint) Set(field, val string) error
- func (e *Endpoint) Type() string
- func (e *Endpoint) UseTLS() bool
- func (e *Endpoint) Write(name string, w io.Writer)
- type GenericObject
- type Object
- type ObjectStore
- type ProfileFile
- type XvalProvider
Constants ¶
const TpEndpoint = "EP"
TpEndpoint is the type name for an endpoint
Variables ¶
var EndpointDescr = &epDescriptor{}
EndpointDescr contains the description of the endpoint
Functions ¶
func BoolValueD ¶ added in v1.0.1
BoolValueD return values as bool, or return defaultVal, if it doesn't exist
func ReloadObjects ¶
func ReloadObjects()
ReloadObjects reloads objects based on the current external values
func ValueD ¶ added in v1.0.1
ValueD retrieves a value. If it doesn't exist it will returen defaultVal instead
func WithObject ¶
func WithObject(descr Descriptor)
WithObject adds support for a specific object type.
Types ¶
type Descriptor ¶
type Descriptor interface { Construct() Object Type() string // "EP" Fields() []string // "ADDRESS", "TLS" }
The Descriptor interface is used to marshal/unmarshal objects via key/values
func GenericObjectDescriptor ¶
func GenericObjectDescriptor( Type string, Fields []string) Descriptor
GenericObjectDescriptor generates a ObjectDescriptor for a generic type object.
type Endpoint ¶
type Endpoint struct { Address string `yaml:"address"` TLS string `yaml:"tls,omitempty"` // Empty is no TLS ServerCACert string `yaml:"server_ca_cert,omitempty"` ServerCert string `yaml:"server_cert,omitempty"` ServerKey string `yaml:"server_key,omitempty"` ClientCACert string `yaml:"client_ca_cert,omitempty"` ClientCert string `yaml:"client_cert,omitempty"` ClientKey string `yaml:"client_key,omitempty"` Path string `yaml:"path,omitempty"` }
Endpoint is either side of a client-server connection
func GetEndpoint ¶
GetEndpoint retrieves and endpoint from the external context
func (*Endpoint) GetClientTLSConfig ¶ added in v1.0.1
GetClientTLSConfig returns a *tls.Config suitable for a server We need the following values from the endpoint - TLS=[none|server|mtls] - ServerCACert=[file|string|"external"] - ClientCertificate=[file|string] - ClientPrivateKey=[file|string]
func (*Endpoint) GetServerTLSConfig ¶ added in v1.0.1
GetServerTLSConfig returns a *tls.Config suitable for a server We need the following values from the endpoint - TLS=[none|server|mtls] - ServerCertificate=[file|string] - ServerPrivateKey=[file|string] - ClientCACert=[file|string]
func (*Endpoint) GrpcClientConn ¶
func (e *Endpoint) GrpcClientConn(ctx context.Context, options ...grpc.DialOption) (*grpc.ClientConn, error)
GrpcClientConn creates a client grpc connection to the endpoint
func (*Endpoint) GrpcServerListener ¶
func (e *Endpoint) GrpcServerListener(allInterfaces bool, options ...grpc.ServerOption) (*grpc.Server, net.Listener, error)
GrpcServerListener creates a grpc server and listener on the endpoint
func (*Endpoint) HTTPClientConnInfo ¶ added in v1.0.1
HTTPClientConnInfo creates a client and an url, which the user can use to setup the client connection to the server.
func (*Endpoint) HTTPServerListener ¶ added in v1.0.1
HTTPServerListener creates a http.Server and a net.Listener to be used by a http server.
...
ep,_ := xvals.GetEndpoint("my_endpoint") server,listener,_ := ep.HTTPServerListener(true) server.Handler = http.NotFoundHandler() server.Serve(listener)
...
type GenericObject ¶
type GenericObject struct {
// contains filtered or unexported fields
}
GenericObject provides a default implementation for objects. It can be used for all objects that has no need for a formal go struct as base for the type.
func (*GenericObject) Fields ¶
func (o *GenericObject) Fields() map[string]string
Fields returns all fields of the object with their values
func (*GenericObject) Get ¶
func (o *GenericObject) Get(field string) (value string, err error)
Get returns the value of a field
func (*GenericObject) Set ¶
func (o *GenericObject) Set(key, val string) error
Set the value of a field
func (*GenericObject) Type ¶
func (o *GenericObject) Type() string
Type returns the type of the object
type Object ¶
type Object interface { Type() string Fields() map[string]string Get(field string) (value string, err error) Set(field, val string) error }
Object is the interface all supported objects must implement. It is described by a Descriptor, which is used to generate the object.
A field is defined by a key in the format:
<TYPE>_<NAME>_<FIELD>=<VALUE> <---- KEY ---->
An Object is made up of the sum of it's keys.
type ObjectStore ¶
type ObjectStore struct {
// contains filtered or unexported fields
}
An ObjectStore is a storage where objects described according can be stored. It uses xvals and descriptors to extract the keys/values that are used to build the objects.
func NewObjectStore ¶
func NewObjectStore() *ObjectStore
NewObjectStore creates a new store for objects.
func (*ObjectStore) AddDescriptor ¶
func (c *ObjectStore) AddDescriptor(descriptor Descriptor)
AddDescriptor lets the store use a new descriptor for objects.
func (*ObjectStore) Get ¶
func (c *ObjectStore) Get(typ, name string) (Object, error)
Get an object based on type and name
func (*ObjectStore) New ¶
func (c *ObjectStore) New(typ, name string) (Object, error)
New creates a new Object based on type name and object name
func (*ObjectStore) Objects ¶
func (c *ObjectStore) Objects() map[string]Object
Objects returns the objects known to the store.
func (*ObjectStore) Reload ¶
func (c *ObjectStore) Reload(kv map[string]string)
Reload the store from the set of key/values
type ProfileFile ¶ added in v1.0.3
type XvalProvider ¶
type XvalProvider interface { // Get Value or error Value(key string) (val string, err error) // Dump all values from the source Dump() map[string]string // Reload the values from the source // In case of an error, the variables will simply not be available // An error message should be logged in that case. Reload() }
XvalProvider is the interface all providers of values must implement
func WithConfigFile ¶
func WithConfigFile(filename string) XvalProvider
WithConfigFile adds a config file to the xval context. More than one file can be added. First added file has highest priority. Last added least priority.
func WithEnvironment ¶
func WithEnvironment() XvalProvider
WithEnvironment adds environmental variables to the xval context. Will panic in case of errors
func WithMap ¶
func WithMap(src map[string]string) XvalProvider
WithMap adds a map to the xval context.
func WithProfile ¶ added in v1.0.3
func WithProfile(profileFilePath string) XvalProvider
WithProfile adds a file that has a one or several profiles, which of one is the current profile. Each profile is a mapProvider