httpagent

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 14 Imported by: 6

README

httpagent

一个简洁易用的 HTTP-User-Agent 客户端

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMainModule added in v0.0.4

func NewMainModule() *application.ModuleBuilder

NewMainModule ...

func NewTestModule added in v0.0.4

func NewTestModule() *application.ModuleBuilder

NewTestModule ...

Types

type Client

type Client interface {
	Execute(req *Request) (*Response, error)
}

Client 是一个简易的 HTTP 客户端

func NewClientWithFilters added in v0.0.3

func NewClientWithFilters(filters ...*FilterRegistration) Client

NewClientWithFilters ...

type ClientContext added in v0.0.4

type ClientContext struct {
	Attributes attributes.Table
	Client     Client
	Chain      FilterChain
	Filters    []*FilterRegistration
}

ClientContext ...

type Clients

type Clients interface {
	GetClient() Client
	NewClient() Client
}

Clients 是一个简易的 HTTP 客户端服务

func Default

func Default() Clients

Default 获取默认的 Clients 对象

type Context added in v0.0.4

type Context struct {
	Attributes    attributes.Table
	ClientContext *ClientContext
	Request       *Request
	Response      *Response
}

Context ...

type Entity

type Entity struct {
	ContentLength int64
	ContentType   string
	Data          []byte
}

Entity ...

func NewEntityWithBinary added in v0.0.4

func NewEntityWithBinary(bin []byte, contentType string) *Entity

NewEntityWithBinary ...

func NewEntityWithJSON added in v0.0.4

func NewEntityWithJSON(v any) *Entity

NewEntityWithJSON ...

func NewEntityWithText added in v0.0.4

func NewEntityWithText(text string, contentType string) *Entity

NewEntityWithText ...

func (*Entity) OpenReader

func (inst *Entity) OpenReader() (io.ReadCloser, error)

OpenReader ...

func (*Entity) ReadBinary

func (inst *Entity) ReadBinary() ([]byte, error)

ReadBinary ...

func (*Entity) ReadJSON

func (inst *Entity) ReadJSON(obj any) error

ReadJSON ...

func (*Entity) ReadText

func (inst *Entity) ReadText() (string, error)

ReadText ...

type Filter added in v0.0.3

type Filter interface {
	Handle(c *Context, chain FilterChain) error
}

Filter 用于过滤 web 请求

type FilterChain added in v0.0.3

type FilterChain interface {
	Handle(c *Context) error
}

FilterChain 表示一个由若干 Filter 构成的链条

type FilterChainBuilder added in v0.0.3

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

FilterChainBuilder 用于创建 FilterChain

func (*FilterChainBuilder) AddRegistration added in v0.0.3

func (inst *FilterChainBuilder) AddRegistration(list ...*FilterRegistration) *FilterChainBuilder

AddRegistration ...

func (*FilterChainBuilder) AddRegistry added in v0.0.3

func (inst *FilterChainBuilder) AddRegistry(list ...FilterRegistry) *FilterChainBuilder

AddRegistry ...

func (*FilterChainBuilder) Create added in v0.0.3

func (inst *FilterChainBuilder) Create() FilterChain

Create ...

type FilterRegistration added in v0.0.3

type FilterRegistration struct {
	Name    string
	Enabled bool
	Order   int
	Filter  Filter
}

FilterRegistration 是 Filter 的注册信息

type FilterRegistry added in v0.0.3

type FilterRegistry interface {
	FilterRegistrations() []*FilterRegistration
}

FilterRegistry 用于注册 Filter

type Headers

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

Headers ...

func (*Headers) Get

func (inst *Headers) Get(name string) string

Get ...

func (*Headers) Remove

func (inst *Headers) Remove(name string)

Remove ...

func (*Headers) Set

func (inst *Headers) Set(name, value string)

Set ...

func (*Headers) Table

func (inst *Headers) Table() map[string]string

Table ...

type Request

type Request struct {
	Context context.Context
	Method  string
	URL     string
	Headers Headers
	Body    io.ReadCloser
}

Request ...

func (*Request) SetEntity

func (inst *Request) SetEntity(entity *Entity)

SetEntity 设置请求的 body

type Response

type Response struct {
	Request *Request
	Status  int
	Message string
	Headers Headers
	Body    io.ReadCloser
}

Response ...

func (*Response) GetEntity

func (inst *Response) GetEntity() (*Entity, error)

GetEntity 以 Entity 的形式获取响应的 body

Directories

Path Synopsis
gen
modules
src

Jump to

Keyboard shortcuts

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