client

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotStringSlice = errors.New("payload must be a string slice")
	ErrNotStructSlice = errors.New("payload must be a struct slice")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	types.Logger
	// contains filtered or unexported fields
}

func New

func New(addr string, opts ...Option) (*Client, error)

New creates a new client instance with given base URL and options. The base URL must start with "http://" or "https://".

func (*Client) Create

func (c *Client) Create(payload any) (*Resp, error)

Create send a POST request to create a new resource. payload can be []byte or struct/pointer that can be marshaled to JSON.

func (*Client) CreateMany

func (c *Client) CreateMany(payload any) (*Resp, error)

CreateMany send a POST request to batch create multiple resources. payload should be a struct slice, eg: []User or []*User

func (*Client) Delete

func (c *Client) Delete(id string) (*Resp, error)

Delete send a DELETE request to delete a resource.

func (*Client) DeleteMany

func (c *Client) DeleteMany(payload any) (*Resp, error)

DeleteMany send a DELETE request to batch delete multiple resources. payload should be a string slice contains id list.

func (*Client) Get

func (c *Client) Get(id string, dst any) (*Resp, error)

Get send a GET request to get one resource by given id. The id parameter specifies which resource to retrieve. The dst parameter must be a pointer to struct where the resource will be unmarshaled into.

func (*Client) List

func (c *Client) List(items any, total *int64) (*Resp, error)

List send a GET request to retrieve a list of resources. items must be a pointer to slice where items will be unmarshaled into. total will be set to the total number of items available.

func (*Client) Patch

func (c *Client) Patch(id string, payload any) (*Resp, error)

Patch send a PATCH request to partially update a resource.

func (*Client) PatchMany

func (c *Client) PatchMany(payload any) (*Resp, error)

PatchMany send a PATCH request to batch partially update multiple resources. payload should be a struct slice, eg: []User or []*User

func (*Client) QueryString

func (c *Client) QueryString() (string, error)

QueryString build the query string from structured query parameters and raw query string.

func (*Client) RequestURL

func (c *Client) RequestURL() (string, error)

RequestURL constructs the full request URL including base URL and query parameters.

func (*Client) Update

func (c *Client) Update(id string, payload any) (*Resp, error)

Update send a PUT request to fully update a resource.

func (*Client) UpdateMany

func (c *Client) UpdateMany(payload any) (*Resp, error)

UpdateMany send a PUT request to batch update multiple resources. payload should be a struct slice, eg: []User or []*User

type Option

type Option func(*Client)

func WithBaseAuth

func WithBaseAuth(username, password string) Option

func WithContext

func WithContext(ctx context.Context) Option

func WithDebug

func WithDebug() Option

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

func WithHeader

func WithHeader(header http.Header) Option

func WithLogger

func WithLogger(logger types.Logger) Option

func WithQuery

func WithQuery(_keyValues ...any) Option

func WithQueryExpand

func WithQueryExpand(expand string, depth uint) Option

func WithQueryFuzzy

func WithQueryFuzzy(fuzzy bool) Option

func WithQueryIndex

func WithQueryIndex(index string) Option

func WithQueryNocache

func WithQueryNocache(nocache bool) Option

func WithQueryOr

func WithQueryOr(or bool) Option

func WithQueryPagination

func WithQueryPagination(page, size uint) Option

func WithQuerySelect

func WithQuerySelect(selects ...string) Option

func WithQuerySortby

func WithQuerySortby(sortby string) Option

func WithQueryTimeRange

func WithQueryTimeRange(columeName string, start, end time.Time) Option

func WithRateLimit

func WithRateLimit(r rate.Limit, b int) Option

func WithRetry

func WithRetry(maxRetries int, wait time.Duration) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

func WithToken

func WithToken(token string) Option

func WithUserAgent

func WithUserAgent(userAgent string) Option

type Resp

type Resp struct {
	Code      int             `json:"code"`
	Msg       string          `json:"msg"`
	Data      json.RawMessage `json:"data"`
	RequestID string          `json:"request_id"`
}

Jump to

Keyboard shortcuts

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