fdk

package
v1.0.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DateFormat = "2006-01-02"
	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, log log.Logger) (res *http.Response, err error)

func CopyResponse added in v1.0.9

func CopyResponse(res *http.Response) ([]byte, 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 RetryForRateLimited added in v1.0.9

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

func SaveResponse added in v1.0.9

func SaveResponse(res *http.Response, path string) error

func SleepForRateLimited added in v1.0.9

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

SleepForRateLimited 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 Attachments added in v1.0.9

type Attachments []*Attachment

func (Attachments) Files added in v1.0.9

func (as Attachments) Files() Files

type Date added in v1.0.9

type Date struct {
	time.Time
}

func (*Date) MarshalJSON added in v1.0.9

func (d *Date) MarshalJSON() ([]byte, error)

func (*Date) String added in v1.0.9

func (d *Date) String() string

func (*Date) UnmarshalJSON added in v1.0.9

func (d *Date) UnmarshalJSON(data []byte) (err error)

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) (buf []byte, err error)

func (*FDK) DoDownloadNoAuth added in v1.0.9

func (fdk *FDK) DoDownloadNoAuth(url string) (buf []byte, err 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) (next bool, err 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) DoSaveFile added in v1.0.9

func (fdk *FDK) DoSaveFile(url string, path string) error

func (*FDK) DoSaveFileNoAuth added in v1.0.9

func (fdk *FDK) DoSaveFileNoAuth(url string, path string) error

func (*FDK) Endpoint added in v1.0.9

func (fdk *FDK) Endpoint(format string, a ...any) string

Endpoint formats endpoint url

func (*FDK) RetryForRateLimited added in v1.0.9

func (fdk *FDK) RetryForRateLimited(api func() error) (err error)

func (*FDK) SleepForRateLimited added in v1.0.9

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

SleepForRateLimited 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 {
	IsNil() bool
	Values() Values
}

type PageOption added in v1.0.9

type PageOption struct {
	Page    int
	PerPage int
}

func (*PageOption) IsNil added in v1.0.9

func (po *PageOption) IsNil() bool

func (*PageOption) Values added in v1.0.9

func (po *PageOption) 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) SetDate added in v1.0.9

func (vs Values) SetDate(name string, value Date)

func (Values) SetDatePtr added in v1.0.9

func (vs Values) SetDatePtr(name string, value *Date)

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