config

package
v1.0.0-pre Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config load all configurations and environment variable to program.

Index

Constants

View Source
const (
	/* dictionary key to find dictionary */
	DICTKEY_CONFIG  = "_dict_config"
	DICTKEY_COMMAND = "_dict_command"
	DICTKEY_SERVER  = "_dict_server"
	DICTKEY_SERVICE = "_dict_service"
	DICTKEY_CLIENT  = "_dict_client"
	DICTKEY_EVENT   = "_dict_event"
)
View Source
const (
	/* data key to fing data */
	DATAKEY_CONFIG           = "_data_config"
	DATAKEY_ENV              = "_data_env"
	DATAKEY_CLI              = "_data_cli"
	DATAKEY_SERVER_ECHO      = "_data_server_echo"
	DATAKEY_PERMISSION_TABLE = "_data_permission_table"
	DATAKEY_PERMISSION_USER  = "_data_permission_user"
	DATAKEY_DB_REDIS         = "_data_db_redis"
)

Variables

This section is empty.

Functions

func DefaultConfigPath

func DefaultConfigPath(path string)

DefaultConfigFile set default config file.

func GetEnv

func GetEnv[ES any]() *ES

GetEnv try to get the pointer to environment structure and will panic if not exists the structure.

func HasDict

func HasDict(k DictKey) bool

HasDict report whether dict with specific key is in directory.

func LoadDict

func LoadDict(dictkey string)

func LoadEnv

func LoadEnv(prefix string, dest any)

LoadEnv load all environment variables matching the specified prefix into the specified structure, which must be a pointer type. An error log will be displayed if a structure configuration problem exists, but the program will not exit. Write all environment variables to the configuration dictionary.

func NextDictCap

func NextDictCap(cap uint64)

NextDictCap set cap used by next dict.

func NextDictTTL

func NextDictTTL(ttl time.Duration)

NextDictTTL set ttl used by next dict.

func PutDict

func PutDict(k DictKey, dict DataDict[any])

PutDict put dict into dict directory.

Types

type Config

type Config struct {
	EnvConfig    []string     `yaml:"environment" json:"environment"` // special environment config
	GithubConfig GithubConfig `yaml:"github" json:"github"`           // github config
	DBConfig     DBConfig     `yaml:"database" json:"database"`       // database config
	ServerConfig ServerConfig `yaml:"server" json:"server"`           // server config
	SwagConfig   SwagConfig   `yaml:"swagger" json:"swagger"`         // swagger config
}

Config record record all possible configuration items.

func GetConfig

func GetConfig() *Config

GetConfig try to get pointer to global config and will panic if not exists the config.

func LoadConfig

func LoadConfig(path string) *Config

LoadConfig return a pointer to all config and will panic if not exists the file path.

type DBConfig

type DBConfig struct {
	SqlDBConfig `yaml:"sql"`
	RedisConfig `yaml:"redis"`
}

func (*DBConfig) RedisOptions

func (db *DBConfig) RedisOptions() *redis.Options

type DataDict

type DataDict[V any] struct {
	// contains filtered or unexported fields
}

DataDict store data with string key.

func GetDict

func GetDict(k DictKey) DataDict[any]

GetDict return dict with specific key and will panic if not exists the dict.

func NewDataDict

func NewDataDict[V any](name string) DataDict[V]

NewDataDict return a data dict with string key.

func (*DataDict[V]) Find

func (dd *DataDict[V]) Find(k string) *ttlcache.Item[string, V]

Find return Item with specific key and will panic if not exists the data.

func (*DataDict[V]) Has

func (dd *DataDict[V]) Has(k string) bool

func (*DataDict[V]) Keys

func (dd *DataDict[V]) Keys(filter func(k string) bool) []string

func (*DataDict[V]) Len

func (dd *DataDict[V]) Len() int

func (*DataDict[V]) Name

func (dd *DataDict[V]) Name() DictKey

Name return the dict's dict key from dict directory.

func (*DataDict[V]) Record

func (dd *DataDict[V]) Record(k string, v V)

func (*DataDict[V]) Remove

func (dd *DataDict[V]) Remove(k string)

func (*DataDict[V]) RemoveAll

func (dd *DataDict[V]) RemoveAll()

type DictDirectory

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

DictDirectory store the whole dicts.

type DictKey

type DictKey string

type GithubConfig

type GithubConfig struct {
	ApiHost     string `yaml:"apiHost" json:"apiHost"`
	RawHost     string `yaml:"rawHost" json:"rawHost"`
	AccessToken string `yaml:"accessToken" json:"accessToken"`
	UserName    string `yaml:"userName" json:"userName"`
	UserEmail   string `yaml:"userEmail" json:"userEmail"`
	Repos       []Repo `yaml:"repos" json:"repos"`
	ActiveRepo  int    `yaml:"activeRepo" json:"activeRepo"`
}

type OAuthConfig

type OAuthConfig struct {
	ClientId string `yaml:"chienId"`
	Realm    string `yaml:"realm"`
	AppName  string `yaml:"appName"`
}

type RedisConfig

type RedisConfig struct {
	Dsn string `yaml:"dsn"`
}

type Repo

type Repo struct {
	Name string `yaml:"name" json:"name"`
	Ref  string `yaml:"ref" json:"ref"`
}

type ServerConfig

type ServerConfig struct {
	Addr              string `yaml:"addr"`
	Host              string `yaml:"host"`
	Port              int    `yaml:"port"`
	EnableOptions     bool   `yaml:"enableOptions"`
	ReadTimeout       int    `yaml:"readTimeout"`
	ReadHeaderTimeout int    `yaml:"readHeaderTimeout"`
	WriteTimeout      int    `yaml:"writeTimeout"`
	IdleTimeout       int    `yaml:"idleTimeout"`
	MaxHeaderBytes    []int  `yaml:"maxHeaderBytes"`
}

type SqlDBConfig

type SqlDBConfig struct {
	Driver          string `yaml:"driver"`
	Dsn             string `yaml:"dsn"`
	MaxIdleConn     int    `yaml:"maxIdleConn"`
	MaxOpenConn     int    `yaml:"maxOpenConn"`
	MaxConnIdleTime int    `yaml:"maxConnIdleTime"`
	MaxConnLifeTime int    `yaml:"maxConnLifeTime"`
}

type SwagConfig

type SwagConfig struct {
	URLs                 []string     `yaml:"urls"`
	DocExpansion         string       `yaml:"docExpansion"`
	DomID                string       `yaml:"domID"`
	InstanceName         string       `yaml:"instanceName"`
	DeepLinking          bool         `yaml:"deepLinking"`
	PersistAuthorization bool         `yaml:"persistAuthorization"`
	SyntaxHighlight      bool         `yaml:"syntaxHightlight"`
	OAuth                *OAuthConfig `yaml:"oauth"`
}

Jump to

Keyboard shortcuts

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