protocol

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RestLiProtocolVersion = "2.0.0"

	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{
	// contains filtered or unexported fields
}
View Source
var RestLiUrlEncoder = RestLiCodec{
	// contains filtered or unexported fields
}

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) RestLiEncodable

func (b *Bytes) RestLiEncodable()

func (*Bytes) UnmarshalJSON

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

type HostnameResolver added in v0.1.1

type HostnameResolver interface {
	GetHostnameForQuery(query string) (*url.URL, error)
}

type RestLiClient

type RestLiClient struct {
	*http.Client
	HostnameResolver
}

func (*RestLiClient) DeleteRequest added in v0.7.0

func (c *RestLiClient) DeleteRequest(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(rawQuery string) (*url.URL, error)

func (*RestLiClient) GetRequest

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

func (*RestLiClient) JsonPostRequest added in v0.3.0

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

func (*RestLiClient) JsonPutRequest added in v0.7.0

func (c *RestLiClient) JsonPutRequest(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) DecodeBoolean

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

func (*RestLiCodec) DecodeBytes

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

func (*RestLiCodec) DecodeDouble

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

func (*RestLiCodec) DecodeFloat

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

func (*RestLiCodec) DecodeInt

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

func (*RestLiCodec) DecodeLong

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

func (*RestLiCodec) DecodeString

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

func (*RestLiCodec) EncodeBoolean

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

func (*RestLiCodec) EncodeBytes

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

func (*RestLiCodec) EncodeDouble

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

func (*RestLiCodec) EncodeFloat

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

func (*RestLiCodec) EncodeInt

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

func (*RestLiCodec) EncodeLong

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

func (*RestLiCodec) EncodeString

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

type RestLiEncodable

type RestLiEncodable interface {
	RestLiEncode(codec RestLiCodec) (data string, err error)
	RestLiDecode(codec RestLiCodec, data string) (err 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) GetHostnameForQuery added in v0.1.1

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

Jump to

Keyboard shortcuts

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