forked from kitex-contrib/optionloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder.go
83 lines (66 loc) · 2.11 KB
/
decoder.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
71
72
73
74
75
76
77
78
79
80
81
82
83
package etcdclient
import (
"encoding/json"
"fmt"
"strings"
)
type ConfigParser interface {
Decode(data []byte, config *EtcdConfig) error
}
type defaultParser struct {
}
func (p *defaultParser) Decode(data []byte, config *EtcdConfig) error {
return json.Unmarshal(data, config)
}
type Config interface {
String() string
}
type EtcdConfig struct {
ClientBasicInfo *EndpointBasicInfo `mapstructure:"ClientBasicInfo"`
HostPorts []string `mapstructure:"HostPorts"`
DestService *string `mapstructure:"DestService"`
Protocol *string `mapstructure:"Protocol"`
Connection *Connection `mapstructure:"Connection"`
MyConfig Config `mapstructure:"MyConfig"`
}
func (c *EtcdConfig) String() string {
var builder strings.Builder
if c.ClientBasicInfo != nil {
builder.WriteString(fmt.Sprintf("ClientBasicInfo: %v\n", *c.ClientBasicInfo))
}
if c.HostPorts != nil {
builder.WriteString(fmt.Sprintf("HostPorts: %v\n", c.HostPorts))
}
if c.DestService != nil {
builder.WriteString(fmt.Sprintf("DestService: %v\n", *c.DestService))
}
if c.Protocol != nil {
builder.WriteString(fmt.Sprintf("Protocol: %v\n", *c.Protocol))
}
if c.Connection != nil {
builder.WriteString(fmt.Sprintf("Connection: %v\n", *c.Connection))
}
if c.MyConfig != nil {
builder.WriteString(c.MyConfig.String())
}
return builder.String()
}
type EndpointBasicInfo struct {
ServiceName string `mapstructure:"ServiceName"`
Method string `mapstructure:"Method"`
Tags map[string]string `mapstructure:"Tags"`
}
type IdleConfig struct {
MinIdlePerAddress int `mapstructure:"MinIdlePerAddress"`
MaxIdlePerAddress int `mapstructure:"MaxIdlePerAddress"`
MaxIdleGlobal int `mapstructure:"MaxIdleGlobal"`
MaxIdleTimeout string `mapstructure:"MaxIdleTimeout"`
}
type MuxConnection struct {
ConnNum int `mapstructure:"ConnNum"`
}
type Connection struct {
Method string `mapstructure:"Method"`
LongConnection IdleConfig `mapstructure:"LongConnection"`
MuxConnection MuxConnection `mapstructure:"MuxConnection"`
}