mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-03-22 11:01:52 +00:00
Web 服务
This commit is contained in:
42
model/config.go
Normal file
42
model/config.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// Config ..
|
||||
type Config struct {
|
||||
Debug bool
|
||||
Site struct {
|
||||
Brand string // 站点名称
|
||||
CookieName string // 浏览器 Cookie 名称
|
||||
}
|
||||
GitHub struct {
|
||||
Admin string // 管理员登录名
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
}
|
||||
}
|
||||
|
||||
// ReadInConfig ..
|
||||
func ReadInConfig(path string) (*Config, error) {
|
||||
viper.SetConfigFile(path)
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var c Config
|
||||
|
||||
err = viper.Unmarshal(&c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
viper.OnConfigChange(func(in fsnotify.Event) {
|
||||
viper.Unmarshal(&c)
|
||||
})
|
||||
|
||||
go viper.WatchConfig()
|
||||
return &c, nil
|
||||
}
|
||||
Reference in New Issue
Block a user