config構造体&読み込み処理、DB接続処理を実装
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
type Config struct {
|
||||
DB struct {
|
||||
Type string `ini:"DBTYPE"`
|
||||
Host string `ini:"DBHOST"`
|
||||
Port int `ini:"DBPORT"`
|
||||
User string `ini:"DBUSER"`
|
||||
Password string `ini:"DBPASS"`
|
||||
Name string `ini:"DBNAME"`
|
||||
} `ini:"db"`
|
||||
Server struct {
|
||||
Host string `ini:"SERVERHOST"`
|
||||
AllowOrigin string `ini:"ALLOWORIGIN"`
|
||||
} `ini:"server"`
|
||||
Security struct {
|
||||
AISpamProtection bool `ini:"AI_SPAM_PROTECTION"`
|
||||
AIProvider string `ini:"AI_PROVIDER"`
|
||||
AIEndpoint string `ini:"AI_ENDPOINT"`
|
||||
AIAPIKey string `ini:"AI_APIKEY"`
|
||||
AISecretKey string `ini:"AI_SECRETKEY"`
|
||||
AIModel string `ini:"AI_MODEL"`
|
||||
AIInstructions string `ini:"AI_INSTURCTIONS"`
|
||||
CaptchaEnabled bool `ini:"CAPTCHA_ENABLED"`
|
||||
CaptchaType string `ini:"CAPTCHA_TYPE"`
|
||||
CaptchaSiteKey string `ini:"CAPTCHA_SITEKEY"`
|
||||
CaptchaSecretKey string `ini:"CAPTCHA_SECRETKEY"`
|
||||
} `ini:"security"`
|
||||
}
|
||||
|
||||
import "gopkg.in/ini.v1"
|
||||
|
||||
func LoadConfig(filePath string) (*Config, error) {
|
||||
cfg, err := ini.Load(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config := &Config{}
|
||||
err = cfg.MapTo(config)
|
||||
return config, err
|
||||
}
|
||||
Reference in New Issue
Block a user