Skip to content

Commit

Permalink
Add context to HTTP client request object
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Greenleaf committed Aug 23, 2018
1 parent db3d663 commit 58e4d2d
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 75 deletions.
4 changes: 2 additions & 2 deletions codegen/template_bundle/template_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codegen/templates/http_client.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (c *{{$clientName}}) {{$methodName}}(
{{if .ResponseType -}}
var defaultRes {{.ResponseType}}
{{end -}}
req := zanzibar.NewClientHTTPRequest(c.clientID, "{{$methodName}}", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "{{$methodName}}", c.httpClient)

{{if .ReqHeaderGoStatements }}
{{range $index, $line := .ReqClientHeaderGoStatements -}}
Expand Down
58 changes: 29 additions & 29 deletions codegen/test_data/clients/bar.gogen
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (c *barClient) ArgNotStruct(
headers map[string]string,
r *clientsBarBar.Bar_ArgNotStruct_Args,
) (map[string]string, error) {
req := zanzibar.NewClientHTTPRequest(c.clientID, "ArgNotStruct", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "ArgNotStruct", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/arg-not-struct-path"
Expand Down Expand Up @@ -317,7 +317,7 @@ func (c *barClient) ArgWithHeaders(
r *clientsBarBar.Bar_ArgWithHeaders_Args,
) (*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes *clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "ArgWithHeaders", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "ArgWithHeaders", c.httpClient)

headers["name"] = string(r.Name)
headers["x-uuid"] = string(*r.UserUUID)
Expand Down Expand Up @@ -377,7 +377,7 @@ func (c *barClient) ArgWithManyQueryParams(
r *clientsBarBar.Bar_ArgWithManyQueryParams_Args,
) (*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes *clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "ArgWithManyQueryParams", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "ArgWithManyQueryParams", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/bar" + "/argWithManyQueryParams"
Expand Down Expand Up @@ -510,7 +510,7 @@ func (c *barClient) ArgWithNestedQueryParams(
r *clientsBarBar.Bar_ArgWithNestedQueryParams_Args,
) (*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes *clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "ArgWithNestedQueryParams", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "ArgWithNestedQueryParams", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/bar" + "/argWithNestedQueryParams"
Expand Down Expand Up @@ -603,7 +603,7 @@ func (c *barClient) ArgWithParams(
r *clientsBarBar.Bar_ArgWithParams_Args,
) (*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes *clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "ArgWithParams", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "ArgWithParams", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/bar" + "/argWithParams" + "/" + string(r.UUID) + "/segment" + "/" + string(r.Params.UserUUID)
Expand Down Expand Up @@ -658,7 +658,7 @@ func (c *barClient) ArgWithQueryHeader(
r *clientsBarBar.Bar_ArgWithQueryHeader_Args,
) (*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes *clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "ArgWithQueryHeader", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "ArgWithQueryHeader", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/bar" + "/argWithQueryHeader"
Expand Down Expand Up @@ -710,7 +710,7 @@ func (c *barClient) ArgWithQueryParams(
r *clientsBarBar.Bar_ArgWithQueryParams_Args,
) (*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes *clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "ArgWithQueryParams", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "ArgWithQueryParams", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/bar" + "/argWithQueryParams"
Expand Down Expand Up @@ -778,7 +778,7 @@ func (c *barClient) Hello(
headers map[string]string,
) (string, map[string]string, error) {
var defaultRes string
req := zanzibar.NewClientHTTPRequest(c.clientID, "Hello", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "Hello", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/bar" + "/hello"
Expand Down Expand Up @@ -837,7 +837,7 @@ func (c *barClient) MissingArg(
headers map[string]string,
) (*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes *clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "MissingArg", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "MissingArg", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/missing-arg-path"
Expand Down Expand Up @@ -897,7 +897,7 @@ func (c *barClient) NoRequest(
headers map[string]string,
) (*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes *clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "NoRequest", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "NoRequest", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/no-request-path"
Expand Down Expand Up @@ -958,7 +958,7 @@ func (c *barClient) Normal(
r *clientsBarBar.Bar_Normal_Args,
) (*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes *clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "Normal", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "Normal", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/bar-path"
Expand Down Expand Up @@ -1019,7 +1019,7 @@ func (c *barClient) NormalRecur(
r *clientsBarBar.Bar_NormalRecur_Args,
) (*clientsBarBar.BarResponseRecur, map[string]string, error) {
var defaultRes *clientsBarBar.BarResponseRecur
req := zanzibar.NewClientHTTPRequest(c.clientID, "NormalRecur", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "NormalRecur", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/bar" + "/recur"
Expand Down Expand Up @@ -1079,7 +1079,7 @@ func (c *barClient) TooManyArgs(
r *clientsBarBar.Bar_TooManyArgs_Args,
) (*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes *clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "TooManyArgs", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "TooManyArgs", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/too-many-args-path"
Expand Down Expand Up @@ -1148,7 +1148,7 @@ func (c *barClient) EchoBinary(
r *clientsBarBar.Echo_EchoBinary_Args,
) ([]byte, map[string]string, error) {
var defaultRes []byte
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoBinary", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoBinary", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/binary"
Expand Down Expand Up @@ -1204,7 +1204,7 @@ func (c *barClient) EchoBool(
r *clientsBarBar.Echo_EchoBool_Args,
) (bool, map[string]string, error) {
var defaultRes bool
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoBool", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoBool", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/bool"
Expand Down Expand Up @@ -1260,7 +1260,7 @@ func (c *barClient) EchoDouble(
r *clientsBarBar.Echo_EchoDouble_Args,
) (float64, map[string]string, error) {
var defaultRes float64
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoDouble", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoDouble", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/double"
Expand Down Expand Up @@ -1316,7 +1316,7 @@ func (c *barClient) EchoEnum(
r *clientsBarBar.Echo_EchoEnum_Args,
) (clientsBarBar.Fruit, map[string]string, error) {
var defaultRes clientsBarBar.Fruit
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoEnum", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoEnum", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/enum"
Expand Down Expand Up @@ -1372,7 +1372,7 @@ func (c *barClient) EchoI16(
r *clientsBarBar.Echo_EchoI16_Args,
) (int16, map[string]string, error) {
var defaultRes int16
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoI16", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoI16", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/i16"
Expand Down Expand Up @@ -1428,7 +1428,7 @@ func (c *barClient) EchoI32(
r *clientsBarBar.Echo_EchoI32_Args,
) (int32, map[string]string, error) {
var defaultRes int32
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoI32", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoI32", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/i32"
Expand Down Expand Up @@ -1484,7 +1484,7 @@ func (c *barClient) EchoI32Map(
r *clientsBarBar.Echo_EchoI32Map_Args,
) (map[int32]*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes map[int32]*clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoI32Map", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoI32Map", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/i32-map"
Expand Down Expand Up @@ -1540,7 +1540,7 @@ func (c *barClient) EchoI64(
r *clientsBarBar.Echo_EchoI64_Args,
) (int64, map[string]string, error) {
var defaultRes int64
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoI64", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoI64", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/i64"
Expand Down Expand Up @@ -1596,7 +1596,7 @@ func (c *barClient) EchoI8(
r *clientsBarBar.Echo_EchoI8_Args,
) (int8, map[string]string, error) {
var defaultRes int8
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoI8", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoI8", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/i8"
Expand Down Expand Up @@ -1652,7 +1652,7 @@ func (c *barClient) EchoString(
r *clientsBarBar.Echo_EchoString_Args,
) (string, map[string]string, error) {
var defaultRes string
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoString", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoString", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/string"
Expand Down Expand Up @@ -1708,7 +1708,7 @@ func (c *barClient) EchoStringList(
r *clientsBarBar.Echo_EchoStringList_Args,
) ([]string, map[string]string, error) {
var defaultRes []string
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoStringList", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoStringList", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/string-list"
Expand Down Expand Up @@ -1764,7 +1764,7 @@ func (c *barClient) EchoStringMap(
r *clientsBarBar.Echo_EchoStringMap_Args,
) (map[string]*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes map[string]*clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoStringMap", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoStringMap", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/string-map"
Expand Down Expand Up @@ -1820,7 +1820,7 @@ func (c *barClient) EchoStringSet(
r *clientsBarBar.Echo_EchoStringSet_Args,
) (map[string]struct{}, map[string]string, error) {
var defaultRes map[string]struct{}
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoStringSet", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoStringSet", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/string-set"
Expand Down Expand Up @@ -1876,7 +1876,7 @@ func (c *barClient) EchoStructList(
r *clientsBarBar.Echo_EchoStructList_Args,
) ([]*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes []*clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoStructList", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoStructList", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/struct-list"
Expand Down Expand Up @@ -1932,7 +1932,7 @@ func (c *barClient) EchoStructSet(
r *clientsBarBar.Echo_EchoStructSet_Args,
) ([]*clientsBarBar.BarResponse, map[string]string, error) {
var defaultRes []*clientsBarBar.BarResponse
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoStructSet", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoStructSet", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/struct-set"
Expand Down Expand Up @@ -1988,7 +1988,7 @@ func (c *barClient) EchoTypedef(
r *clientsBarBar.Echo_EchoTypedef_Args,
) (clientsBarBar.UUID, map[string]string, error) {
var defaultRes clientsBarBar.UUID
req := zanzibar.NewClientHTTPRequest(c.clientID, "EchoTypedef", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "EchoTypedef", c.httpClient)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/typedef"
Expand Down

0 comments on commit 58e4d2d

Please sign in to comment.