@@ -51,12 +51,27 @@ type HTTPRemoteConfig struct {
51
51
}
52
52
53
53
type HTTPClientConfig struct {
54
- Servers []* HTTPRemoteConfig `json:"servers"`
55
- Headers map [string ]string `json:"headers"`
54
+ Address * Address `json:"address"`
55
+ Port uint16 `json:"port"`
56
+ Level uint32 `json:"level"`
57
+ Email string `json:"email"`
58
+ Username string `json:"user"`
59
+ Password string `json:"pass"`
60
+ Servers []* HTTPRemoteConfig `json:"servers"`
61
+ Headers map [string ]string `json:"headers"`
56
62
}
57
63
58
64
func (v * HTTPClientConfig ) Build () (proto.Message , error ) {
59
65
config := new (http.ClientConfig )
66
+ if v .Address != nil {
67
+ v .Servers = []* HTTPRemoteConfig {
68
+ {
69
+ Address : v .Address ,
70
+ Port : v .Port ,
71
+ Users : []json.RawMessage {{}},
72
+ },
73
+ }
74
+ }
60
75
config .Server = make ([]* protocol.ServerEndpoint , len (v .Servers ))
61
76
for idx , serverConfig := range v .Servers {
62
77
server := & protocol.ServerEndpoint {
@@ -65,12 +80,22 @@ func (v *HTTPClientConfig) Build() (proto.Message, error) {
65
80
}
66
81
for _ , rawUser := range serverConfig .Users {
67
82
user := new (protocol.User )
68
- if err := json .Unmarshal (rawUser , user ); err != nil {
69
- return nil , errors .New ("failed to parse HTTP user" ).Base (err ).AtError ()
83
+ if v .Address != nil {
84
+ user .Level = v .Level
85
+ user .Email = v .Email
86
+ } else {
87
+ if err := json .Unmarshal (rawUser , user ); err != nil {
88
+ return nil , errors .New ("failed to parse HTTP user" ).Base (err ).AtError ()
89
+ }
70
90
}
71
91
account := new (HTTPAccount )
72
- if err := json .Unmarshal (rawUser , account ); err != nil {
73
- return nil , errors .New ("failed to parse HTTP account" ).Base (err ).AtError ()
92
+ if v .Address != nil {
93
+ account .Username = v .Username
94
+ account .Password = v .Password
95
+ } else {
96
+ if err := json .Unmarshal (rawUser , account ); err != nil {
97
+ return nil , errors .New ("failed to parse HTTP account" ).Base (err ).AtError ()
98
+ }
74
99
}
75
100
user .Account = serial .ToTypedMessage (account .Build ())
76
101
server .User = append (server .User , user )
0 commit comments