@@ -51,12 +51,27 @@ type HTTPRemoteConfig struct {
5151}
5252
5353type 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"`
5662}
5763
5864func (v * HTTPClientConfig ) Build () (proto.Message , error ) {
5965 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+ }
6075 config .Server = make ([]* protocol.ServerEndpoint , len (v .Servers ))
6176 for idx , serverConfig := range v .Servers {
6277 server := & protocol.ServerEndpoint {
@@ -65,12 +80,22 @@ func (v *HTTPClientConfig) Build() (proto.Message, error) {
6580 }
6681 for _ , rawUser := range serverConfig .Users {
6782 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+ }
7090 }
7191 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+ }
7499 }
75100 user .Account = serial .ToTypedMessage (account .Build ())
76101 server .User = append (server .User , user )
0 commit comments