requests

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: Apache-2.0 Imports: 20 Imported by: 7

README

requests

a go http client for human

Examples

import "github.com/jacexh/requests"


func main() {
	_, _, err := requests.Get("https://cn.bing.com/search", requests.Params{Query: requests.Any{"q": "golang"}}, nil)
	if err != nil {
		panic(err)
	}

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func Delete

func Delete(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func DeleteWithContext added in v0.1.5

func DeleteWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func Get

func Get(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func GetBuffer

func GetBuffer() *bytes.Buffer

func GetWithContext added in v0.1.5

func GetWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)
func Head(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func HeadWithContext added in v0.1.5

func HeadWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func OptionWithContext added in v0.1.5

func OptionWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func Options

func Options(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func Patch

func Patch(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func PatchWithContext added in v0.1.5

func PatchWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func Post

func Post(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func PostWithContext added in v0.1.5

func PostWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func Put

func Put(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func PutBuffer

func PutBuffer(b *bytes.Buffer)

func PutWithContext added in v0.1.5

func PutWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func Request

func Request(method, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func RequestWithContext added in v0.1.5

func RequestWithContext(ctx context.Context, method, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func ToString added in v0.4.0

func ToString(v any) (string, error)

func Trace

func Trace(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func TraceWithContext added in v0.1.5

func TraceWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

Types

type AfterRequestHook added in v0.3.0

type AfterRequestHook func(*http.Response, error)

AfterRequestHook 会在完成`Client.Do(*http.Request)`后立即调用

func LogResponse added in v0.3.0

func LogResponse(logger *slog.Logger) AfterRequestHook

func StdLogResponse added in v0.3.0

func StdLogResponse(logger *log.Logger) AfterRequestHook

type Any added in v0.1.2

type Any map[string]any

Any 可用于query/headers/data/files传参

type BeforeRequestHook added in v0.3.0

type BeforeRequestHook func(*http.Request, []byte)

BeforeRequestHook 会在调用`Client.Do(*http.Request)`前调用,此时已经完成了parama的自动装填

func LogRequest added in v0.3.0

func LogRequest(logger *slog.Logger) BeforeRequestHook

func StdLogRequest added in v0.3.0

func StdLogRequest(logger *log.Logger) BeforeRequestHook

type Option

type Option func(*Session)

func WithAfterHooks added in v0.3.0

func WithAfterHooks(hooks ...AfterRequestHook) Option

func WithBeforeHooks added in v0.3.0

func WithBeforeHooks(hooks ...BeforeRequestHook) Option

func WithClient added in v0.2.0

func WithClient(client *http.Client) Option

func WithGlobalHeader added in v0.2.0

func WithGlobalHeader(header Any) Option

func WithGlobalTimeout added in v0.2.0

func WithGlobalTimeout(t time.Duration) Option

func WithTransport added in v0.2.2

func WithTransport(t http.RoundTripper) Option

func WithUserAgent added in v0.2.0

func WithUserAgent(name string) Option

type Params added in v0.1.2

type Params struct {
	Query   Any
	Data    Any
	Json    interface{}
	Files   Any
	Body    []byte
	Headers Any
}

type Session

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

func NewSession

func NewSession(opts ...Option) *Session

func (*Session) Apply added in v0.2.0

func (s *Session) Apply(opts ...Option)

func (*Session) Connect

func (s *Session) Connect(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) ConnectWithContext added in v0.1.5

func (s *Session) ConnectWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) Delete

func (s *Session) Delete(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) DeleteWithContext added in v0.1.5

func (s *Session) DeleteWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) Get

func (s *Session) Get(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) GetWithContext added in v0.1.5

func (s *Session) GetWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) Head

func (s *Session) Head(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) HeadWithContext added in v0.1.5

func (s *Session) HeadWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) OptionWithContext added in v0.1.5

func (s *Session) OptionWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) Options

func (s *Session) Options(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) Patch

func (s *Session) Patch(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) PatchWithContext added in v0.1.5

func (s *Session) PatchWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) Post

func (s *Session) Post(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) PostWithContext added in v0.1.5

func (s *Session) PostWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) Prepare added in v0.1.1

func (s *Session) Prepare(ctx context.Context, method, path string, params Params, buff *bytes.Buffer) (*http.Request, error)

func (*Session) Put

func (s *Session) Put(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) PutWithContext added in v0.1.5

func (s *Session) PutWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) Request

func (s *Session) Request(method, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) RequestWithContext added in v0.1.5

func (s *Session) RequestWithContext(ctx context.Context, method, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) Send added in v0.1.1

func (s *Session) Send(req *http.Request, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) Trace

func (s *Session) Trace(path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

func (*Session) TraceWithContext added in v0.1.5

func (s *Session) TraceWithContext(ctx context.Context, path string, params Params, unmarshaller Unmarshaller) (*http.Response, []byte, error)

type Unmarshaller added in v0.3.0

type Unmarshaller func([]byte) error

ResponseRender 用于对response的反序列化

func UnmarlXML added in v0.3.0

func UnmarlXML(v any) Unmarshaller

func UnmarshalJSON added in v0.3.0

func UnmarshalJSON(v any) Unmarshaller

Directories

Path Synopsis
zaplog module

Jump to

Keyboard shortcuts

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