protocol

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RestLiProtocolVersion = "2.0.0"

	RestLiHeader_ID              = "X-RestLi-Id"
	RestLiHeader_Method          = "X-RestLi-Method"
	RestLiHeader_ProtocolVersion = "X-RestLi-Protocol-Version"
	RestLiHeader_ErrorResponse   = "X-RestLi-Error-Response"
)
View Source
const (
	Method_Unknown = RestLiMethod(iota)

	Method_get
	Method_create
	Method_delete
	Method_update
	Method_partial_update

	Method_batch_get
	Method_batch_create
	Method_batch_delete
	Method_batch_update
	Method_batch_partial_update

	Method_get_all

	Method_action
	Method_finder
)

Variables

View Source
var RestLiMethodNameMapping = func() map[string]RestLiMethod {
	mapping := make(map[string]RestLiMethod)
	for m := Method_get; m <= Method_finder; m++ {
		mapping[m.String()] = m
	}
	return mapping
}()
View Source
var RestLiReducedEncoder = &RestLiCodec{
	encoder: strings.NewReplacer(
		",", url.QueryEscape(","),
		"(", url.QueryEscape("("),
		")", url.QueryEscape(")"),
		"'", url.QueryEscape("'"),
		":", url.QueryEscape(":")).Replace,
	decoder: url.QueryUnescape,
}
View Source
var RestLiUrlEncoder = &RestLiCodec{
	encoder: url.QueryEscape,
	decoder: url.QueryUnescape,
}

Functions

func IsErrorResponse

func IsErrorResponse(res *http.Response) error

func SetJsonAcceptHeader added in v0.7.0

func SetJsonAcceptHeader(req *http.Request)

func SetJsonContentTypeHeader added in v0.3.0

func SetJsonContentTypeHeader(req *http.Request)

func SetRestLiHeaders added in v0.2.0

func SetRestLiHeaders(req *http.Request, method RestLiMethod)

Types

type Bytes

type Bytes []byte

func (*Bytes) MarshalJSON

func (b *Bytes) MarshalJSON() (data []byte, err error)

func (*Bytes) UnmarshalJSON

func (b *Bytes) UnmarshalJSON(data []byte) (err error)

type HostnameResolver added in v0.1.1

type HostnameResolver interface {
	// ResolveHostnameAndContextForQuery takes in the name of the service for which to resolve the hostname, along with
	// the URL for the query that is about to be sent. The service name is often the top-level parent resource's name,
	// but can be any unique identifier for a D2 endpoint. Some HostnameResolver implementations will choose to ignore
	// this parameter and resolve hostnames using a different strategy. By default, the generated code will always pass
	// in the top-level parent resource's name.
	ResolveHostnameAndContextForQuery(serviceName string, query *url.URL) (*url.URL, error)
}

type RestLiClient

type RestLiClient struct {
	*http.Client
	HostnameResolver
}

func (*RestLiClient) DeleteRequest added in v0.7.0

func (c *RestLiClient) DeleteRequest(ctx context.Context, url *url.URL, method RestLiMethod) (*http.Request, error)

func (*RestLiClient) Do

func (c *RestLiClient) Do(req *http.Request) (*http.Response, error)

Do is a very thin shim between the standard http.Client.Do. All it does it parse the response into a RestLiError if the RestLi error header is set. A non-nil Response with a non-nil error will only occur if http.Client.Do returns such values (see the corresponding documentation). Otherwise, the response will only be non-nil if the error is nil.

func (*RestLiClient) DoAndDecode added in v0.2.0

func (c *RestLiClient) DoAndDecode(req *http.Request, v interface{}) (res *http.Response, err error)

DoAndDecode calls Do and attempts to unmarshal the response into the given value. The response body will always be read to EOF and closed, to ensure the connection can be reused.

func (*RestLiClient) DoAndIgnore added in v0.2.0

func (c *RestLiClient) DoAndIgnore(req *http.Request) (res *http.Response, err error)

DoAndDecode calls Do and drops the response's body. The response body will always be read to EOF and closed, to ensure the connection can be reused.

func (*RestLiClient) FormatQueryUrl

func (c *RestLiClient) FormatQueryUrl(resourceBasename, rawQuery string) (*url.URL, error)

func (*RestLiClient) GetRequest

func (c *RestLiClient) GetRequest(ctx context.Context, url *url.URL, method RestLiMethod) (*http.Request, error)

func (*RestLiClient) JsonPostRequest added in v0.3.0

func (c *RestLiClient) JsonPostRequest(ctx context.Context, url *url.URL, restLiMethod RestLiMethod, contents interface{}) (*http.Request, error)

func (*RestLiClient) JsonPutRequest added in v0.7.0

func (c *RestLiClient) JsonPutRequest(ctx context.Context, url *url.URL, restLiMethod RestLiMethod, contents interface{}) (*http.Request, error)

func (*RestLiClient) RawPostRequest added in v0.3.0

func (c *RestLiClient) RawPostRequest(url *url.URL, method RestLiMethod, contents []byte) (*http.Request, error)

type RestLiCodec

type RestLiCodec struct {
	// contains filtered or unexported fields
}

func (*RestLiCodec) DecodeBool added in v0.8.1

func (r *RestLiCodec) DecodeBool(data string, v *bool) error

func (*RestLiCodec) DecodeBytes

func (r *RestLiCodec) DecodeBytes(data string, v *Bytes) error

func (*RestLiCodec) DecodeFloat32 added in v0.8.1

func (r *RestLiCodec) DecodeFloat32(data string, v *float32) error

func (*RestLiCodec) DecodeFloat64 added in v0.8.1

func (r *RestLiCodec) DecodeFloat64(data string, v *float64) error

func (*RestLiCodec) DecodeInt32 added in v0.8.1

func (r *RestLiCodec) DecodeInt32(data string, v *int32) error

func (*RestLiCodec) DecodeInt64 added in v0.8.1

func (r *RestLiCodec) DecodeInt64(data string, v *int64) error

func (*RestLiCodec) DecodeString

func (r *RestLiCodec) DecodeString(data string, v *string) error

func (*RestLiCodec) Encode added in v0.11.0

func (r *RestLiCodec) Encode(e RestLiEncodable) (string, error)

func (*RestLiCodec) EncodeBool added in v0.8.1

func (r *RestLiCodec) EncodeBool(v bool) string

func (*RestLiCodec) EncodeBytes

func (r *RestLiCodec) EncodeBytes(v Bytes) string

func (*RestLiCodec) EncodeFloat32 added in v0.8.1

func (r *RestLiCodec) EncodeFloat32(v float32) string

func (*RestLiCodec) EncodeFloat64 added in v0.8.1

func (r *RestLiCodec) EncodeFloat64(v float64) string

func (*RestLiCodec) EncodeInt32 added in v0.8.1

func (r *RestLiCodec) EncodeInt32(v int32) string

func (*RestLiCodec) EncodeInt64 added in v0.8.1

func (r *RestLiCodec) EncodeInt64(v int64) string

func (*RestLiCodec) EncodeString

func (r *RestLiCodec) EncodeString(v string) string

type RestLiDecodable added in v0.11.1

type RestLiDecodable interface {
	RestLiDecode(*RestLiCodec, string) error
}

type RestLiEncodable

type RestLiEncodable interface {
	RestLiEncode(*RestLiCodec, *strings.Builder) error
}

type RestLiError

type RestLiError struct {
	Status         int
	Message        string
	ExceptionClass string
	StackTrace     string

	FullResponse         []byte      `json:"-"`
	ResponseHeaders      http.Header `json:"-"`
	DeserializationError error       `json:"-"`
}

func (*RestLiError) Error

func (r *RestLiError) Error() string

func (*RestLiError) Format added in v0.7.0

func (r *RestLiError) Format(s fmt.State, verb rune)

type RestLiMethod added in v0.2.0

type RestLiMethod int

func (RestLiMethod) String added in v0.7.0

func (i RestLiMethod) String() string

type SimpleHostnameSupplier

type SimpleHostnameSupplier struct {
	Hostname *url.URL
}

func (*SimpleHostnameSupplier) ResolveHostnameAndContextForQuery added in v0.7.3

func (s *SimpleHostnameSupplier) ResolveHostnameAndContextForQuery(string, *url.URL) (*url.URL, error)

Jump to

Keyboard shortcuts

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