@@ -13,12 +13,18 @@ import (
1313 "github.com/pelletier/go-toml/v2"
1414)
1515
16+ type Server struct {
17+ LogLevel string `json:"log_level,omitempty" toml:"log_level,commented"`
18+ DBPath string `json:"database_path,omitempty" toml:"database_path,commented"`
19+ Token string `json:"token,omitempty" toml:"token,commented"`
20+ ListenAddr string `json:"listen_addr,omitempty" toml:"listen_addr,commented"`
21+ CertFile string `json:"cert_file,omitempty" toml:"cert_file,commented"`
22+ KeyFile string `json:"key_file,omitempty" toml:"key_file,commented"`
23+ }
24+
1625type Config struct {
17- LogLevel string `json:"log_level,omitempty" toml:"log_level,commented"`
18- DBPath string `json:"database_path,omitempty" toml:"database_path,commented"`
19- Token string `json:"token,omitempty" toml:"token,commented"`
20- ListenAddr string `json:"listen_addr,omitempty" toml:"listen_addr,commented"`
21- Endpoints []Endpoint `json:"endpoints,omitempty" toml:"endpoints,commented"`
26+ Server Server `json:"server,omitempty" toml:"server,commented"`
27+ Endpoints []Endpoint `json:"endpoints,omitempty" toml:"endpoints,commented"`
2228
2329 configPath string
2430 sha string
@@ -27,15 +33,19 @@ type Config struct {
2733func (c * Config ) validate () error {
2834 uid := os .Getuid ()
2935
30- if c .ListenAddr == "" {
36+ if c .Server . ListenAddr == "" {
3137 return errors .New ("listen_addr must not be empty" )
3238 }
3339
34- if _ , _ , err := net .SplitHostPort (c .ListenAddr ); err != nil {
40+ if c .Server .Token == "" {
41+ return errors .New ("server token must not be empty" )
42+ }
43+
44+ if _ , _ , err := net .SplitHostPort (c .Server .ListenAddr ); err != nil {
3545 return fmt .Errorf ("listen_addr must be host:port or :port: %v" , err )
3646 }
3747
38- _ , err := parseLogLevel (c .LogLevel )
48+ _ , err := parseLogLevel (c .Server . LogLevel )
3949 if err != nil {
4050 return fmt .Errorf ("invalid log level: %v" , err )
4151 }
@@ -55,8 +65,6 @@ func (c *Config) validate() error {
5565 "path" , e .Path ,
5666 "index" , i ,
5767 )
58- } else if c .Token == "" && e .Token == "" {
59- return fmt .Errorf ("token missing for path: %q: set global token or endpoint[%d].token" , e .Path , i )
6068 }
6169
6270 if _ , dup := seen [e .Path ]; dup {
@@ -74,7 +82,7 @@ func (c *Config) setDefaults() error {
7482 return errors .New ("cannot set defaults on nil config" )
7583 }
7684
77- c .ListenAddr = cmp .Or (c .ListenAddr , defaultListenAddr )
85+ c .Server . ListenAddr = cmp .Or (c . Server .ListenAddr , defaultListenAddr )
7886
7987 return nil
8088}
@@ -85,14 +93,10 @@ func (c *Config) redact() *Config {
8593 }
8694
8795 redacted := * c
88-
89- if redacted .Token != "" {
90- redacted .Token = redact
91- }
92-
9396 redacted .Endpoints = append ([]Endpoint (nil ), redacted .Endpoints ... )
94- for i , e := range redacted .Endpoints {
95- redacted .Endpoints [i ] = e .redact ()
97+
98+ if redacted .Server .Token != "" {
99+ redacted .Server .Token = redact
96100 }
97101
98102 return & redacted
0 commit comments