Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalReq ¶
func MarshalReq(input interface{}) events.APIGatewayProxyRequest
MarshalReq will take an interface input, marshal it to JSON, and add the JSON as a string to the events.APIGatewayProxyRequest body field before returning.
func UnmarshalReq ¶
func UnmarshalReq(req events.APIGatewayProxyRequest, body bool, target interface{}) error
UnmarshalReq "fills" out a target Go struct with data from the req. If body is true, then the req body is assumed to be JSON and simply unmarshalled into the target (taking into account that the req body may be base-64 encoded). After that, or if body is false, the function will traverse the exported fields of the target struct, and fill those that include the "lambda" struct tag with values taken from the request's query string parameters, path parameters and headers, according to the field's struct tag definition. This means a struct value can be filled with data from the body, the path, the query string and the headers at the same time.
Field types are currently limited to string, all integer types, all unsigned integer types, all float types, booleans, slices of the aforementioned types and pointers of these types.
Note that custom types that alias any of the aforementioned types are also accepted and the appropriate constant values will be generated. Boolean fields accept (in a case-insensitive way) the values "1", "true", "on" and "enabled". Any other value is considered false.
Example struct (no body):
type ListPostsInput struct { ID uint64 `lambda:"path.id"` Page uint64 `lambda:"query.page"` PageSize uint64 `lambda:"query.page_size"` Search string `lambda:"query.search"` ShowDrafts bool `lambda:"query.show_hidden"` Languages []string `lambda:"header.Accept-Language"` }
Example struct (JSON body):
type UpdatePostInput struct { ID uint64 `lambda:"path.id"` Author string `lambda:"header.Author"` Title string `json:"title"` Content string `json:"content"` }
Types ¶
This section is empty.