-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
config.go
70 lines (59 loc) · 1.63 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package service
import (
"fmt"
"github.com/plgd-dev/hub/v2/pkg/config"
"github.com/plgd-dev/hub/v2/pkg/log"
certManagerServer "github.com/plgd-dev/hub/v2/pkg/security/certManager/server"
"github.com/plgd-dev/hub/v2/pkg/sync/task/queue"
)
type Config struct {
Log LogConfig `yaml:"log" json:"log"`
APIs APIsConfig `yaml:"apis" json:"apis"`
TaskQueue queue.Config `yaml:"taskQueue" json:"taskQueue"`
}
// Config represents application configuration
type LogConfig struct {
log.Config `yaml:",inline" json:",inline"`
DumpCoapMessages bool `yaml:"dumpCoapMessages" json:"dumpCoapMessages"`
}
func (c *Config) Validate() error {
if err := c.Log.Validate(); err != nil {
return fmt.Errorf("log.%w", err)
}
if err := c.APIs.Validate(); err != nil {
return fmt.Errorf("apis.%w", err)
}
if err := c.TaskQueue.Validate(); err != nil {
return fmt.Errorf("taskQueue.%w", err)
}
return nil
}
type APIsConfig struct {
COAP COAPConfig `yaml:"coap" json:"coap"`
}
func (c *APIsConfig) Validate() error {
if err := c.COAP.Validate(); err != nil {
return fmt.Errorf("coap.%w", err)
}
return nil
}
type COAPConfig struct {
Addr string `yaml:"address" json:"address"`
TLS TLSConfig `yaml:"tls" json:"tls"`
}
func (c *COAPConfig) Validate() error {
if c.Addr == "" {
return fmt.Errorf("address('%v')", c.Addr)
}
if err := c.TLS.Validate(); err != nil {
return fmt.Errorf("tls.%w", err)
}
return nil
}
type TLSConfig struct {
Enabled bool `yaml:"enabled" json:"enabled"`
certManagerServer.Config `yaml:",inline" json:",inline"`
}
func (c Config) String() string {
return config.ToString(c)
}