encoding

package
v1.35.3 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 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
	}
	CookieTag = 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 GetConcreteStructType added in v1.8.0

func GetConcreteStructType(appDecls []*schema.Decl, typ *schema.Type, typeArgs []*schema.Type) (*schema.Struct, error)

GetConcreteStructType returns a construct Struct object for the given schema. This means any generic types in the struct will be resolved to their concrete types and there will be no generic parameters in the struct object. However, any nested structs may still contain generic types.

If a nil schema is provided, a nil struct is returned.

func GetConcreteType added in v1.8.0

func GetConcreteType(appDecls []*schema.Decl, originalType *schema.Type, typeArgs []*schema.Type) (*schema.Type, error)

GetConcreteType returns a concrete type for the given schema. This means any generic types in the top level type will be resolved to their concrete types and there will be no generic parameters in returned typ. However, any nested types may still contain generic types.

If a nil schema is provided, a nil is returned.

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
	HeaderParameters []*ParameterEncoding `json:"header_parameters"`
	QueryParameters  []*ParameterEncoding `json:"query_parameters"`
	CookieParameters []*ParameterEncoding `json:"cookie_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.

func (*AuthEncoding) ParameterEncodingMapByName added in v1.13.0

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

ParameterEncodingMapByName returns the parameter encodings as a map, keyed by Name. Conflicts result in an undefined encoding getting set.

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"`
	// WireFormat is the wire format of the parameter.
	WireFormat string `json:"wire_format"`
	// Optional indicates whether the field is optional.
	Optional bool `json:"optional"`
}

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
	Cookie    ParameterLocation = "cookie"    // Parameter is placed in cookies
)

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
	HeaderParameters []*ParameterEncoding `json:"header_parameters"`
	QueryParameters  []*ParameterEncoding `json:"query_parameters"`
	BodyParameters   []*ParameterEncoding `json:"body_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.

func (*RequestEncoding) ParameterEncodingMapByName added in v1.13.0

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

ParameterEncodingMapByName returns the parameter encodings as a map, keyed by Name. Conflicts result in an undefined encoding getting set.

type ResponseEncoding

type ResponseEncoding struct {
	// Contains metadata about how to marshal an HTTP parameter
	HeaderParameters []*ParameterEncoding `json:"header_parameters"`
	BodyParameters   []*ParameterEncoding `json:"body_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.

func (*ResponseEncoding) ParameterEncodingMapByName added in v1.13.0

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

ParameterEncodingMapByName returns the parameter encodings as a map, keyed by Name. Conflicts result in an undefined encoding getting set.

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