package invoke import ( "git.sxidc.com/service-supports/dapr_api/utils" "github.com/go-resty/resty/v2" "net/url" "time" ) type API struct { client *resty.Client baseUrl string } func NewAPI(baseUrl string, timeout time.Duration) *API { return &API{ client: resty.New().SetTimeout(timeout), baseUrl: baseUrl, } } func DestroyAPI(api *API) { if api == nil { return } api.baseUrl = "" api.client = nil } func (api *API) PostJSON() { } func (api *API) GetJSON() { } func (api *API) PutJSON() { } func (api *API) DeleteJSON() { } func (api *API) Post(methodName string, headers map[string]string, data []byte) ([]byte, error) { invokeUrl, err := url.JoinPath(api.baseUrl, methodName) if err != nil { return nil, err } resp, err := api.client.R(). SetHeaders(headers). SetBody(data). Post(invokeUrl) if err != nil { return nil, err } if resp.IsError() { return nil, utils.ResponseStatusError(resp) } return resp.Body(), nil } func (api *API) Get() { } func (api *API) Put() { } func (api *API) Delete() { }