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
type Database struct {
DB *gorm.DB `toml:"-"`
Connection string `toml:"connection"`
Debug bool `toml:"debug"`
Testdata bool `toml:"testdata"`
LogLevel logger.LogLevel `toml:"log_level"`
DB *gorm.DB `config:"-" toml:"-"`
Connection string `config:"connection" toml:"connection"`
Debug bool `config:"debug" toml:"debug"`
Testdata bool `config:"testdata" toml:"testdata"`
LogLevel logger.LogLevel `config:"log_level" toml:"log_level"`
migrations map[string]*gormigrate.Migration
migrationTestdata map[string]*gormigrate.Migration
}

View File

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

View File

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

View File

@ -6,13 +6,13 @@ import (
// Service to send mail
type Service struct {
SMTPHost string `toml:"smtp_host"`
SMTPPort int `toml:"smtp_port"`
SMTPUsername string `toml:"smtp_username"`
SMTPPassword string `toml:"smtp_password"`
SMTPSSL bool `toml:"smtp_ssl"`
Dailer *mail.Dialer `toml:"-"`
From string `toml:"from"`
SMTPHost string `config:"smtp_host" toml:"smtp_host"`
SMTPPort int `config:"smtp_port" toml:"smtp_port"`
SMTPUsername string `config:"smtp_username" toml:"smtp_username"`
SMTPPassword string `config:"smtp_password" toml:"smtp_password"`
SMTPSSL bool `config:"smtp_ssl" toml:"smtp_ssl"`
Dailer *mail.Dialer `config:"-" toml:"-"`
From string `config:"from" toml:"from"`
}
// 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.
type FSInfo struct {
FSType fsType `toml:"type"`
FSType fsType `config:"type" toml:"type"`
// file system
Root string `toml:",omitempty"`
Root string `config:",omitempty" toml:",omitempty"`
// s3
Endpoint string `toml:",omitempty"`
Secure bool `toml:",omitempty"`
ID string `toml:",omitempty"`
Secret string `toml:",omitempty"`
Bucket string `toml:",omitempty"`
Location string `toml:",omitempty"`
Endpoint string `config:",omitempty" toml:",omitempty"`
Secure bool `config:",omitempty" toml:",omitempty"`
ID string `config:",omitempty" toml:",omitempty"`
Secret string `config:",omitempty" toml:",omitempty"`
Bucket string `config:",omitempty" toml:",omitempty"`
Location string `config:",omitempty" toml:",omitempty"`
}
// Create creates a file store from the information provided.

View File

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