rigel

package module
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: Apache-2.0 Imports: 9 Imported by: 3

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.

Installation

rigelctl is a cli tool that allows you to interact with Rigel. You can use rigelctl to add schemas, set configuration values, retrieve configuration values, and so on.

go install github.com/remiges-tech/rigel/cmd/rigelctl@latest

It will install rigelctl in your $GOPATH/bin directory.

Or you can download the latest binray release from https://github.com/remiges-tech/rigel/releases

Add a schema

rigelctl --etcd-endpoint localhost:2379,localhost:2380,localhost:2390 --app banking_app --module transactions --version 1 schema add banking_schema.json
Sample schema
{
    "fields": [
        {
            "name": "api_endpoint",
            "type": "string",
            "description": "The URL endpoint for the banking API."
        },
        {
            "name": "max_transactions_per_day",
            "type": "int",
            "description": "The maximum number of transactions allowed per day.",
            "constraints": {
                "min": 1
            }
        },
        {
            "name": "enable_fraud_detection", 
            "type": "bool",
            "description": "Indicates whether fraud detection should be enabled."
        }
    ],
    "description": "Configuration schema for the banking application's transactions module."
}

set a config key

rigelctl --app banking_app --module transactions --version 1 --config prod-us config set api_endpoint "https://api.bankingapp.com"
rigelctl --app banking_app --module transactions --version 1 --config prod-us config set enable_fraud_detection true
rigelctl --app banking_app --module transactions --version 1 --config prod-eu config set enable_fraud_detection true

For more details on the available commands and flags, run rigelctl --help.

Usage in Go code

Usage

Here's an example of how to use the Rigel Go package in your banking application:

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/remiges-tech/rigel"
    "github.com/remiges-tech/rigel/etcd"
)

func main() {
    // 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 := rigel.New(etcdStorage, "banking_app", "transactions", 1, "banking_config")

    // Retrieve configuration values
    apiEndpoint, err := rigelClient.Get(context.Background(), "api_endpoint")
    if err != nil {
        log.Fatalf("Failed to get api_endpoint: %v", err)
    }

    enableFraudDetection, err := rigelClient.GetBool(context.Background(), "enable_fraud_detection")
    if err != nil {
        log.Fatalf("Failed to get enable_fraud_detection: %v", err)
    }

    fmt.Printf("API Endpoint: %s\n", apiEndpoint)
    fmt.Printf("Max Transactions Per Day: %s\n", maxTransactionsPerDay)
    fmt.Printf("Enable Fraud Detection: %s\n", enableFraudDetection)
}

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. By default, caching is enabled.

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. By default, caching is enabled.

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. By default, caching is enabled.

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) DisableCaching added in v0.18.0

func (r *Rigel) DisableCaching() *Rigel

DisableCaching disables the use of the cache for Get operations. When disabled, all Get operations fetch values directly from etcd, bypassing the local cache entirely. This ensures values are always fresh from etcd but may impact performance with increased network calls. This also clears the schema cache to ensure fresh schema lookups.

func (*Rigel) EnableCaching added in v0.18.0

func (r *Rigel) EnableCaching() *Rigel

EnableCaching enables the use of the cache for Get operations and etcd watches. When enabled, values are cached locally for faster access, and the cache is updated when changes occur in etcd (if WatchConfig is called).

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. If caching is enabled, it tries to get the value from the cache first, otherwise it retrieves it directly from the storage.

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) InvalidateSchemaCache added in v0.18.0

func (r *Rigel) InvalidateSchemaCache()

InvalidateSchemaCache clears the cached schema fields, forcing a fresh load from storage on the next access. This is useful when schema changes are made and need to be reflected immediately.

func (*Rigel) IsCachingEnabled added in v0.18.0

func (r *Rigel) IsCachingEnabled() bool

IsCachingEnabled returns whether caching is currently enabled for this Rigel instance.

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:
//// DatabaseURL: postgres://user:pass@localhost:5432/dbname
//// APIKey: abc123
//// IsDebug: false

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 if caching is enabled. The method takes the schemaName, schemaVersion, and configName to construct the base key for the configuration namespace. Note: When caching is disabled, events are still received but not cached. Security: Only keys that already exist in the cache are updated. New keys are not added to prevent cache pollution and ensure the cache only contains keys the application actually uses.

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
rigelctl command
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.
cache_control command
tutorial command
watch command
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