rigel

package module
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 8 Imported by: 2

README

Rigel

Remiges Rigel is a product which helps application administrators to manage configuration parameters and their values for one or more live applications.

This repository contains the source code for the Rigel server, client library for Go and the command line interface called rigelctl.

It uses etcd as a backend storage for configuration parameters and their values.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfKeyPath added in v0.12.0

func GetConfKeyPath(appName string, moduleName string, version int, namedConfig string, confKey string) string

GetConfKeyPath constructs the path for a configuration based on the provided appName, moduleName, version, namedConfig, and confKey.

func GetConfPath added in v0.12.0

func GetConfPath(appName string, moduleName string, version int, namedConfig string) string

GetConfPath constructs the path for a configuration based on the provided appName, moduleName and version.

func GetSchemaDescriptionPath added in v0.12.0

func GetSchemaDescriptionPath(appName string, moduleName string, version int) string

getSchemaDescriptionPath constructs the path for a schema based on the provided appName, moduleName and version.

func GetSchemaFieldsPath added in v0.12.0

func GetSchemaFieldsPath(appName string, moduleName string, version int) string

GetSchemaFieldsPath constructs the path for a schema based on the provided appName, moduleName and version.

func GetSchemaPath added in v0.12.0

func GetSchemaPath(appName string, moduleName string, version int) string

GetSchemaPath constructs the base key for a schema in etcd based on the provided appName, moduleName and version.

func ValidateValueAgainstConstraints added in v0.12.0

func ValidateValueAgainstConstraints(value string, field *types.Field) bool

Types

type InMemoryCache added in v0.9.0

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

func NewInMemoryCache added in v0.9.0

func NewInMemoryCache() *InMemoryCache

func (*InMemoryCache) Delete added in v0.9.0

func (c *InMemoryCache) Delete(key string)

func (*InMemoryCache) Get added in v0.9.0

func (c *InMemoryCache) Get(key string) (value string, found bool)

func (*InMemoryCache) Set added in v0.9.0

func (c *InMemoryCache) Set(key string, value string)

type KeyNotFoundError added in v0.9.0

type KeyNotFoundError struct {
	Key string
}

func (*KeyNotFoundError) Error added in v0.9.0

func (e *KeyNotFoundError) Error() string

type Rigel

type Rigel struct {
	Storage types.Storage
	Cache   types.Cache
	App     string
	Module  string
	Version int
	Config  string
	// contains filtered or unexported fields
}

Rigel represents a client for Rigel configuration manager server.

func Default added in v0.8.0

func Default() (*Rigel, error)

Default creates a new instance of Rigel with a default EtcdStorage instance.

func New

func New(storage types.Storage, app string, module string, version int, config string) *Rigel

New creates a new instance of Rigel with the provided Storage interface. The Storage interface is used by Rigel to interact with the underlying storage system. Currently, only etcd is supported as a storage system.

func NewWithStorage added in v0.10.0

func NewWithStorage(storage types.Storage) *Rigel

NewWithStorage creates a new instance of Rigel with the provided Storage interface. This function is useful when you want to create a Rigel object with a specific storage system, but you don't want to set the other parameters (app, module, version, config) at the time of creation. This is typically used in admin tasks like schema creation where version field is not known while adding a new schema definition. Once Rigel object is constructed using NewWithStorage other required params for admin tasks are supposed to be added using the with-prefixed functions like WithApp, WithModule, etc.

func (*Rigel) AddSchema

func (r *Rigel) AddSchema(ctx context.Context, schema types.Schema) error

AddSchema adds a new schema to the Rigel storage. If a schema with the same name and version already exists in the storage, AddSchema will override the existing schema with the new one.

func (*Rigel) Get added in v0.9.0

func (r *Rigel) Get(ctx context.Context, configKey string) (string, error)

Get retrieves a value from the storage based on the provided key. It converts the retrieved value to the correct type based on the field type. If the field type is not "int" or "bool", the value is assumed to be a string. get retrieves a value from the cache or storage and returns it as a string.

func (*Rigel) GetBool added in v0.9.0

func (r *Rigel) GetBool(ctx context.Context, configKey string) (bool, error)

func (*Rigel) GetFloat added in v0.11.0

func (r *Rigel) GetFloat(ctx context.Context, configKey string) (float64, error)

func (*Rigel) GetInt added in v0.9.0

func (r *Rigel) GetInt(ctx context.Context, configKey string) (int, error)

func (*Rigel) GetSchema added in v0.12.0

func (r *Rigel) GetSchema(ctx context.Context) (*types.Schema, error)

GetSchema retrieves a schema (fields and metadata)

func (*Rigel) GetString added in v0.9.0

func (r *Rigel) GetString(ctx context.Context, configKey string) (string, error)

func (*Rigel) KeyExistsInSchema added in v0.11.0

func (r *Rigel) KeyExistsInSchema(ctx context.Context, key string) (bool, error)

KeyExistsInSchema checks if a key exists in the schema.

func (*Rigel) LoadConfig

func (r *Rigel) LoadConfig(ctx context.Context, configStruct any) error

LoadConfig retrieves the configuration data associated with the provided configName. It then unmarshals this data into the provided configStruct.

The configStruct parameter must be a pointer to a config struct used in the application. If it is not, an error will be returned. Non-pointer or non-struct types aren't supported due to type safety issues (e.g., unexpected fields in JSON) and modification restrictions, as non-pointer variables can't be updated by json.Unmarshal.

Example
//// Create a new EtcdStorage instance
//etcdStorage, err := etcd.NewEtcdStorage([]string{"localhost:2379"})
//if err != nil {
//	log.Fatalf("Failed to create EtcdStorage: %v", err)
//}
//
//// Create a new Rigel instance
//rigelClient := New(etcdStorage)
//
//// Define a config struct
//var config struct {
//	DatabaseURL string `json:"database_url"`
//	APIKey      string `json:"api_key"`
//	IsDebug     bool   `json:"is_debug"`
//}
//
//// Load the config
//err = rigelClient.LoadConfig("AppConfig", 1, "Production", &config)
//if err != nil {
//	log.Fatalf("Failed to load config: %v", err)
//}
//
//// Print the loaded config
//fmt.Printf("DatabaseURL: %s\n", config.DatabaseURL)
//fmt.Printf("APIKey: %s\n", config.APIKey)
//fmt.Printf("IsDebug: %t\n", config.IsDebug)
//
Output:

func (*Rigel) Set added in v0.11.0

func (r *Rigel) Set(ctx context.Context, configKey string, value string) error

Set sets a value of a config key in the storage.

func (*Rigel) WatchConfig added in v0.9.0

func (r *Rigel) WatchConfig(ctx context.Context) error

WatchConfig starts watching for changes to any key in the specified configuration namespace in the storage. When a change is detected, it updates the corresponding key-value pair in the cache. The method takes the schemaName, schemaVersion, and configName to construct the base key for the configuration namespace.

func (*Rigel) WithApp added in v0.10.0

func (r *Rigel) WithApp(app string) *Rigel

WithApp sets the App field of the Rigel struct and returns the modified Rigel object. This method is typically used for method chaining during Rigel object creation.

func (*Rigel) WithConfig added in v0.10.0

func (r *Rigel) WithConfig(config string) *Rigel

WithConfig sets the Config field of the Rigel struct and returns the modified Rigel object. This method is typically used for method chaining during Rigel object creation.

func (*Rigel) WithModule added in v0.10.0

func (r *Rigel) WithModule(module string) *Rigel

WithModule sets the Module field of the Rigel struct and returns the modified Rigel object. This method is typically used for method chaining during Rigel object creation.

func (*Rigel) WithVersion added in v0.10.0

func (r *Rigel) WithVersion(version int) *Rigel

WithVersion sets the Version field of the Rigel struct and returns the modified Rigel object. This method is typically used for method chaining during Rigel object creation.

Directories

Path Synopsis
cmd
Package etcd provides an implementation of the Storage interface defined in the Rigel project.
Package etcd provides an implementation of the Storage interface defined in the Rigel project.
Package mocks provides mock implementations of the interfaces used in Rigel.
Package mocks provides mock implementations of the interfaces used in Rigel.
Package types defines the core data types used in Rigel.
Package types defines the core data types used in Rigel.

Jump to

Keyboard shortcuts

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