config

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 28 Imported by: 1

Documentation

Index

Constants

View Source
const (
	//
	ENV_PREFIX    = "PORTAL__"
	ENV_SEPARATOR = "__"

	// Configuration keys and flags
	CLUSTER_CONFIG_KEY = "config"
	FLAG_SYNC          = "sync"
	FLAG_VOLATILE      = "volatile"

	// File extensions and names
	CONFIG_EXTENSION  = ".yaml"
	CoreConfigFile    = "core" + CONFIG_EXTENSION
	SectionConfigFile = "default" + CONFIG_EXTENSION

	// Directory names
	PluginsDir = "plugins.d"
	ProtoDir   = "proto.d"
	ServiceDir = "service.d"
	APIDir     = "api.d"
)

Variables

View Source
var (
	ErrInvalidServiceConfig = errors.New("service config must be of type config.ServiceConfig")
)

Functions

func GetAPISectionSpecifier added in v0.2.0

func GetAPISectionSpecifier(pluginName string) string

func GetCoreSectionSpecifier added in v0.2.0

func GetCoreSectionSpecifier(key string) string

func GetProtoSectionSpecifier added in v0.2.0

func GetProtoSectionSpecifier(pluginName string) string

func GetServiceSectionSpecifier added in v0.2.0

func GetServiceSectionSpecifier(pluginName string, serviceName string) string

Types

type APIConfig

type APIConfig interface {
	Defaults
}

type AccountConfig added in v0.2.0

type AccountConfig struct {
	DeletionGracePeriod uint `config:"deletion_grace_period"`
}

func (AccountConfig) Defaults added in v0.2.0

func (a AccountConfig) Defaults() map[string]any

type CacheConfig

type CacheConfig struct {
	Mode    CacheMode   `config:"mode"`
	Options interface{} `config:"options"`
}

func (CacheConfig) Defaults added in v0.2.0

func (c CacheConfig) Defaults() map[string]any

func (CacheConfig) Validate added in v0.2.0

func (c CacheConfig) Validate() error

type CacheMode added in v0.2.0

type CacheMode string
const (
	CacheModeMemory CacheMode = "memory"
	CacheModeRedis  CacheMode = "redis"
	CacheModeNone   CacheMode = "none"
)

type ClusterConfig

type ClusterConfig struct {
	Enabled bool         `config:"enabled"`
	Redis   *RedisConfig `config:"redis"`
	Etcd    *EtcdConfig  `config:"etcd"`
}

func (ClusterConfig) EtcdEnabled added in v0.4.1

func (c ClusterConfig) EtcdEnabled() bool

func (ClusterConfig) RedisEnabled added in v0.2.0

func (c ClusterConfig) RedisEnabled() bool

func (ClusterConfig) Validate added in v0.2.0

func (c ClusterConfig) Validate() error

type Config

type Config struct {
	Core   CoreConfig              `config:"core"`
	Plugin map[string]PluginEntity `config:"plugin"`
}

func (Config) Defaults added in v0.2.0

func (c Config) Defaults() map[string]any

type ConfigChangeCallback added in v0.2.0

type ConfigChangeCallback func(key string, value any) error

type ConfigPropertyUpdateCategory added in v0.2.0

type ConfigPropertyUpdateCategory string
const (
	CONFIG_PROPERTY_UPDATE_EVENT_CATEGORY_CORE     ConfigPropertyUpdateCategory = "core"
	CONFIG_PROPERTY_UPDATE_EVENT_CATEGORY_PROTOCOL ConfigPropertyUpdateCategory = "protocol"
	CONFIG_PROPERTY_UPDATE_EVENT_CATEGORY_API      ConfigPropertyUpdateCategory = "api"
	CONFIG_PROPERTY_UPDATE_EVENT_CATEGORY_SERVICE  ConfigPropertyUpdateCategory = "service"
)

type ConfigUpdate added in v0.2.0

type ConfigUpdate struct {
	Key    string
	Value  any
	Source string
}

type CoreConfig

type CoreConfig struct {
	DB              DatabaseConfig `config:"db"`
	Domain          string         `config:"domain"`
	PortalName      string         `config:"portal_name"`
	ExternalPort    uint           `config:"external_port"`
	Identity        types.Identity `config:"identity"`
	Log             LogConfig      `config:"log"`
	Port            uint           `config:"port"`
	PostUploadLimit uint64         `config:"post_upload_limit"`
	Storage         StorageConfig  `config:"storage"`
	Mail            MailConfig     `config:"mail"`
	Clustered       *ClusterConfig `config:"clustered"`
	NodeID          types.UUID     `config:"node_id"`
	Cron            CronConfig     `config:"cron"`
	Account         AccountConfig  `config:"account"`
}

func (CoreConfig) ClusterEnabled

func (c CoreConfig) ClusterEnabled() bool

func (CoreConfig) Defaults

func (c CoreConfig) Defaults() map[string]any

func (CoreConfig) Validate

func (c CoreConfig) Validate() error

type CronConfig added in v0.2.0

type CronConfig struct {
	Enabled  bool `config:"enabled"`
	MaxQueue uint `config:"queue_limit"`
}

func (CronConfig) Defaults added in v0.2.0

func (c CronConfig) Defaults() map[string]any

type DatabaseConfig

type DatabaseConfig struct {
	Type          string       `config:"type"`
	File          string       `config:"file"`
	Charset       string       `config:"charset"`
	Host          string       `config:"host"`
	Name          string       `config:"name"`
	Password      string       `config:"password"`
	Port          int          `config:"port"`
	Username      string       `config:"username"`
	Cache         *CacheConfig `config:"cache"`
	TLSEnabled    bool         `config:"tls_enabled"`
	TLSSkipVerify bool         `config:"tls_skip_verify"`
}

func (DatabaseConfig) CacheEnabled added in v0.2.0

func (d DatabaseConfig) CacheEnabled() bool

func (DatabaseConfig) Defaults

func (d DatabaseConfig) Defaults() map[string]any

func (DatabaseConfig) Validate

func (d DatabaseConfig) Validate() error

type Defaults

type Defaults interface {
	Defaults() map[string]any
}

type EtcdConfig

type EtcdConfig struct {
	Endpoints   []string `config:"endpoints"`
	Username    string   `config:"username"`
	Password    string   `config:"password"`
	Prefix      string   `config:"prefix"`
	DialTimeout int      `config:"dial_timeout"`
	// contains filtered or unexported fields
}

func (*EtcdConfig) Client

func (r *EtcdConfig) Client() (*clientv3.Client, error)

func (*EtcdConfig) Close added in v0.4.0

func (r *EtcdConfig) Close() error

func (*EtcdConfig) ComputePrefix added in v0.4.0

func (r *EtcdConfig) ComputePrefix(key string) string

func (*EtcdConfig) Defaults

func (r *EtcdConfig) Defaults() map[string]interface{}

func (*EtcdConfig) GetManager added in v0.4.0

func (r *EtcdConfig) GetManager(logger *zap.Logger) (*EtcdManager, error)

GetManager returns the EtcdManager, initializing it if necessary

func (*EtcdConfig) Validate

func (r *EtcdConfig) Validate() error

type EtcdManager added in v0.4.0

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

func NewEtcdManager added in v0.4.0

func NewEtcdManager(config *EtcdConfig, logger *zap.Logger) (*EtcdManager, error)

func (*EtcdManager) Client added in v0.4.0

func (m *EtcdManager) Client() *clientv3.Client

func (*EtcdManager) Close added in v0.4.0

func (m *EtcdManager) Close() error

type FieldProcessor added in v0.2.0

type FieldProcessor func(parent *reflect.StructField, field reflect.StructField, value reflect.Value, prefix string) error

type LogConfig

type LogConfig struct {
	Level string `config:"level"`
}

func (LogConfig) Defaults

func (l LogConfig) Defaults() map[string]interface{}

type MailConfig

type MailConfig struct {
	Host     string `config:"host"`
	Port     int    `config:"port"`
	SSL      bool   `config:"ssl"`
	AuthType string `config:"auth_type"`
	Username string `config:"username"`
	Password string `config:"password"`
	From     string `config:"from"`
}

func (MailConfig) Defaults

func (c MailConfig) Defaults() map[string]interface{}

func (MailConfig) Validate

func (m MailConfig) Validate() error

type Manager

type Manager interface {
	Init() error
	SetLogger(logger *zap.Logger)
	RegisterConfigChangeCallback(callback ConfigChangeCallback)
	FieldProcessor(obj any, prefix string, processors ...FieldProcessor) error
	ConfigureProtocol(pluginName string, cfg ProtocolConfig) error
	ConfigureAPI(pluginName string, cfg APIConfig) error
	ConfigureService(pluginName string, serviceName string, cfg ServiceConfig) error
	GetPlugin(pluginName string) *PluginEntity
	GetService(serviceName string) ServiceConfig
	GetProtocol(pluginName string) ProtocolConfig
	GetAPI(pluginName string) APIConfig
	Config() *Config
	Save() error
	ConfigFile() string
	ConfigDir() string
	Update(key string, value any) error
	Exists(key string) bool
	Get(key string) any
	All() map[string]any
	IsEditable(key string) bool
	Flags(key string) []string
}

type ManagerDefault

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

func NewManager

func NewManager(cmd *cli.Command) (*ManagerDefault, error)

func (*ManagerDefault) All added in v0.2.0

func (m *ManagerDefault) All() map[string]any

func (*ManagerDefault) Config

func (m *ManagerDefault) Config() *Config

func (*ManagerDefault) ConfigDir

func (m *ManagerDefault) ConfigDir() string

func (*ManagerDefault) ConfigFile

func (m *ManagerDefault) ConfigFile() string

func (*ManagerDefault) ConfigureAPI

func (m *ManagerDefault) ConfigureAPI(pluginName string, cfg APIConfig) error

func (*ManagerDefault) ConfigureProtocol

func (m *ManagerDefault) ConfigureProtocol(pluginName string, cfg ProtocolConfig) error

func (*ManagerDefault) ConfigureService

func (m *ManagerDefault) ConfigureService(pluginName string, serviceName string, cfg ServiceConfig) error

func (*ManagerDefault) Exists added in v0.2.0

func (m *ManagerDefault) Exists(key string) bool

func (*ManagerDefault) FieldProcessor added in v0.2.0

func (m *ManagerDefault) FieldProcessor(obj any, prefix string, processors ...FieldProcessor) error

func (*ManagerDefault) Flags added in v0.2.0

func (m *ManagerDefault) Flags(key string) []string

func (*ManagerDefault) Get added in v0.2.0

func (m *ManagerDefault) Get(key string) any

func (*ManagerDefault) GetAPI

func (m *ManagerDefault) GetAPI(pluginName string) APIConfig

func (*ManagerDefault) GetPlugin

func (m *ManagerDefault) GetPlugin(pluginName string) *PluginEntity

func (*ManagerDefault) GetProtocol added in v0.1.1

func (m *ManagerDefault) GetProtocol(pluginName string) ProtocolConfig

func (*ManagerDefault) GetService

func (m *ManagerDefault) GetService(serviceName string) ServiceConfig

func (*ManagerDefault) Init

func (m *ManagerDefault) Init() error

func (*ManagerDefault) IsEditable added in v0.2.0

func (m *ManagerDefault) IsEditable(key string) bool

func (*ManagerDefault) RegisterConfigChangeCallback added in v0.2.0

func (m *ManagerDefault) RegisterConfigChangeCallback(callback ConfigChangeCallback)

func (*ManagerDefault) Save

func (m *ManagerDefault) Save() error

func (*ManagerDefault) SetLogger added in v0.2.0

func (m *ManagerDefault) SetLogger(logger *zap.Logger)

func (*ManagerDefault) Shutdown added in v0.4.0

func (m *ManagerDefault) Shutdown() error

func (*ManagerDefault) Update added in v0.2.0

func (m *ManagerDefault) Update(key string, value any) error

type MemoryConfig

type MemoryConfig struct {
}

type PluginEntity

type PluginEntity struct {
	Protocol ProtocolConfig           `config:"protocol"`
	API      APIConfig                `config:"api"`
	Service  map[string]ServiceConfig `config:"service"`
}

type ProtocolConfig

type ProtocolConfig interface {
	Defaults
}

type Reconfigurable added in v0.2.0

type Reconfigurable interface {
	Reconfigure(scope Scope, value any) error
}

type RedisConfig

type RedisConfig struct {
	Address  string `config:"address"`
	Password string `config:"password"`
	DB       int    `config:"db"`
	// contains filtered or unexported fields
}

func (*RedisConfig) Client

func (r *RedisConfig) Client() (*redis.Client, error)

func (*RedisConfig) Defaults

func (r *RedisConfig) Defaults() map[string]interface{}

func (*RedisConfig) Validate

func (r *RedisConfig) Validate() error

type S3Config

type S3Config struct {
	BufferBucket string `config:"buffer_bucket"`
	Endpoint     string `config:"endpoint"`
	Region       string `config:"region"`
	AccessKey    string `config:"access_key"`
	SecretKey    string `config:"secret_key"`
}

func (S3Config) Defaults

func (s S3Config) Defaults() map[string]any

func (S3Config) Validate

func (s S3Config) Validate() error

type Scope added in v0.2.0

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

func NewScope added in v0.2.0

func NewScope(category ConfigPropertyUpdateCategory, entity, subEntity, property string) Scope

func NewScopeFromKey added in v0.2.0

func NewScopeFromKey(key string) Scope

func (Scope) Category added in v0.2.0

func (s Scope) Category() ConfigPropertyUpdateCategory

func (Scope) Entity added in v0.2.0

func (s Scope) Entity() string

func (Scope) Key added in v0.2.0

func (s Scope) Key() string

func (Scope) Property added in v0.2.0

func (s Scope) Property() string

func (Scope) SubEntity added in v0.2.0

func (s Scope) SubEntity() string

type ServiceConfig

type ServiceConfig interface {
	Defaults
}

type SiaConfig

type SiaConfig struct {
	Key     string `config:"key"`
	URL     string `config:"url"`
	Cluster bool   `config:"cluster"`
}

func (SiaConfig) Defaults

func (s SiaConfig) Defaults() map[string]interface{}

func (SiaConfig) Validate

func (s SiaConfig) Validate() error

type StorageConfig

type StorageConfig struct {
	S3  S3Config  `config:"s3"`
	Sia SiaConfig `config:"sia"`
	Tus TusConfig `config:"tus"`
}

type SyncConfig

type SyncConfig struct {
	Enabled bool `config:"enabled"`
}

func (SyncConfig) Defaults

func (s SyncConfig) Defaults() map[string]any

type TusConfig added in v0.2.0

type TusConfig struct {
	LockerMode string `config:"locker_mode"`
}

func (TusConfig) Validate added in v0.2.0

func (t TusConfig) Validate() error

type Validator

type Validator interface {
	Validate() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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