Documentation ¶
Index ¶
- func BindQueryParameter(style string, explode bool, required bool, paramName string, ...) error
- func BindStringToObject(src string, dst interface{}) error
- func BindStyledParameter(style string, explode bool, paramName string, value string, dest interface{}) error
- func BindStyledParameterWithLocation(style string, explode bool, paramName string, paramLocation ParamLocation, ...) error
- func MarshalDeepObject(i interface{}, paramName string) (string, error)
- func StyleParamWithLocation(style string, explode bool, paramName string, paramLocation ParamLocation, ...) (string, error)
- func UnmarshalDeepObject(dst interface{}, paramName string, params url.Values) error
- type Binder
- type ParamLocation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindQueryParameter ¶
func BindQueryParameter(style string, explode bool, required bool, paramName string, queryParams url.Values, dest interface{}) error
BindQueryParameter works much like BindStyledParameter, however it takes a query argument input array from the url package, since query arguments come through a different path than the styled arguments. They're also exceptionally fussy.
For example, consider the exploded and unexploded form parameter examples: (exploded) /users?role=admin&firstName=Alex (unexploded) /users?id=role,admin,firstName,Alex
In the first case, we can pull the "id" parameter off the context, and unmarshal via json as an intermediate. Easy. In the second case, we don't have the id QueryParam present, but must find "role", and "firstName". what if there is another parameter similar to "ID" named "role"? We can't tell them apart. This code tries to fail, but the moral of the story is that you shouldn't pass objects via form styled query arguments, just use the Content parameter form.
func BindStringToObject ¶
BindStringToObject takes a string, and attempts to assign it to the destination interface via whatever type conversion is necessary. We have to do this via reflection instead of a much simpler type switch so that we can handle type aliases. This function was the easy way out, the better way, since we know the destination type each place that we use this, is to generate code to read each specific type.
func BindStyledParameter ¶
func BindStyledParameter(style string, explode bool, paramName string, value string, dest interface{}) error
BindStyledParameter binds a parameter as described in the Path Parameters section here to a Go object: https://swagger.io/docs/specification/serialization/ It is a backward compatible function to clients generated with codegen up to version v1.5.5. v1.5.6+ calls the function below.
func BindStyledParameterWithLocation ¶
func BindStyledParameterWithLocation(style string, explode bool, paramName string, paramLocation ParamLocation, value string, dest interface{}) error
BindStyledParameterWithLocation parameter as described in the Path Parameters section here to a Go object: https://swagger.io/docs/specification/serialization/
func MarshalDeepObject ¶
MarshalDeepObject marshals i deeply using paramName.
func StyleParamWithLocation ¶
func StyleParamWithLocation(style string, explode bool, paramName string, paramLocation ParamLocation, value interface{}) (string, error)
StyleParamWithLocation converts value into a parameter based on the options provided, and necessary escaping necessary.
Types ¶
type Binder ¶
Binder is the interface implemented by types that can be bound to a query string or a parameter string The input can be assumed to be a valid string. If you define a Bind method you are responsible for all data being completely bound to the type.
By convention, to approximate the behavior of Bind functions themselves, Binder implements Bind("") as a no-op.
type ParamLocation ¶
type ParamLocation int
ParamLocation escaping works differently based on where a header is found
const ( ParamLocationUndefined ParamLocation = iota ParamLocationQuery ParamLocationPath ParamLocationHeader ParamLocationCookie )
List of locations where Params can be.