httpx

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildFormBody

func BuildFormBody(data map[string]string) io.Reader

func CheckStatus

func CheckStatus(resp *http.Response) error

func DecodeResponse

func DecodeResponse(resp *http.Response) (io.ReadCloser, error)

func ErrEncryptParams

func ErrEncryptParams(err error) error

ErrEncryptParams wraps encryption parameter errors

func GenerateZaloSignKey

func GenerateZaloSignKey(apiType string, params map[string]any) string

func IsClientError

func IsClientError(resp *http.Response) bool

func IsServerError

func IsServerError(resp *http.Response) bool

func IsSuccess

func IsSuccess(resp *http.Response) bool

func JoinURL

func JoinURL(base, path string) string

func MakeURL

func MakeURL(
	sc session.Context,
	baseURL string,
	params map[string]any,
	includeDefaults bool,
) string

func ReadBytes

func ReadBytes(resp *http.Response) ([]byte, error)

func ReadJSON

func ReadJSON(resp *http.Response, target any) error

func ReadString

func ReadString(resp *http.Response) (string, error)

func Request

func Request(ctx context.Context, sc session.MutableContext, urlStr string, opt *RequestOptions) (*http.Response, error)

func ResolveURL

func ResolveURL(base, href string) string

func SignZaloURL

func SignZaloURL(baseURL string, apiType string, params map[string]any) string

Types

type BaseResponse

type BaseResponse = Response[*string]

func ParseBaseResponse

func ParseBaseResponse(resp *http.Response) (*BaseResponse, error)

type BuildOptions

type BuildOptions struct {
	FileName    string // default: "blob"
	ContentType string // default: auto-detect then fallback to octet-stream
	ChunkSize   int64  // >0 => build chunks; else single form
}

type EncryptParamResult

type EncryptParamResult struct {
	Params map[string]any
	Enk    *string
}

func GetEncryptParam

func GetEncryptParam(sc session.Context, encryptParams bool, typeStr string) (*EncryptParamResult, error)

GetEncryptParam generates encrypted parameters for Zalo API requests

type EncryptedPayload

type EncryptedPayload struct {
	EncryptedData   string `json:"encrypted_data"`
	EncryptedParams Params `json:"encrypted_params"`
	Enk             string `json:"enk"`
}

func EncryptParam

func EncryptParam(sc session.Context, data map[string]any) (*EncryptedPayload, error)

EncryptParam encrypts the provided data using session context

type FormData

type FormData struct {
	Body   *bytes.Buffer
	Header http.Header
}

func BuildFormData

func BuildFormData(fieldName string, source io.Reader, opts ...Opt) ([]*FormData, error)

type Opt

type Opt func(*BuildOptions)

func WithChunkSize

func WithChunkSize(n int64) Opt

func WithContentType

func WithContentType(ct string) Opt

func WithFileName

func WithFileName(name string) Opt

type Params

type Params struct {
	ZCID          string `json:"zcid"`
	EncryptVer    string `json:"enc_ver"`
	ZCIDExtension string `json:"zcid_ext"`
}

func (*Params) ToMap

func (p *Params) ToMap() map[string]any

type ParamsEncryptor

type ParamsEncryptor interface {
	GetEncryptKey() (string, error)
	GetParams() *Params
}

func NewParamsEncryptor

func NewParamsEncryptor(apiType uint, imei string, firstLaunchTime int64) (ParamsEncryptor, error)

type RequestOptions

type RequestOptions struct {
	Method  string
	Headers http.Header
	Query   url.Values
	Body    io.Reader
	Raw     bool
}

type Response

type Response[T any] struct {
	ErrorCode    int    `json:"error_code"`
	ErrorMessage string `json:"error_message"`
	Data         T      `json:"data"`
}

type URLBuilder

type URLBuilder struct {
	// contains filtered or unexported fields
}

func NewURL

func NewURL(baseURL string) *URLBuilder

func (*URLBuilder) Build

func (u *URLBuilder) Build() string

func (*URLBuilder) Param

func (u *URLBuilder) Param(key, value string) *URLBuilder

func (*URLBuilder) Params

func (u *URLBuilder) Params(params map[string]string) *URLBuilder

type ZaloResponse

type ZaloResponse[T any] struct {
	Meta struct {
		Code    int
		Message string
	}
	Data T
}

func HandleZaloResponse

func HandleZaloResponse[T any](sc session.Context, resp *http.Response, isEncrypted bool) *ZaloResponse[T]

func ParseZaloResponse

func ParseZaloResponse[T any](resp *http.Response) (*ZaloResponse[T], error)

Jump to

Keyboard shortcuts

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