Documentation
¶
Overview ¶
Package config load all configurations and environment variable to program.
Index ¶
- Constants
- func DefaultConfigPath(path string)
- func GetEnv[ES any]() *ES
- func HasDict(k DictKey) bool
- func LoadDict(dictkey string)
- func LoadEnv(prefix string, dest any)
- func NextDictCap(cap uint64)
- func NextDictTTL(ttl time.Duration)
- func PutDict(k DictKey, dict DataDict[any])
- type Config
- type DBConfig
- type DataDict
- func (dd *DataDict[V]) Find(k string) *ttlcache.Item[string, V]
- func (dd *DataDict[V]) Has(k string) bool
- func (dd *DataDict[V]) Keys(filter func(k string) bool) []string
- func (dd *DataDict[V]) Len() int
- func (dd *DataDict[V]) Name() DictKey
- func (dd *DataDict[V]) Record(k string, v V)
- func (dd *DataDict[V]) Remove(k string)
- func (dd *DataDict[V]) RemoveAll()
- type DictDirectory
- type DictKey
- type GithubConfig
- type OAuthConfig
- type RedisConfig
- type Repo
- type ServerConfig
- type SqlDBConfig
- type SwagConfig
Constants ¶
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" )
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 LoadEnv ¶
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.
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 ¶
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 ¶
type DataDict ¶
type DataDict[V any] struct { // contains filtered or unexported fields }
DataDict store data with string key.
func NewDataDict ¶
NewDataDict return a data dict with string key.
func (*DataDict[V]) Find ¶
Find return Item with specific key and will panic if not exists the data.
type DictDirectory ¶
type DictDirectory struct {
// contains filtered or unexported fields
}
DictDirectory store the whole dicts.
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 RedisConfig ¶
type RedisConfig struct {
Dsn string `yaml:"dsn"`
}
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 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"`
}