fix(config): add config loading functions and tests, also fix config issues
This commit is contained in:
parent
67da1ea0eb
commit
32a003d789
11 changed files with 42 additions and 69 deletions
|
@ -31,20 +31,20 @@ type ISiteStore interface {
|
|||
}
|
||||
|
||||
type ClientConfig struct {
|
||||
SiteName string `json:"siteName"`
|
||||
SiteDesc string `json:"siteDesc"`
|
||||
Bg *BgConfig `json:"bg"`
|
||||
SiteName string `json:"siteName" yaml:"siteName"`
|
||||
SiteDesc string `json:"siteDesc" yaml:"siteDesc"`
|
||||
Bg *BgConfig `json:"bg" yaml:"bg"`
|
||||
}
|
||||
|
||||
type BgConfig struct {
|
||||
Url string `json:"url"`
|
||||
Repeat string `json:"repeat"`
|
||||
Position string `json:"position"`
|
||||
Align string `json:"align"`
|
||||
Url string `json:"url" yaml:"url"`
|
||||
Repeat string `json:"repeat" yaml:"repeat"`
|
||||
Position string `json:"position" yaml:"position"`
|
||||
Align string `json:"align" yaml:"align"`
|
||||
}
|
||||
|
||||
type SiteConfig struct {
|
||||
ClientCfg *ClientConfig `json:"clientCfg"`
|
||||
ClientCfg *ClientConfig `json:"clientCfg" yaml:"clientCfg"`
|
||||
}
|
||||
|
||||
type SiteStore struct {
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
|
||||
var (
|
||||
ErrBucketNotFound = errors.New("bucket not found")
|
||||
DBName = "quickshare.db"
|
||||
)
|
||||
|
||||
type BoltPvd struct {
|
||||
|
@ -25,7 +26,7 @@ type BoltPvd struct {
|
|||
}
|
||||
|
||||
func New(dbPath string, maxStrLen int) *BoltPvd {
|
||||
boltPath := path.Join(path.Clean(dbPath), "quickshare.db")
|
||||
boltPath := path.Join(path.Clean(dbPath), DBName)
|
||||
db, err := bolt.Open(boltPath, 0600, &bolt.Options{Timeout: 1 * time.Second})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -67,10 +67,15 @@ func NewConfig() *Config {
|
|||
}
|
||||
|
||||
func DefaultConfig() (string, error) {
|
||||
defaultCfg := &Config{
|
||||
cfgBytes, err := json.Marshal(DefaultConfigStruct())
|
||||
return string(cfgBytes), err
|
||||
}
|
||||
|
||||
func DefaultConfigStruct() *Config {
|
||||
return &Config{
|
||||
Fs: &FSConfig{
|
||||
Root: "root",
|
||||
OpensLimit: 128,
|
||||
OpensLimit: 1024,
|
||||
OpenTTL: 60, // 1 min
|
||||
},
|
||||
Users: &UsersCfg{
|
||||
|
@ -81,15 +86,16 @@ func DefaultConfig() (string, error) {
|
|||
CookieSecure: false,
|
||||
CookieHttpOnly: true,
|
||||
MinUserNameLen: 4,
|
||||
MinPwdLen: 6,
|
||||
MinPwdLen: 8,
|
||||
CaptchaWidth: 256,
|
||||
CaptchaHeight: 60,
|
||||
CaptchaEnabled: true,
|
||||
UploadSpeedLimit: 100 * 1024, // B
|
||||
DownloadSpeedLimit: 100 * 1024, // B
|
||||
UploadSpeedLimit: 1024 * 1024, // B
|
||||
DownloadSpeedLimit: 1024 * 1024, // B
|
||||
SpaceLimit: 1024 * 1024 * 100, // 100MB
|
||||
LimiterCapacity: 1000,
|
||||
LimiterCyc: 1000, // 1s
|
||||
PredefinedUsers: []*userstore.UserCfg{},
|
||||
},
|
||||
Secrets: &Secrets{
|
||||
TokenSecret: "",
|
||||
|
@ -121,7 +127,4 @@ func DefaultConfig() (string, error) {
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
cfgBytes, err := json.Marshal(defaultCfg)
|
||||
return string(cfgBytes), err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue