make config struct koanf ready

This commit is contained in:
genofire 2022-08-14 16:50:52 +02:00
parent 2aee702fc6
commit 4fc3ec1b9f
6 changed files with 37 additions and 37 deletions

View File

@ -9,11 +9,11 @@ import (
// Database struct to read from config // Database struct to read from config
type Database struct { type Database struct {
DB *gorm.DB `toml:"-"` DB *gorm.DB `config:"-" toml:"-"`
Connection string `toml:"connection"` Connection string `config:"connection" toml:"connection"`
Debug bool `toml:"debug"` Debug bool `config:"debug" toml:"debug"`
Testdata bool `toml:"testdata"` Testdata bool `config:"testdata" toml:"testdata"`
LogLevel logger.LogLevel `toml:"log_level"` LogLevel logger.LogLevel `config:"log_level" toml:"log_level"`
migrations map[string]*gormigrate.Migration migrations map[string]*gormigrate.Migration
migrationTestdata map[string]*gormigrate.Migration migrationTestdata map[string]*gormigrate.Migration
} }

View File

@ -12,7 +12,7 @@ func TestReadJSON(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
a := struct { a := struct {
Text string `toml:"text"` Text string `config:"text" toml:"text"`
}{} }{}
err := ReadJSON("testfiles/donoexists", &a) err := ReadJSON("testfiles/donoexists", &a)

View File

@ -27,7 +27,7 @@ func TestReadTOML(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
a := struct { a := struct {
Text string `toml:"text"` Text string `config:"text" toml:"text"`
}{} }{}
err := ReadTOML("testfiles/donoexists", &a) err := ReadTOML("testfiles/donoexists", &a)
@ -45,7 +45,7 @@ func TestSaveTOML(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
type to struct { type to struct {
Value int `toml:"v"` Value int `config:"v" toml:"v"`
} }
toSave := to{Value: 3} toSave := to{Value: 3}

View File

@ -6,13 +6,13 @@ import (
// Service to send mail // Service to send mail
type Service struct { type Service struct {
SMTPHost string `toml:"smtp_host"` SMTPHost string `config:"smtp_host" toml:"smtp_host"`
SMTPPort int `toml:"smtp_port"` SMTPPort int `config:"smtp_port" toml:"smtp_port"`
SMTPUsername string `toml:"smtp_username"` SMTPUsername string `config:"smtp_username" toml:"smtp_username"`
SMTPPassword string `toml:"smtp_password"` SMTPPassword string `config:"smtp_password" toml:"smtp_password"`
SMTPSSL bool `toml:"smtp_ssl"` SMTPSSL bool `config:"smtp_ssl" toml:"smtp_ssl"`
Dailer *mail.Dialer `toml:"-"` Dailer *mail.Dialer `config:"-" toml:"-"`
From string `toml:"from"` From string `config:"from" toml:"from"`
} }
// Ping mailer // Ping mailer

View File

@ -29,16 +29,16 @@ func (t *fsType) UnmarshalText(input []byte) error {
// FSInfo is a TOML structure storing access information about a file store. // FSInfo is a TOML structure storing access information about a file store.
type FSInfo struct { type FSInfo struct {
FSType fsType `toml:"type"` FSType fsType `config:"type" toml:"type"`
// file system // file system
Root string `toml:",omitempty"` Root string `config:",omitempty" toml:",omitempty"`
// s3 // s3
Endpoint string `toml:",omitempty"` Endpoint string `config:",omitempty" toml:",omitempty"`
Secure bool `toml:",omitempty"` Secure bool `config:",omitempty" toml:",omitempty"`
ID string `toml:",omitempty"` ID string `config:",omitempty" toml:",omitempty"`
Secret string `toml:",omitempty"` Secret string `config:",omitempty" toml:",omitempty"`
Bucket string `toml:",omitempty"` Bucket string `config:",omitempty" toml:",omitempty"`
Location string `toml:",omitempty"` Location string `config:",omitempty" toml:",omitempty"`
} }
// Create creates a file store from the information provided. // Create creates a file store from the information provided.

View File

@ -27,23 +27,23 @@ import (
// A Service stores configuration of a server. // A Service stores configuration of a server.
type Service struct { type Service struct {
// config // config
Listen string `toml:"listen"` Listen string `config:"listen" toml:"listen"`
AccessLog bool `toml:"access_log"` AccessLog bool `config:"access_log" toml:"access_log"`
WebrootIndexDisable bool `toml:"webroot_index_disable"` WebrootIndexDisable bool `config:"webroot_index_disable" toml:"webroot_index_disable"`
Webroot string `toml:"webroot"` Webroot string `config:"webroot" toml:"webroot"`
WebrootFS http.FileSystem `toml:"-"` WebrootFS http.FileSystem `config:"-" toml:"-"`
ACME struct { ACME struct {
Enable bool `toml:"enable"` Enable bool `config:"enable" toml:"enable"`
Domains []string `toml:"domains"` Domains []string `config:"domains" toml:"domains"`
Cache string `toml:"cache"` Cache string `config: "cache" toml:"cache"`
} `toml:"acme"` } `config:"acme" toml:"acme"`
Session struct { Session struct {
Name string `toml:"name"` Name string `config:"name" toml:"name"`
Secret string `toml:"secret"` Secret string `config: "secret" toml:"secret"`
} `toml:"session"` } `config:"session" toml:"session"`
// internal // internal
DB *gorm.DB `toml:"-"` DB *gorm.DB `config:"-" toml:"-"`
Mailer *mailer.Service `toml:"-"` Mailer *mailer.Service `config:"-" toml:"-"`
log *zap.Logger log *zap.Logger
modules []ModuleRegisterFunc modules []ModuleRegisterFunc