codec

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package codec holds encoding decoding reading writing stuff

Index

Constants

This section is empty.

Variables

View Source
var ErrEndOfResults = errors.New("No results are left to read")

ErrEndOfResults denotes absence of results

Functions

func EncodeReqBody

func EncodeReqBody(data interface{}, req *http.Request) error

EncodeReqBody encodes data into the req as a json object

func EncodeReqFormData

func EncodeReqFormData(data interface{}) (io.ReadCloser, string, error)

EncodeReqFormData encodes data passed as a form data. NOTE: data must be a pointer to a struct type.

func EncodeReqQuery

func EncodeReqQuery(data interface{}, req *http.Request) error

EncodeReqQuery encodes data passed as an http.Request query string. NOTE: data must be a pointer to a struct type.

Types

type NextRawResulter

type NextRawResulter interface {
	Next() bool
	ReadRawResult() (Raw, error)
}

NextRawResulter abstracts reading raw results from paginated api response

type Raw

type Raw []byte

Raw represents raw bytes data

func (*Raw) UnmarshalJSON

func (v *Raw) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type ResultBuf

type ResultBuf struct {
	Ctx       context.Context
	ReqMethod string
	Client    ucare.Client

	sync.Mutex         // guards everything below
	NextPage   *string `json:"next"`
	Vals       []Raw   `json:"results"`
	// contains filtered or unexported fields
}

ResultBuf implements NextRawResulter

func (*ResultBuf) Next

func (b *ResultBuf) Next() bool

Next indicates if there is a result to read

func (*ResultBuf) ReadRawResult

func (b *ResultBuf) ReadRawResult() (Raw, error)

ReadRawResult reads returns next Raw result. It makes paginated requests when all results from the current page have been read.

type TypeErr

type TypeErr struct {
	Data string
	Type string
}

TypeErr is basically !ok casting case

func (TypeErr) Error

func (e TypeErr) Error() string

Jump to

Keyboard shortcuts

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