-
Notifications
You must be signed in to change notification settings - Fork 1
/
agent.go
39 lines (33 loc) · 993 Bytes
/
agent.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
package config
import (
"errors"
"fmt"
"github.com/frp-sigs/frp-provisioner/pkg/log"
"github.com/spf13/pflag"
)
// AgentConfiguration is the agent configuration.
type AgentConfiguration struct {
// Log is the log options struct for zap logger
Log *log.Options `json:"log,omitempty"`
}
// AddFlags adds flags for a specific configuration to the specified FlagSet
func (c *AgentConfiguration) AddFlags(fs *pflag.FlagSet) {
c.Log.AddFlags(fs)
}
// SetDefaults sets the default values for a specific configuration.
func (c *AgentConfiguration) SetDefaults() {
c.Log.SetDefaults()
}
// Validate validates a specific configuration.
func (c *AgentConfiguration) Validate() (errs error) {
if err := c.Log.Validate(); err != nil {
errs = errors.Join(errs, fmt.Errorf("invalid log config, got: '%w'", err))
}
return errs
}
// NewAgentConfiguration create AgentConfiguration
func NewAgentConfiguration() *AgentConfiguration {
return &AgentConfiguration{
Log: log.NewOptions(),
}
}