Documentation ¶
Index ¶
- func ApiPost(ctx context.Context, api string, req, resp any) (err error)
- func CallApi[T any](ctx context.Context, api string, req any) (*T, error)
- func FetchAndInsertPagedData[RESP, L any](ctx context.Context, api string, req page.PageReq, fn func(resp *RESP) []L, ...) error
- func GetPageAll[A interface{ ... }, B, C any](ctx context.Context, api string, req A, fn func(resp *B) []C) ([]C, error)
- func GetPageAllWithMaxNum[A interface{ ... }, B, C any](ctx context.Context, api string, req A, fn func(resp *B) []C, maxItems int) ([]C, error)
- func PageNext[Req pagination, Resp any, Elem any](ctx context.Context, req Req, ...) ([]Elem, error)
- func PostWithTimeOut(url string, data interface{}, token string, timeout time.Duration) (content []byte, err error)
- func Str2bytes(s string) []byte
- type ApiResponse
- type HttpCli
- func (c *HttpCli) BodyWithBytes(buf []byte) *HttpCli
- func (c *HttpCli) BodyWithForm(form map[string]string) *HttpCli
- func (c *HttpCli) BodyWithJson(obj interface{}) *HttpCli
- func (c *HttpCli) SetHeader(key, value string) *HttpCli
- func (c *HttpCli) SetTimeOut(timeout time.Duration) *HttpCli
- func (c *HttpCli) ToBytes() (content []byte, err error)
- func (c *HttpCli) ToJson(obj interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApiPost ¶ added in v3.8.1
ApiPost performs an HTTP POST request to a specified API endpoint. It serializes the request object, sends it to the API, and unmarshals the response into the resp object. It handles logging, error wrapping, and operation ID validation. Context (ctx) is used for passing metadata and control information. api: the API endpoint to which the request is sent. req: the request object to be sent to the API. resp: a pointer to the response object where the API response will be unmarshalled. Returns an error if the request fails at any stage.
func CallApi ¶ added in v3.8.1
CallApi wraps ApiPost to make an API call and unmarshal the response into a new instance of type T.
func FetchAndInsertPagedData ¶ added in v3.8.1
func GetPageAll ¶ added in v3.8.1
func GetPageAll[A interface { GetPagination() *sdkws.RequestPagination }, B, C any](ctx context.Context, api string, req A, fn func(resp *B) []C) ([]C, error)
GetPageAll handles pagination for API requests. It iterates over pages of data until all data is retrieved. A is the request type with pagination support, B is the response type, and C is the type of data to be returned. The function fn processes each page of response data to extract a slice of C.
func GetPageAllWithMaxNum ¶ added in v3.8.1
func PostWithTimeOut ¶
Types ¶
type ApiResponse ¶ added in v3.8.1
type ApiResponse struct { ErrCode int `json:"errCode"` ErrMsg string `json:"errMsg"` ErrDlt string `json:"errDlt"` Data json.RawMessage `json:"data"` }
ApiResponse represents the standard structure of an API response.
type HttpCli ¶
type HttpCli struct { Error error // contains filtered or unexported fields }