Files
go-gin-api/internal/api/third_party_request/go_gin_api/demoget.go
T
新亮 eba8929b4d feature(安装): 安装时新增选择语言包
- 安装时新增选择语言包
- 优化代码并删除无用的代码
2021-06-26 12:06:20 +08:00

64 lines
1.2 KiB
Go

package go_gin_api
import (
"encoding/json"
"github.com/xinliangnote/go-gin-api/pkg/httpclient"
"github.com/pkg/errors"
)
// 接口地址
var demoGetApi = "http://127.0.0.1:9999/demo/get/"
// 接口返回结构
type demoGetResponse struct {
Name string `json:"name"`
Job string `json:"job"`
}
// DemoGet 发起请求
func DemoGet(name string, opts ...httpclient.Option) (res *demoGetResponse, err error) {
api := demoGetApi + name
body, err := httpclient.Get(api, nil, opts...)
if err != nil {
return nil, err
}
res = new(demoGetResponse)
err = json.Unmarshal(body, res)
if err != nil {
return nil, errors.Wrap(err, "DemoGet json unmarshal error")
}
return res, nil
}
// DemoGetRetryVerify 设置重试规则
func DemoGetRetryVerify(body []byte) (shouldRetry bool) {
if len(body) == 0 {
return true
}
return false
}
// DemoGetAlarmVerify 设置告警规则
func DemoGetAlarmVerify(body []byte) (shouldAlarm bool) {
if len(body) == 0 {
return true
}
return false
}
// DemoGetMock 设置 Mock 数据
func DemoGetMock() (body []byte) {
res := new(demoGetResponse)
res.Name = "AA"
res.Job = "AA_JOB"
body, _ = json.Marshal(res)
return body
}