/
client.go
38 lines (31 loc) · 835 Bytes
/
client.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
package typhon
import (
"github.com/bingoohuang/gou/str"
"github.com/bingoohuang/typhon4g/base"
)
// MetaRsp defines the meta response structure of typhon meta service.
type MetaRsp struct {
Status int `json:"status"`
Message string `json:"message"`
Data string `json:"data"`
}
// Client defines the typhon client.
type Client struct {
*base.Context
fileRaw chan base.FileRawWait
}
// MetaGet gets the config servers address from the meta server.
func (c *Client) MetaGet(addr string) ([]string, error) {
var rsp MetaRsp
if err := c.Req.RestGet(addr, &rsp); err != nil {
return nil, err
}
return str.SplitN(rsp.Data, ",", true, true), nil
}
// MakeClient makes a apollo client.
func MakeClient(c *base.Context, fileRaw chan base.FileRawWait) *Client {
return &Client{
Context: c,
fileRaw: fileRaw,
}
}