util

package
v3.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 12 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 Batch

func Batch[T any, V any](fn func(T) V, ts []T) []V

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 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 NoticeChange

func NoticeChange[T any](fn func(data string)) func(ctx context.Context, state int, value T) 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