fresh

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateFormat = time.DateOnly // "2006-01-02"
	TimeFormat = time.RFC3339  // "2006-01-02T15:04:05Z07:00"
)

Variables

This section is empty.

Functions

func BuildJSONRequest

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

func BuildMultipartRequest

func BuildMultipartRequest(vs Values, fs Files) (io.Reader, string, error)

func IsResultError added in v1.1.4

func IsResultError(err error) bool

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

type Attachments []*Attachment

func (Attachments) Files

func (as Attachments) Files() Files

type Client added in v1.1.6

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

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

	MaxRetries  int
	RetryAfter  time.Duration
	ShouldRetry func(error) bool // default retry on not canceled error or (status = 429 || (status >= 500 && status <= 599))
}

func (*Client) DoCall added in v1.1.6

func (c *Client) DoCall(req *http.Request, result any) error

func (*Client) DoCopyFile added in v1.1.6

func (c *Client) DoCopyFile(ctx context.Context, url string, w io.Writer) error

func (*Client) DoCopyFileNoAuth added in v1.1.6

func (c *Client) DoCopyFileNoAuth(ctx context.Context, url string, w io.Writer) error

func (*Client) DoDelete added in v1.1.6

func (c *Client) DoDelete(ctx context.Context, url string) error

func (*Client) DoGet added in v1.1.6

func (c *Client) DoGet(ctx context.Context, url string, result any) error

func (*Client) DoList added in v1.1.6

func (c *Client) DoList(ctx context.Context, url string, lo ListOption, ap any) (next bool, err error)

func (*Client) DoPost added in v1.1.6

func (c *Client) DoPost(ctx context.Context, url string, source, result any) error

func (*Client) DoPut added in v1.1.6

func (c *Client) DoPut(ctx context.Context, url string, source, result any) error

func (*Client) DoReadFile added in v1.1.6

func (c *Client) DoReadFile(ctx context.Context, url string) (buf []byte, err error)

func (*Client) DoReadFileNoAuth added in v1.1.6

func (c *Client) DoReadFileNoAuth(ctx context.Context, url string) (buf []byte, err error)

func (*Client) DoSaveFile added in v1.1.6

func (c *Client) DoSaveFile(ctx context.Context, url string, path string) error

func (*Client) DoSaveFileNoAuth added in v1.1.6

func (c *Client) DoSaveFileNoAuth(ctx context.Context, url string, path string) error

func (*Client) Endpoint added in v1.1.6

func (c *Client) Endpoint(format string, a ...any) string

Endpoint formats endpoint url

func (*Client) RetryForError added in v1.1.6

func (c *Client) RetryForError(ctx context.Context, api func() error) (err error)

type CustomRequest

type CustomRequest interface {
	RequestBody() (io.Reader, string, error)
}

type Date

type Date struct {
	time.Time
}

func ParseDate

func ParseDate(s string) (Date, error)

func (*Date) MarshalJSON

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

func (*Date) String

func (d *Date) String() string

func (*Date) UnmarshalJSON

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

type FieldError

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

func (*FieldError) Error

func (fe *FieldError) Error() string

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

type PageOption struct {
	Page    int
	PerPage int
}

func (*PageOption) IsNil

func (po *PageOption) IsNil() bool

func (*PageOption) Values

func (po *PageOption) Values() Values

type ResultError

type ResultError struct {
	Method      string        `json:"-"` // http request method
	URL         *url.URL      `json:"-"` // http request URL
	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      []*FieldError `json:"errors,omitempty"`
	RetryAfter  time.Duration `json:"-"`
}

func AsResultError added in v1.1.4

func AsResultError(err error) (re *ResultError, ok bool)

func (*ResultError) Detail

func (re *ResultError) Detail() string

func (*ResultError) Error

func (re *ResultError) Error() string

func (*ResultError) GetRetryAfter

func (re *ResultError) GetRetryAfter() time.Duration

type Time

type Time struct {
	time.Time
}

func ParseTime

func ParseTime(s string) (Time, error)

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 TimeSpent

type TimeSpent = tmu.HHMM

func ParseTimeSpent

func ParseTimeSpent(s string) (TimeSpent, error)

type Values

type Values url.Values

func (Values) Add

func (vs Values) Add(key, value string)

Add adds the value to key. It appends to any existing values associated with key.

func (Values) Del

func (vs Values) Del(key string)

Del deletes the values associated with key.

func (Values) Encode

func (vs Values) Encode() string

Encode encodes the values into “URL encoded” form ("bar=baz&foo=quux") sorted by key.

func (Values) Get

func (vs Values) Get(key string) string

Get gets the first value associated with the given key. If there are no values associated with the key, Get returns the empty string. To access multiple values, use the map directly.

func (Values) Has

func (vs Values) Has(key string) bool

Has checks whether a given key is set.

func (Values) Map

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

func (Values) Set

func (vs Values) Set(key, value string)

Set sets the key to value. It replaces any existing values.

func (Values) SetBool

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

func (Values) SetDate

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

func (Values) SetDatePtr

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

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

func (Values) SetStrings

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

func (Values) SetStringsPtr

func (vs Values) SetStringsPtr(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
}

Jump to

Keyboard shortcuts

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