Help us shape the future of Go! Take the 2026 Go Developer Survey

http

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// HandlerReturnOk handler return ok
	HandlerReturnOk = 1

	// HandlerReturnBreak handler return break
	HandlerReturnBreak = 0

	// HandlerReturnError handler return error
	HandlerReturnError = -1
)

Variables

View Source
var HTTPHandlers = map[string]process.Handler{
	"get":    processHTTPGet,
	"post":   processHTTPPost,
	"put":    processHTTPPut,
	"patch":  processHTTPPatch,
	"delete": processHTTPDelete,
	"head":   processHTTPHead,
	"send":   processHTTPSend,
	"stream": processHTTPStream,
}

HTTPHandlers the http handlers

Functions

func CloseAllTransports added in v1.0.0

func CloseAllTransports()

CloseAllTransports closes all idle connections in the transport pool This is useful for testing and cleanup

func GetProxy added in v1.0.0

func GetProxy(https bool) string

GetProxy get the proxy

func GetTransport added in v1.0.0

func GetTransport(isHTTPS bool, proxy string) *http.Transport

GetTransport returns a reusable HTTP transport for the given configuration

func SetFileRoot added in v0.10.3

func SetFileRoot(root string) error

SetFileRoot SetFileRoot

Types

type File added in v1.0.0

type File struct {
	Name string `json:"name"`
	Path string `json:"path,omitempty"`
	Data string `json:"data,omitempty"`
	// contains filtered or unexported fields
}

File file

type Request

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

Request HTTP Request

func New

func New(url string) *Request

New make a new http Request

func (*Request) AddFile

func (r *Request) AddFile(name, file string) *Request

AddFile set the file

func (*Request) AddFileBytes added in v1.0.0

func (r *Request) AddFileBytes(name, pathname string, data []byte) *Request

AddFileBytes set the file

func (*Request) AddHeader

func (r *Request) AddHeader(name, value string) *Request

AddHeader set the request header

func (*Request) DelHeader

func (r *Request) DelHeader(name string) *Request

DelHeader unset the request header

func (*Request) Delete

func (r *Request) Delete(data interface{}) *Response

Delete send the DELETE request

func (*Request) Get

func (r *Request) Get() *Response

Get send the GET request

func (*Request) GetHeader

func (r *Request) GetHeader(name string) string

GetHeader get the request header

func (*Request) HasHeader

func (r *Request) HasHeader(name string) bool

HasHeader check if the header name is exists

func (*Request) Head

func (r *Request) Head(data interface{}) *Response

Head send the Head request

func (*Request) Patch

func (r *Request) Patch(data interface{}) *Response

Patch send the PATCH request

func (*Request) Post

func (r *Request) Post(data interface{}) *Response

Post send the POST request

func (*Request) Put

func (r *Request) Put(data interface{}) *Response

Put send the PUT request

func (*Request) Send

func (r *Request) Send(method string, data interface{}) *Response

Send send the request

func (*Request) SetHeader

func (r *Request) SetHeader(name string, value string) *Request

SetHeader set the request header

func (*Request) Stream added in v1.0.0

func (r *Request) Stream(ctx context.Context, method string, data interface{}, handler func(data []byte) int) error

Stream stream the request

func (*Request) Upload

func (r *Request) Upload(file string, chunksize int) *Response

Upload upload a big file

func (*Request) WithContext added in v1.0.0

func (r *Request) WithContext(ctx context.Context) *Request

WithContext set the request context

func (*Request) WithHeader

func (r *Request) WithHeader(headers http.Header) *Request

WithHeader set the request headers

func (*Request) WithQuery

func (r *Request) WithQuery(values neturl.Values) *Request

WithQuery set the request query params

type Response

type Response struct {
	Status  int         `json:"status"`
	Data    interface{} `json:"data"`
	Headers http.Header `json:"headers"`
	Code    int         `json:"code"`
	Message string      `json:"message"`
}

Response HTTP Response

func ResponseError

func ResponseError(code int, message string) *Response

ResponseError return new error response

Jump to

Keyboard shortcuts

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