-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
config.go
63 lines (55 loc) · 1.54 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
package client
import (
"fmt"
"time"
nats "github.com/nats-io/nats.go"
"github.com/plgd-dev/hub/v2/pkg/security/certManager/client"
)
type PendingLimitsConfig struct {
MsgLimit int `yaml:"msgLimit" json:"msgLimit"`
BytesLimit int `yaml:"bytesLimit" json:"bytesLimit"`
}
func (c *PendingLimitsConfig) Validate() error {
if c.MsgLimit == 0 {
return fmt.Errorf("msgLimit('%v')", c.MsgLimit)
}
if c.BytesLimit == 0 {
return fmt.Errorf("bytesLimit('%v')", c.BytesLimit)
}
return nil
}
type Config struct {
URL string `yaml:"url" json:"url"`
FlusherTimeout time.Duration `yaml:"flusherTimeout" json:"flusherTimeout"`
PendingLimits PendingLimitsConfig `yaml:"pendingLimits" json:"pendingLimits"`
TLS client.Config `yaml:"tls" json:"tls"`
Options []nats.Option `yaml:"-" json:"-"`
}
type ConfigPublisher struct {
JetStream bool `yaml:"jetstream" json:"jetstream"`
Config `yaml:",inline" json:",inline"`
}
func (c *Config) Validate() error {
if c.URL == "" {
return fmt.Errorf("url('%v')", c.URL)
}
if err := c.PendingLimits.Validate(); err != nil {
return fmt.Errorf("pendingLimits.%w", err)
}
if err := c.TLS.Validate(); err != nil {
return fmt.Errorf("tls.%w", err)
}
return nil
}
func (c *ConfigPublisher) Validate() error {
if c.URL == "" {
return fmt.Errorf("url('%v')", c.URL)
}
if c.FlusherTimeout <= 0 {
return fmt.Errorf("flusherTimeout('%v')", c.FlusherTimeout)
}
if err := c.TLS.Validate(); err != nil {
return fmt.Errorf("tls.%w", err)
}
return nil
}