Feat: read CORS config from file

This commit is contained in:
HFO4
2019-12-13 19:00:58 +08:00
parent c102c74d6d
commit ad02a659a6
5 changed files with 42 additions and 10 deletions

View File

@@ -51,6 +51,16 @@ type thumb struct {
FileSuffix string `validate:"min=1"`
}
// 跨域配置
type cors struct {
AllowAllOrigins bool
AllowOrigins []string
AllowMethods []string
AllowHeaders []string
AllowCredentials bool
ExposeHeaders []string
}
var cfg *ini.File
// Init 初始化配置文件
@@ -69,6 +79,7 @@ func Init(path string) {
"Captcha": CaptchaConfig,
"Redis": RedisConfig,
"Thumbnail": ThumbConfig,
"CORS": CORSConfig,
}
for sectionName, sectionStruct := range sections {
err = mapSection(sectionName, sectionStruct)

View File

@@ -34,6 +34,16 @@ var CaptchaConfig = &captcha{
CaptchaLen: 6,
}
// CORSConfig 跨域配置
var CORSConfig = &cors{
AllowAllOrigins: false,
AllowOrigins: []string{"UNSET"},
AllowMethods: []string{"PUT", "POST", "GET", "OPTIONS"},
AllowHeaders: []string{"Cookie", "Content-Length", "Content-Type", "X-Path", "X-FileName"},
AllowCredentials: true,
ExposeHeaders: nil,
}
var ThumbConfig = &thumb{
MaxWidth: 400,
MaxHeight: 300,