encoding

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2022 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	QueryTag = tagDescription{
				// contains filtered or unexported fields
	}
	QsTag     = QueryTag
	HeaderTag = tagDescription{
				// contains filtered or unexported fields
	}
	JSONTag = tagDescription{
			// contains filtered or unexported fields
	}
)

Functions

func DefaultClientHttpMethod

func DefaultClientHttpMethod(rpc *meta.RPC) string

DefaultClientHttpMethod works out the default HTTP method a client should use for a given RPC. When possible we will default to POST either when no method has been specified on the API or when then is a selection of methods and POST is one of them. If POST is not allowed as a method then we will use the first specified method.

Types

type AuthEncoding

type AuthEncoding struct {
	// Contains metadata about how to marshal an HTTP parameter
	QueryParameters  []*ParameterEncoding `json:"query_parameters"`
	HeaderParameters []*ParameterEncoding `json:"header_parameters"`
}

AuthEncoding expresses how a response should be encoded on the wire

func DescribeAuth

func DescribeAuth(appMetaData *meta.Data, authSchema *schema.Type, options *Options) (*AuthEncoding, error)

DescribeAuth generates a ParameterEncoding per field of the auth struct and returns it as the AuthEncoding

type Options

type Options struct {
	SrcNameTag string
}

type ParameterEncoding

type ParameterEncoding struct {
	// The location specific name of the parameter (e.g. cheeseEater, cheese-eater, X-Cheese-Eater
	Name string `json:"name"`
	// Whether the parameter should be omitted if it's empty
	OmitEmpty bool `json:"omit_empty"`
	// The name of the struct field
	SrcName string `json:"src_name"`
	// Doc of the struct field
	Doc string `json:"doc"`
	// The field type
	Type *schema.Type `json:"type"`
	// The raw tag of the field
	RawTag string `json:"-"`
}

ParameterEncoding expresses how a parameter should be encoded on the wire

type ParameterLocation

type ParameterLocation int

ParameterLocation is the request/response home of the parameter

const (
	Undefined ParameterLocation = iota // Parameter location is Undefined
	Header                             // Parameter is placed in the HTTP header
	Query                              // Parameter is placed in the query string
	Body                               // Parameter is placed in the body
)

type RPCEncoding

type RPCEncoding struct {
	// Expresses how the default request encoding and method should be
	// Note: DefaultRequestEncoding.HTTPMethods will always be a slice with length 1
	DefaultRequestEncoding *RequestEncoding `json:"default_request_encoding"`
	// Expresses all the different ways the request can be encoded for this RPC
	RequestEncoding []*RequestEncoding `json:"request_encoding"`
	// Expresses how the response to this RPC will be encoded
	ResponseEncoding *ResponseEncoding `json:"response_encoding"`
}

RPCEncoding expresses how an RPC should be encoded on the wire for both the request and responses.

func DescribeRPC

func DescribeRPC(appMetaData *meta.Data, rpc *meta.RPC, options *Options) (*RPCEncoding, error)

DescribeRPC expresses how to encode an RPCs request and response objects for the wire.

func (*RPCEncoding) RequestEncodingForMethod

func (e *RPCEncoding) RequestEncodingForMethod(method string) *RequestEncoding

RequestEncodingForMethod returns the request encoding required for the given HTTP method

type RequestEncoding

type RequestEncoding struct {
	// The HTTP methods these field configurations can be used for
	HTTPMethods []string `json:"http_methods"`
	// Contains metadata about how to marshal an HTTP parameter
	BodyParameters   []*ParameterEncoding `json:"body_parameters"`
	HeaderParameters []*ParameterEncoding `json:"header_parameters"`
	QueryParameters  []*ParameterEncoding `json:"query_parameters"`
}

RequestEncoding expresses how a request should be encoded for an explicit set of HTTPMethods

func DescribeRequest

func DescribeRequest(appMetaData *meta.Data, requestSchema *schema.Type, options *Options, httpMethods ...string) ([]*RequestEncoding, error)

DescribeRequest groups the provided httpMethods by default ParameterLocation and returns a RequestEncoding per ParameterLocation

type ResponseEncoding

type ResponseEncoding struct {
	// Contains metadata about how to marshal an HTTP parameter
	BodyParameters   []*ParameterEncoding `json:"body_parameters"`
	HeaderParameters []*ParameterEncoding `json:"header_parameters"`
}

ResponseEncoding expresses how a response should be encoded on the wire

func DescribeResponse

func DescribeResponse(appMetaData *meta.Data, responseSchema *schema.Type, options *Options) (*ResponseEncoding, error)

DescribeResponse generates a ParameterEncoding per field of the response struct and returns it as the ResponseEncoding

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL