Documentation
¶
Index ¶
- func GetConfKeyPath(appName string, moduleName string, version int, namedConfig string, ...) string
- func GetConfPath(appName string, moduleName string, version int, namedConfig string) string
- func GetSchemaDescriptionPath(appName string, moduleName string, version int) string
- func GetSchemaFieldsPath(appName string, moduleName string, version int) string
- func GetSchemaPath(appName string, moduleName string, version int) string
- func ValidateValueAgainstConstraints(value string, field *types.Field) bool
- type InMemoryCache
- type KeyNotFoundError
- type Rigel
- func (r *Rigel) AddSchema(ctx context.Context, schema types.Schema) error
- func (r *Rigel) DisableCaching() *Rigel
- func (r *Rigel) EnableCaching() *Rigel
- func (r *Rigel) Get(ctx context.Context, configKey string) (string, error)
- func (r *Rigel) GetBool(ctx context.Context, configKey string) (bool, error)
- func (r *Rigel) GetFloat(ctx context.Context, configKey string) (float64, error)
- func (r *Rigel) GetInt(ctx context.Context, configKey string) (int, error)
- func (r *Rigel) GetSchema(ctx context.Context) (*types.Schema, error)
- func (r *Rigel) GetString(ctx context.Context, configKey string) (string, error)
- func (r *Rigel) InvalidateSchemaCache()
- func (r *Rigel) IsCachingEnabled() bool
- func (r *Rigel) KeyExistsInSchema(ctx context.Context, key string) (bool, error)
- func (r *Rigel) LoadConfig(ctx context.Context, configStruct any) error
- func (r *Rigel) Set(ctx context.Context, configKey string, value string) error
- func (r *Rigel) WatchConfig(ctx context.Context) error
- func (r *Rigel) WithApp(app string) *Rigel
- func (r *Rigel) WithConfig(config string) *Rigel
- func (r *Rigel) WithModule(module string) *Rigel
- func (r *Rigel) WithVersion(version int) *Rigel
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
GetConfPath constructs the path for a configuration based on the provided appName, moduleName and version.
func GetSchemaDescriptionPath ¶ added in v0.12.0
getSchemaDescriptionPath constructs the path for a schema based on the provided appName, moduleName and version.
func GetSchemaFieldsPath ¶ added in v0.12.0
GetSchemaFieldsPath constructs the path for a schema based on the provided appName, moduleName and version.
func GetSchemaPath ¶ added in v0.12.0
GetSchemaPath constructs the base key for a schema in etcd based on the provided appName, moduleName and version.
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
Default creates a new instance of Rigel with a default EtcdStorage instance. By default, caching is enabled.
func New ¶
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
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 ¶
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
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
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
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) 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
IsCachingEnabled returns whether caching is currently enabled for this Rigel instance.
func (*Rigel) KeyExistsInSchema ¶ added in v0.11.0
KeyExistsInSchema checks if a key exists in the schema.
func (*Rigel) LoadConfig ¶
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) WatchConfig ¶ added in v0.9.0
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
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
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
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
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. |