Skip to content

Commit

Permalink
Add integer keyed map thrift use casse
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuntao Lu committed Oct 23, 2017
1 parent 3df1335 commit 9aa8067
Show file tree
Hide file tree
Showing 9 changed files with 1,090 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backend/repository/data/gateway_config_expected.json
Expand Up @@ -311,6 +311,7 @@
"EchoEnum": "Echo::echoEnum",
"EchoI16": "Echo::echoI16",
"EchoI32": "Echo::echoI32",
"EchoI32Map": "Echo::echoI32Map",
"EchoI64": "Echo::echoI64",
"EchoI8": "Echo::echoI8",
"EchoString": "Echo::echoString",
Expand Down Expand Up @@ -490,6 +491,10 @@
"Name": "echoI32",
"Type": "http"
},
{
"Name": "echoI32Map",
"Type": "http"
},
{
"Name": "echoI64",
"Type": "http"
Expand Down
16 changes: 16 additions & 0 deletions backend/repository/data/handler/test_cases.json
Expand Up @@ -52,6 +52,7 @@
"EchoEnum": "Echo::echoEnum",
"EchoI16": "Echo::echoI16",
"EchoI32": "Echo::echoI32",
"EchoI32Map": "Echo::echoI32Map",
"EchoI64": "Echo::echoI64",
"EchoI8": "Echo::echoI8",
"EchoString": "Echo::echoString",
Expand Down Expand Up @@ -104,6 +105,7 @@
"EchoEnum": "Echo::echoEnum",
"EchoI16": "Echo::echoI16",
"EchoI32": "Echo::echoI32",
"EchoI32Map": "Echo::echoI32Map",
"EchoI64": "Echo::echoI64",
"EchoI8": "Echo::echoI8",
"EchoString": "Echo::echoString",
Expand Down Expand Up @@ -377,6 +379,10 @@
"Name": "echoI32",
"Type": "http"
},
{
"Name": "echoI32Map",
"Type": "http"
},
{
"Name": "echoI64",
"Type": "http"
Expand Down Expand Up @@ -2336,6 +2342,7 @@
"EchoEnum": "Echo::echoEnum",
"EchoI16": "Echo::echoI16",
"EchoI32": "Echo::echoI32",
"EchoI32Map": "Echo::echoI32Map",
"EchoI64": "Echo::echoI64",
"EchoI8": "Echo::echoI8",
"EchoString": "Echo::echoString",
Expand Down Expand Up @@ -2808,6 +2815,10 @@
"Name": "echoI32",
"Type": "http"
},
{
"Name": "echoI32Map",
"Type": "http"
},
{
"Name": "echoI64",
"Type": "http"
Expand Down Expand Up @@ -3173,6 +3184,7 @@
"EchoEnum": "Echo::echoEnum",
"EchoI16": "Echo::echoI16",
"EchoI32": "Echo::echoI32",
"EchoI32Map": "Echo::echoI32Map",
"EchoI64": "Echo::echoI64",
"EchoI8": "Echo::echoI8",
"EchoString": "Echo::echoString",
Expand Down Expand Up @@ -3645,6 +3657,10 @@
"Name": "echoI32",
"Type": "http"
},
{
"Name": "echoI32Map",
"Type": "http"
},
{
"Name": "echoI64",
"Type": "http"
Expand Down
56 changes: 56 additions & 0 deletions codegen/test_data/bar.json
Expand Up @@ -1419,6 +1419,62 @@
"ConvertResponseGoStatements": null,
"RequestParamGoStatements": null
},
{
"Name": "echoI32Map",
"HTTPMethod": "POST",
"EndpointName": "",
"HTTPPath": "/echo/i32-map",
"PathSegments": [
{
"Type": "static",
"Text": "echo",
"BodyIdentifier": "",
"ParamName": "",
"Required": false
},
{
"Type": "static",
"Text": "i32-map",
"BodyIdentifier": "",
"ParamName": "",
"Required": false
}
],
"IsEndpoint": false,
"ParseQueryParamGoStatements": null,
"WriteQueryParamGoStatements": null,
"ReqHeaderGoStatements": null,
"ReqClientHeaderGoStatements": null,
"ResHeaderFields": null,
"ReqHeaders": [
"x-uuid"
],
"ResHeaders": null,
"RequestType": "*clientsBarBar.Echo_EchoI32Map_Args",
"ShortRequestType": "clientsBarBar.Echo_EchoI32Map_Args",
"ResponseType": "map[int32]*clientsBarBar.BarResponse",
"ShortResponseType": "map[int32]*clientsBarBar.BarResponse",
"OKStatusCode": {
"Code": 200,
"Message": ""
},
"Exceptions": [],
"ExceptionsIndex": {},
"ValidStatusCodes": [
200
],
"RequestBoxed": false,
"ThriftService": "Echo",
"GenCodePkgName": "clientsBarBar",
"WantAnnot": true,
"CompiledThriftSpec": null,
"Downstream": null,
"DownstreamService": "",
"DownstreamMethod": null,
"ConvertRequestGoStatements": null,
"ConvertResponseGoStatements": null,
"RequestParamGoStatements": null
},
{
"Name": "echoI64",
"HTTPMethod": "POST",
Expand Down
63 changes: 63 additions & 0 deletions codegen/test_data/clients/bar.gogen
Expand Up @@ -133,6 +133,11 @@ type Client interface {
reqHeaders map[string]string,
args *clientsBarBar.Echo_EchoI32_Args,
) (int32, map[string]string, error)
EchoI32Map(
ctx context.Context,
reqHeaders map[string]string,
args *clientsBarBar.Echo_EchoI32Map_Args,
) (map[int32]*clientsBarBar.BarResponse, map[string]string, error)
EchoI64(
ctx context.Context,
reqHeaders map[string]string,
Expand Down Expand Up @@ -229,6 +234,7 @@ func NewClient(
"EchoEnum",
"EchoI16",
"EchoI32",
"EchoI32Map",
"EchoI64",
"EchoI8",
"EchoString",
Expand Down Expand Up @@ -1450,6 +1456,63 @@ func (c *barClient) EchoI32(
}
}

// EchoI32Map calls "/echo/i32-map" endpoint.
func (c *barClient) EchoI32Map(
ctx context.Context,
headers map[string]string,
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)

// Generate full URL.
fullURL := c.httpClient.BaseURL + "/echo" + "/i32-map"

err := req.WriteJSON("POST", fullURL, headers, r)
if err != nil {
return defaultRes, nil, err
}

headerErr := req.CheckHeaders([]string{"x-uuid"})
if headerErr != nil {
return defaultRes, nil, headerErr
}

res, err := req.Do(ctx)
if err != nil {
return defaultRes, nil, err
}

respHeaders := map[string]string{}
for k := range res.Header {
respHeaders[k] = res.Header.Get(k)
}

res.CheckOKResponse([]int{200})

switch res.StatusCode {
case 200:
var responseBody map[int32]*clientsBarBar.BarResponse
err = res.ReadAndUnmarshalBody(&responseBody)
if err != nil {
return defaultRes, respHeaders, err
}

return responseBody, respHeaders, nil
default:
// TODO: log about unexpected body bytes?
_, err = res.ReadAll()
if err != nil {
return defaultRes, respHeaders, err
}
}

return defaultRes, respHeaders, &zanzibar.UnexpectedHTTPError{
StatusCode: res.StatusCode,
RawBody: res.GetRawBody(),
}
}

// EchoI64 calls "/echo/i64" endpoint.
func (c *barClient) EchoI64(
ctx context.Context,
Expand Down
63 changes: 63 additions & 0 deletions examples/example-gateway/build/clients/bar/bar.go

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

0 comments on commit 9aa8067

Please sign in to comment.