configmanager

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConfigNotFound = fmt.Errorf("config not found")
	ErrInvalidConfig  = fmt.Errorf("invalid config")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Key   string
	Value string
	// UpdatedBy is the user who updated the configuration. It will taken from header (X-User-Id) of the request. it will be empty if header is not present.
	UpdatedBy string
	UpdatedAt int64
	CreatedAt int64
}

type ConfigManager

type ConfigManager interface {
	// It will register the config in manager, it will save the config in repo if not already present with default values.
	RegisterConfig(ctx context.Context, cfg config) error
	// RegisterRoute will register the necesory endpoints for the configuration manager. using the provided RouteRegistrar.
	RegisterRoute(ctx context.Context, registerFunc RouteRegistrar) error
	// Get will return the configuration for the given key. It will return an error if the configuration is not found. It expects the pointer to the config object which implements config interface.
	Get(ctx context.Context, cfg config) error
}

type ConfigManagerConfig

type ConfigManagerConfig struct {
	ServiceName         string `name:"service_name" type:"string" description:"service name" required:"true"`
	CacheTimeoutMinutes int    `name:"cache_timeout_minutes" type:"number" description:"cache timeout in minutes for config manager" required:"true"`
}

func (*ConfigManagerConfig) Key

func (c *ConfigManagerConfig) Key() string

type ConfigObject

type ConfigObject struct {
	Name        string         `json:"name"`
	Type        ConfigType     `json:"type"`
	Description string         `json:"description"`
	Required    bool           `json:"required"`
	Choices     []string       `json:"choices,omitempty"`
	Value       any            `json:"value"`
	Childrens   []ConfigObject `json:"children"`
}

func (ConfigObject) Validate

func (co ConfigObject) Validate() error

type ConfigTag

type ConfigTag string

ConfigTag is a type for configuration tags.

const (
	// CONFIG_TAG_NAME is the tag for the name of the configuration. It is required tag.
	CONFIG_TAG_NAME ConfigTag = "name"
	// CONFIG_TAG_DESCRIPTION is the tag for the description of the configuration. It is optional tag.
	CONFIG_TAG_DESCRIPTION ConfigTag = "description"
	// CONFIG_TAG_TYPE is the tag for the type of the configuration. It is required
	CONFIG_TAG_TYPE ConfigTag = "type"
	// CONFIG_TAG_REQUIRED is the tag for the required value of the configuration. It should be true or false. It will be false by default.
	CONFIG_TAG_REQUIRED ConfigTag = "required"
	// CONFIG_TAG_CHOICES is the tag for the choices of the configuration. It is required if the type is choice.
	CONFIG_TAG_CHOICES ConfigTag = "choices"
)

type ConfigType

type ConfigType string
const (
	// CONFIG_TYPE_STRING is the type for string configuration, it will show a textbox on ui.
	CONFIG_TYPE_STRING ConfigType = "string"
	// CONFIG_TYPE_NUMBER is the type for integer configuration, it will show a number input on ui.
	CONFIG_TYPE_NUMBER ConfigType = "number"
	// CONFIG_TYPE_BOOLEAN is the type for boolean configuration, it will show a checkbox on ui.
	CONFIG_TYPE_BOOLEAN ConfigType = "boolean"
	// CONFIG_TYPE_JSON is the type for json configuration, it will show a textarea on ui which will have json formatting.
	CONFIG_TYPE_JSON ConfigType = "json"
	// CONFIG_TYPE_FLOAT is the type for float configuration, it will show a number input on ui.
	CONFIG_TYPE_BIG_TEXT ConfigType = "big_text"
	// CONFIG_TYPE_CHOICE is the type for choice configuration, it will show a dropdown on ui and it should have type string.
	CONFIG_TYPE_CHOICE ConfigType = "choice"
	//CONFIG_TYPE_PARENT
	CONFIG_TYPE_PARENT ConfigType = "parent"
	//CONFIG_TYPE_LIST
	CONFIG_TYPE_LIST ConfigType = "list"
)

type Repository

type Repository interface {
	// GetConfig will return the value of the configuration for the given key. It will return nil if the configuration is not found.
	// it will return an error if there is an issue with the repository.
	GetConfig(ctx context.Context, key string) (*Config, error)
	// SaveConfig will save the configuration with the given key and value. It will return an error if there is an issue with the repository.
	SaveConfig(ctx context.Context, cfg *Config) error
}

type RouteRegistrar

type RouteRegistrar func(method, path string, handler http.HandlerFunc) error

RouteRegistrar defines a generic function type for registering routes.

Directories

Path Synopsis
docs
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.

Jump to

Keyboard shortcuts

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