quickshare/src/server/config.go
Hexxa 1fcb2223a0
feat(be/fe): enable captcha (#69)
* feat(ui): enable captcha

* feat(server): enable captcha

* fix(ui): fix login pane layout

* fix(config): remove unused config and files

* fix(be/fe): clean up code

* chore(fe/be): clean up code
2021-08-07 11:27:24 +08:00

86 lines
2.5 KiB
Go

package server
import "encoding/json"
type FSConfig struct {
Root string `json:"root"`
OpensLimit int `json:"opensLimit"`
OpenTTL int `json:"openTTL"`
}
type UsersCfg struct {
EnableAuth bool `json:"enableAuth" yaml:"enableAuth"`
DefaultAdmin string `json:"defaultAdmin" yaml:"defaultAdmin" cfg:"env"`
DefaultAdminPwd string `json:"defaultAdminPwd" yaml:"defaultAdminPwd" cfg:"env"`
CookieTTL int `json:"cookieTTL" yaml:"cookieTTL"`
CookieSecure bool `json:"cookieSecure" yaml:"cookieSecure"`
CookieHttpOnly bool `json:"cookieHttpOnly" yaml:"cookieHttpOnly"`
MinUserNameLen int `json:"minUserNameLen" yaml:"minUserNameLen"`
MinPwdLen int `json:"minPwdLen" yaml:"minPwdLen"`
CaptchaWidth int `json:"captchaWidth" yaml:"captchaWidth"`
CaptchaHeight int `json:"captchaHeight" yaml:"captchaHeight"`
CaptchaEnabled bool `json:"captchaEnabled" yaml:"captchaEnabled"`
}
type Secrets struct {
TokenSecret string `json:"tokenSecret" yaml:"tokenSecret" cfg:"env"`
}
type ServerCfg struct {
Debug bool `json:"debug" yaml:"debug"`
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
ReadTimeout int `json:"readTimeout" yaml:"readTimeout"`
WriteTimeout int `json:"writeTimeout" yaml:"writeTimeout"`
MaxHeaderBytes int `json:"maxHeaderBytes" yaml:"maxHeaderBytes"`
PublicPath string `json:"publicPath" yaml:"publicPath"`
}
type Config struct {
Fs *FSConfig `json:"fs" yaml:"fs"`
Secrets *Secrets `json:"secrets" yaml:"secrets"`
Server *ServerCfg `json:"server" yaml:"server"`
Users *UsersCfg `json:"users" yaml:"users"`
}
func NewConfig() *Config {
return &Config{}
}
func DefaultConfig() (string, error) {
defaultCfg := &Config{
Fs: &FSConfig{
Root: "root",
OpensLimit: 128,
OpenTTL: 60, // 1 min
},
Users: &UsersCfg{
EnableAuth: true,
DefaultAdmin: "",
DefaultAdminPwd: "",
CookieTTL: 3600 * 24 * 7, // 1 week
CookieSecure: false,
CookieHttpOnly: true,
MinUserNameLen: 4,
MinPwdLen: 6,
CaptchaWidth: 256,
CaptchaHeight: 60,
CaptchaEnabled: true,
},
Secrets: &Secrets{
TokenSecret: "",
},
Server: &ServerCfg{
Debug: false,
Host: "0.0.0.0",
Port: 8686,
ReadTimeout: 2000,
WriteTimeout: 1000 * 3600 * 24, // 1 day
MaxHeaderBytes: 512,
PublicPath: "public",
},
}
cfgBytes, err := json.Marshal(defaultCfg)
return string(cfgBytes), err
}