Documentation
¶
Index ¶
- func DeleteAccess() error
- func GetAccessToken() string
- func GetCacheDir() (string, error)
- func GetConfigPath() string
- func GetDBFile() (string, error)
- func GetDefaultConfigPath() (string, error)
- func GetLogFile() (string, error)
- func Init(configFile string) error
- func SaveAccess(a Access) error
- func SaveCredential(c Credential) error
- func Set(conf *Config)
- func SetConfigPath(path string)
- func Show(hiddenFields ...string) string
- type Access
- type App
- type Config
- type Credential
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteAccess ¶ added in v0.0.9
func DeleteAccess() error
DeleteAccess 删除本地 access.json 文件。
实现逻辑:
- 通过 getAccessPath() 获取 access.json 路径(复用现有逻辑)
- 文件不存在时返回 nil(幂等,不报错)
- 文件存在时调用 os.Remove 删除
- 删除失败时返回 error,由调用方决定如何处理
安全说明:access.json 包含用户的 access token 和 refresh token, 登出时必须彻底删除以防止 token 泄露(T-09-01)。
func GetAccessToken ¶
func GetAccessToken() string
func GetCacheDir ¶ added in v0.0.5
GetCacheDir 获取缓存目录。 若配置未初始化,返回 error。
func GetConfigPath ¶
func GetConfigPath() string
func GetDefaultConfigPath ¶ added in v0.0.3
func GetLogFile ¶ added in v0.0.5
GetLogFile 返回日志文件路径。 若配置未初始化,返回 error。
func Init ¶
初始化配置 功能需求: - 如果 config 变量有值,直接返回 - 初始化的过程使用 sync.Once 保证只做一次 - 先通过 configYml 加载配置 config - 如果 configFile 地址存在
- 如果内容不是 Yml 配置,则报错
- 是配置文件,则对 config 进行合并,字段值以文件中优先
- *_dir/*_file 后缀的字段,使用 homedir.Expand 做 ~/ 地址开头解析 - 如果 DataDir 为空,需要使用 utils.GetUserDataRoot 获取默认值
单元测试见本包 _test
func SaveAccess ¶
func SaveCredential ¶
func SaveCredential(c Credential) error
func SetConfigPath ¶ added in v0.0.3
func SetConfigPath(path string)
Types ¶
type Access ¶
type 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
Click to show internal directories.
Click to hide internal directories.