-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jess Frazelle <[email protected]>
- Loading branch information
Showing
13 changed files
with
4,389 additions
and
804 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v0.2.32 | ||
v0.2.33 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// {{.Description}} | ||
func Example{{.Tag}}Service_{{.Name}}() { | ||
client, err := {{.PackageName}}.NewClientFromEnv("your apps user agent") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
buf := new(bytes.Buffer) | ||
|
||
{{if .Response}} | ||
result, err := client.{{.Tag}}.{{.Name}}({{range .Args -}}{{.Example}},{{end -}} buf) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("%#v", result) | ||
{{else}} | ||
if err := client.{{.Tag}}.{{.Name}}({{range .Args -}}{{.Example}},{{end -}} buf); err != nil { | ||
panic(err) | ||
} | ||
{{end}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// {{.Description}} | ||
func (s *{{.Tag}}Service) {{.Name}}({{range .Args -}}{{.Name}} {{.Type}},{{end -}} body *bytes.Buffer) {{if .Response}}(*{{.Response.Type}}, error){{else}}error{{end}} { | ||
// Create the url. | ||
path := "{{.Path}}" | ||
uri := resolveRelative(s.client.server, path) | ||
|
||
|
||
// Create the request. | ||
req, err := http.NewRequest("{{.Method}}", uri, body) | ||
if err != nil { | ||
return {{if .Response}}nil,{{end}} fmt.Errorf("error creating request: %v", err) | ||
} | ||
|
||
{{if .RequestBody}} | ||
// Add our headers. | ||
req.Header.Add("Content-Type", "{{.RequestBody.MediaType}}") | ||
{{end}} | ||
|
||
{{if .Args}} | ||
// Add the parameters to the url. | ||
if err := expandURL(req.URL, map[string]string{ | ||
{{range .Args -}} | ||
"{{.Property}}": {{.ToString}}, | ||
{{end -}} | ||
}); err != nil { | ||
return {{if .Response}}nil,{{end}} fmt.Errorf("expanding URL with parameters failed: %v", err) | ||
} | ||
{{end}} | ||
|
||
// Send the request. | ||
resp, err := s.client.client.Do(req) | ||
if err != nil { | ||
return {{if .Response}}nil,{{end}} fmt.Errorf("error sending request: %v", err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
// Check the response. | ||
if err := checkResponse(resp); err != nil { | ||
return {{if .Response}}nil,{{end}} err | ||
} | ||
|
||
{{if .Response}} | ||
// Decode the body from the response. | ||
if resp.Body == nil { | ||
return nil, errors.New("request returned an empty body in the response") | ||
} | ||
var decoded {{.Response.Type}} | ||
if err := json.NewDecoder(resp.Body).Decode(&decoded); err != nil { | ||
return nil, fmt.Errorf("error decoding response body: %v", err) | ||
} | ||
|
||
// Return the response. | ||
return &decoded, nil | ||
{{else}} | ||
// Return. | ||
return nil | ||
{{end}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.