github.com/zooyer/miskit@v1.0.71/sdk/neeko/neeko.go (about) 1 package neeko 2 3 import ( 4 "context" 5 "fmt" 6 "strings" 7 "time" 8 9 "github.com/zooyer/miskit/zrpc" 10 ) 11 12 type Client struct { 13 url string 14 addr string 15 client *zrpc.Client 16 } 17 18 type SystemInfo struct { 19 SystemID string `json:"system_id"` 20 DeviceID string `json:"device_id"` 21 } 22 23 func New() *Client { 24 return &Client{ 25 addr: "127.0.0.1:54321", 26 client: zrpc.New("neeko", 1, 50*time.Millisecond, nil), 27 } 28 } 29 30 func (c *Client) api(version int, uri string) string { 31 return fmt.Sprintf("http://%s/neeko/api/v%d/%s", c.addr, version, strings.TrimLeft(uri, "/")) 32 } 33 34 func (c *Client) SystemInfo(ctx context.Context) (info *SystemInfo, err error) { 35 var resp SystemInfo 36 37 if _, _, err = c.client.Get(ctx, c.api(1, "/system/info"), nil, &resp); err != nil { 38 return 39 } 40 41 return &resp, nil 42 }