client

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoParser       = DataParser{R: ByteReader, W: ByteWriter}
	JsonParser     = DataParser{R: JsonReader, W: JsonWriter}
	TextParser     = DataParser{R: TextReader, W: TextWriter}
	FormParser     = DataParser{} // 暂时不实现
	GetFileParser  = DataParser{} // 暂时不实现
	SendFileParser = DataParser{} // 暂时不实现
)

Functions

func ByteReader added in v0.2.7

func ByteReader(req any) ([]byte, error)

func ByteWriter added in v0.2.7

func ByteWriter(b []byte, res any) error

func JsonReader added in v0.2.7

func JsonReader(req any) ([]byte, error)

func JsonWriter added in v0.2.7

func JsonWriter(b []byte, res any) error

func TextReader added in v0.2.7

func TextReader(req any) ([]byte, error)

func TextWriter added in v0.2.7

func TextWriter(b []byte, res any) error

Types

type Api added in v0.2.6

type Api[R any] struct {
	Method string // 默认视为POST
	Parser DataParser
	Path   string
	Client *Client
}

常规请求定义

func (*Api[R]) Req added in v0.2.6

func (a *Api[R]) Req(req any, h map[string]string, qp ...string) (R, error)

执行网络请求

req: 请求方 body, res: 接收方 body(要求为指针类型), h: 需要的 http-header, qp: url中的参数,要求类似 "id=123" 样式,

func (*Api[R]) ReqWithCtx added in v0.2.6

func (a *Api[R]) ReqWithCtx(ctx context.Context, req any, h map[string]string, qp ...string) (R, error)

type Client added in v0.2.6

type Client struct {
	Url     string
	CrtPath string
	KeyPath string
	Timeout int

	MaxIdleConns        int
	MaxIdleConnsPerHost int
	MaxConns            int
	*http.Client
}

func (*Client) Default added in v0.2.6

func (cl *Client) Default()

func (*Client) Init added in v0.2.6

func (cl *Client) Init() error

type DataParser added in v0.2.6

type DataParser struct {
	R func(req any) ([]byte, error) // RequestReader
	W func(b []byte, res any) error // ResponseWriter
}

Jump to

Keyboard shortcuts

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