encoding

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MPL-2.0 Imports: 10 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.

func IgnoreField added in v1.2.0

func IgnoreField(field *schema.Field) bool

IgnoreField returns true if the field name is "-" is any of the valid request or response tags

Types

type APIEncoding added in v1.2.0

type APIEncoding struct {
	Services      []*ServiceEncoding `json:"services"`
	Authorization *AuthEncoding      `json:"authorization"`
}

func DescribeAPI added in v1.2.0

func DescribeAPI(meta *meta.Data) *APIEncoding

type AuthEncoding

type AuthEncoding struct {
	// LegacyTokenFormat specifies whether the auth encoding uses the legacy format of
	// "just give us a token as a string". If true, the other parameters are all empty.
	LegacyTokenFormat bool

	// 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. If authSchema is nil it returns nil, nil.

func (*AuthEncoding) ParameterEncodingMap added in v1.2.0

func (e *AuthEncoding) ParameterEncodingMap() map[string]*ParameterEncoding

ParameterEncodingMap returns the parameter encodings as a map, keyed by SrcName.

type Options

type Options struct {
	// SrcNameTag, if set, specifies which source tag should be used to determine
	// the value of the SrcName field in the returned parameter descriptions.
	//
	// If the given SrcNameTag is not present on the field, SrcName will be set
	// to the Go field name instead.
	//
	// If SrcNameTag is empty, SrcName is set to the Go field name.
	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"`
	// Location is the location this encoding is for.
	Location ParameterLocation `json:"location"`
	// OmitEmpty specifies whether the parameter should be omitted if it's empty.
	OmitEmpty bool `json:"omit_empty"`
	// SrcName is the name of the struct field
	SrcName string `json:"src_name"`
	// Doc is the documentation of the struct field
	Doc string `json:"doc"`
	// Type is the field's type description.
	Type *schema.Type `json:"type"`
	// RawTag specifies the raw, unparsed struct tag for the field.
	RawTag string `json:"raw_tag"`
}

ParameterEncoding expresses how a parameter should be encoded on the wire

type ParameterLocation

type ParameterLocation string

ParameterLocation is the request/response home of the parameter

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

type RPCEncoding

type RPCEncoding struct {
	Name        string     `json:"name"`
	Doc         string     `json:"doc"`
	AccessType  string     `json:"access_type"`
	Proto       string     `json:"proto"`
	Path        *meta.Path `json:"path"`
	HttpMethods []string   `json:"http_methods"`

	DefaultMethod string `json:"default_method"`
	// Expresses how the default request encoding and method should be
	// Note: DefaultRequestEncoding.HTTPMethods will always be a slice with length 1
	DefaultRequestEncoding *RequestEncoding `json:"request_encoding"`
	// Expresses all the different ways the request can be encoded for this RPC
	RequestEncoding []*RequestEncoding `json:"all_request_encodings"`
	// 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. If the method is not supported by the RPC it reports nil.

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

func (*RequestEncoding) ParameterEncodingMap added in v1.2.0

func (e *RequestEncoding) ParameterEncodingMap() map[string]*ParameterEncoding

ParameterEncodingMap returns the parameter encodings as a map, keyed by SrcName.

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

func (*ResponseEncoding) ParameterEncodingMap added in v1.2.0

func (e *ResponseEncoding) ParameterEncodingMap() map[string]*ParameterEncoding

ParameterEncodingMap returns the parameter encodings as a map, keyed by SrcName.

type ServiceEncoding added in v1.2.0

type ServiceEncoding struct {
	Name string         `json:"name"`
	Doc  string         `json:"doc"`
	RPCs []*RPCEncoding `json:"rpcs"`
}

func DescribeService added in v1.2.0

func DescribeService(meta *meta.Data, svc *meta.Service) *ServiceEncoding

Jump to

Keyboard shortcuts

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