add basic query struct, support 1.12
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package {{.PackageName}}
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type {{.ResponseName}} = {{.ResponseType}}
|
||||
|
||||
// {{.OperationDoc}}
|
||||
func {{.OperationName}}(ctx context.Context) (*{{.ResponseName}}, error) {
|
||||
req, err := http.NewRequest(
|
||||
http.MethodPost,
|
||||
`{{.Endpoint}}`,
|
||||
strings.NewReader(`{{.Operation}}`))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req = req.WithContext(ctx)
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
retval := {{.ResponseName}}{}
|
||||
err = json.Unmarshal(body, &retval)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &retval, nil
|
||||
}
|
||||
Reference in New Issue
Block a user