fdk

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const TimeFormat = "2006-01-02T15:04:05Z"

Variables

This section is empty.

Functions

func BuildRequest

func BuildRequest(a any) (io.Reader, string, error)

BuildRequest build a fdk request, returns buffer, contentType, error

func Call

func Call(client *http.Client, req *http.Request, retryOnRateLimited int, log log.Logger) (res *http.Response, err error)

func DecodeResponse

func DecodeResponse(res *http.Response, obj any) error

func LogRequest

func LogRequest(log log.Logger, req *http.Request) (rid uint64)

func LogResponse

func LogResponse(log log.Logger, res *http.Response, rid uint64)

func SleepAndRetry

func SleepAndRetry(api func() error, maxRetry int, log log.Logger) (err error)

func SleepForRetry

func SleepForRetry(err error, log log.Logger) bool

SleepForRetry if err is RateLimitedError, sleep Retry-After and return true

func ToString

func ToString(o any) string

Types

type Attachment

type Attachment struct {
	ID int64 `json:"id,omitempty"`

	Name string `json:"name,omitempty"`

	Size int `json:"size,omitempty"`

	ContentType string `json:"content_type,omitempty"`

	AttachmentURL string `json:"attachment_url,omitempty"`

	CanonicalURL string `json:"canonical_url,omitempty"`

	CreatedAt *Time `json:"created_at,omitempty"`

	UpdatedAt *Time `json:"updated_at,omitempty"`
	// contains filtered or unexported fields
}

func NewAttachment

func NewAttachment(file string, data ...[]byte) *Attachment

func (*Attachment) Data

func (a *Attachment) Data() []byte

func (*Attachment) Field

func (a *Attachment) Field() string

func (*Attachment) File

func (a *Attachment) File() string

func (*Attachment) String

func (a *Attachment) String() string

type Error

type Error struct {
	Code    string `json:"code,omitempty"`
	Field   string `json:"field,omitempty"`
	Message string `json:"message,omitempty"`
}

func (*Error) Error

func (e *Error) Error() string

type ErrorResult

type ErrorResult struct {
	StatusCode  int      `json:"-"` // http status code
	Status      string   `json:"-"` // http status
	Code        string   `json:"code,omitempty"`
	Message     string   `json:"message,omitempty"`
	Description string   `json:"description,omitempty"`
	Errors      []*Error `json:"errors,omitempty"`
}

func (*ErrorResult) Error

func (er *ErrorResult) Error() string

type FDK

type FDK struct {
	Domain   string
	Apikey   string
	Username string
	Password string

	Transport http.RoundTripper
	Timeout   time.Duration
	Logger    log.Logger

	RetryOnRateLimited int
}

func (*FDK) DoDelete

func (fdk *FDK) DoDelete(url string) error

func (*FDK) DoDownload

func (fdk *FDK) DoDownload(url string) ([]byte, error)

func (*FDK) DoGet

func (fdk *FDK) DoGet(url string, result any) error

func (*FDK) DoList

func (fdk *FDK) DoList(url string, lo ListOption, ap any) (bool, error)

func (*FDK) DoPost

func (fdk *FDK) DoPost(url string, source, result any) error

func (*FDK) DoPut

func (fdk *FDK) DoPut(url string, source, result any) error

func (*FDK) DoSave

func (fdk *FDK) DoSave(url string, filename string) error

func (*FDK) SleepAndRetry

func (fdk *FDK) SleepAndRetry(api func() error, maxRetry int) (err error)

func (*FDK) SleepForRetry

func (fdk *FDK) SleepForRetry(err error) bool

SleepForRetry if err is RateLimitedError, sleep Retry-After and return true

type File

type File interface {
	Field() string
	File() string
	Data() []byte
}

type Files

type Files []File

type ListOption

type ListOption interface {
	Values() Values
}

type RateLimitedError

type RateLimitedError struct {
	StatusCode int // http status code
	RetryAfter int // retry after seconds
}

func (*RateLimitedError) Error

func (e *RateLimitedError) Error() string

type Time

type Time struct {
	time.Time
}

func (*Time) MarshalJSON

func (t *Time) MarshalJSON() ([]byte, error)

func (*Time) String

func (t *Time) String() string

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) (err error)

type Values

type Values url.Values

func (Values) Encode

func (vs Values) Encode() string

func (Values) Map

func (vs Values) Map() map[string][]string

func (Values) SetBool

func (vs Values) SetBool(name string, value bool)

func (Values) SetInt

func (vs Values) SetInt(name string, value int)

func (Values) SetInt64

func (vs Values) SetInt64(name string, value int64)

func (Values) SetInt64s

func (vs Values) SetInt64s(name string, value []int64)

func (Values) SetInts

func (vs Values) SetInts(name string, value []int)

func (Values) SetMap

func (vs Values) SetMap(name string, value map[string]any)

func (Values) SetString

func (vs Values) SetString(name string, value string)

func (Values) SetStrings

func (vs Values) SetStrings(name string, value []string)

func (Values) SetTime

func (vs Values) SetTime(name string, value Time)

func (Values) SetTimePtr

func (vs Values) SetTimePtr(name string, value *Time)

type WithFiles

type WithFiles interface {
	Files() Files
	Values() Values
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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