util

package
v3.8.0-rc.17 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApiPost

func ApiPost(ctx context.Context, api string, req, resp any) (err error)

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

func CallApi[T any](ctx context.Context, api string, req any) (*T, error)

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.0

func FetchAndInsertPagedData[RESP, L any](ctx context.Context, api string, req page.PageReq, fn func(resp *RESP) []L, batchInsertFn func(ctx context.Context, items []L) error,
	insertFn func(ctx context.Context, item L) error, maxItems int64) error

func GetPageAll

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.0

func GetPageAllWithMaxNum[A interface {
	GetPagination() *sdkws.RequestPagination
}, B, C any](ctx context.Context, api string, req A, fn func(resp *B) []C, maxItems int) ([]C, error)

Types

type ApiResponse

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.

Jump to

Keyboard shortcuts

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