-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
53 lines (46 loc) · 1.13 KB
/
configuration.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
package pb
import "go.uber.org/zap/zapcore"
func (c *Config) Copy() *Config {
out := &Config{}
for _, peer := range c.Peers {
out.Peers = append(out.Peers, peer.Copy())
}
return out
}
func (c *Config) MarshalLogObject(e zapcore.ObjectEncoder) error {
if c == nil {
return nil
}
if err := e.AddArray("peers", PeerArray(c.Peers)); err != nil {
return err
}
return nil
}
func (c *Configuration) Copy() *Configuration {
out := &Configuration{Current: c.Current.Copy()}
if out.Next != nil {
out.Next = c.Next.Copy()
}
return out
}
func (c *Configuration) CopyInitiateTransition(next *Config) *Configuration {
return &Configuration{Current: c.Current.Copy(), Next: next.Copy()}
}
func (c *Configuration) CopyCommitTransition() *Configuration {
return &Configuration{Current: c.Next.Copy()}
}
func (c *Configuration) MarshalLogObject(e zapcore.ObjectEncoder) error {
if err := e.AddObject("current", c.Current); err != nil {
return err
}
if c.Next == nil {
if err := e.AddReflected("next", nil); err != nil {
return err
}
} else {
if err := e.AddObject("next", c.Next); err != nil {
return err
}
}
return nil
}