config

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatConfig added in v0.0.3

func FormatConfig(config *Config) error

func GetAccessToken

func GetAccessToken() string

func GetCacheDir added in v0.0.5

func GetCacheDir() string

获取缓存目录

func GetConfigPath

func GetConfigPath() string

func GetDBFile added in v0.0.5

func GetDBFile() string

func GetDefaultConfigPath added in v0.0.3

func GetDefaultConfigPath() (string, error)

func GetLogFile added in v0.0.5

func GetLogFile() string

func Init

func Init(configFile string) error

初始化配置 功能需求: - 如果 config 变量有值,直接返回 - 初始化的过程使用 sync.Once 保证只做一次 - 先通过 configYml 加载配置 config - 如果 configFile 地址存在

  • 如果内容不是 Yml 配置,则报错
  • 是配置文件,则对 config 进行合并,字段值以文件中优先

- *_dir/*_file 后缀的字段,使用 homedir.Expand 做 ~/ 地址开头解析 - 如果 DataDir 为空,需要使用 utils.GetUserDataRoot 获取默认值

单元测试见本包 _test

func InitConfig

func InitConfig(configFile string) error

func InitConfigByCode

func InitConfigByCode() error

func ReInitConfig added in v0.0.3

func ReInitConfig() error

func SaveAccess

func SaveAccess(a Access) error

func SaveCredential

func SaveCredential(c Credential) error

func Set

func Set(conf *Config)

func SetConfigPath added in v0.0.3

func SetConfigPath(path string)

func Show

func Show(hiddenFields ...string) string

Types

type Access

type Access struct {
	AccessToken      string `yaml:"accessToken" json:"accessToken"`
	ExpiresIn        int    `yaml:"expiresIn" json:"expiresIn"`
	RefreshTimestamp int    `yaml:"refreshTimestamp" json:"refreshTimestamp"`
	RefreshToken     string `yaml:"refreshToken" json:"refreshToken"`
}

func GetAccess added in v0.0.3

func GetAccess() (*Access, error)

func (*Access) IsExpired

func (a *Access) IsExpired() bool

func (*Access) IsNil

func (a *Access) IsNil() bool

type App

type App struct {
	Name  string `yaml:"name" json:"name"`
	Scope string `yaml:"scope" json:"scope"`
}

type Config

type Config struct {
	App     App    `yaml:"app" json:"app"`
	DataDir string `yaml:"data_dir" json:"data_dir" mapstructure:"data_dir"`
}

func Get

func Get() *Config

type Credential

type Credential struct {
	AppID     int    `yaml:"appId" json:"appId"`
	AppKey    string `yaml:"appKey" json:"appKey"`
	SecretKey string `yaml:"secretKey" json:"secretKey"`
	SignKey   string `yaml:"signKey" json:"signKey"`
}

func GetCredential added in v0.0.5

func GetCredential() (*Credential, error)

func (*Credential) IsNil

func (c *Credential) IsNil() bool

Jump to

Keyboard shortcuts

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