package module
v0.0.0-...-327943f Latest Latest

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

Go to latest
Published: Jul 31, 2021 License: MIT Imports: 13 Imported by: 0



A http library based on golang




This section is empty.


View Source
var ErrorOfEmptyClient = errors.New("client is nil")


func AddParameterToURL

func AddParameterToURL(URL string, parameter map[string]string) (string, error)

AddParameterToURL 向URL中添加参数

func Client

func Client(tr *http.Transport, timeout time.Duration) *http.Client

Client 创建http client.

func ClientSetCookie

func ClientSetCookie(request *http.Request, data map[string]string)

ClientSetCookie 设置cookie.

func CloseRsp

func CloseRsp(response *http.Response)

CloseRsp 关闭http client的回应.

func CreateToken

func CreateToken(payload map[string]interface{}, key string) (string, error)

CreateToken 创建token

iss: 签发者
sub: 面向的用户
aud: 接收方
exp: 过期时间
nbf: 生效时间
iat: 签发时间
jti: 唯一身份标识

func GetParameterFromURL

func GetParameterFromURL(URL *url.URL) (url.Values, error)

GetParameterFromURL 获取URL中的参数

func NewListener

func NewListener(addr string, readTimeout, writeTimeout time.Duration) (net.Listener, error)

func NewRequest

func NewRequest(method string, url string, body []byte) (*http.Request, error)

NewRequest 生成新的请求

func NewUnixListener

func NewUnixListener(path string, readTimeout, writeTimeout time.Duration) (net.Listener, error)

Binds to a UNIX socket. If the file already exists, try to remove it before binding again. This logic is borrowed from Gunicorn (see https://github.com/benoitc/gunicorn/blob/a8963ef1a5a76f3df75ce477b55fe0297e3b617d/gunicorn/sock.py#L106)

func ParseToken

func ParseToken(tokenStr string, key string) (jwt.MapClaims, error)

ParseToken 解析token

func ServerDelCookie

func ServerDelCookie(rw http.ResponseWriter, name string)

ServerDelCookie 删除cookie.

func ServerGetCookie

func ServerGetCookie(request *http.Request, key string) (string, error)

ServerGetCookie 获取cookie值

func ServerSetCookie

func ServerSetCookie(rw http.ResponseWriter, data map[string]string)

ServerSetCookie 设置cookie.

func SetHeader

func SetHeader(req *http.Request, data map[string]string)

SetHeader 设置请求头, like contentType = "application/json;charset=utf-8" and so on.

func StartServer

func StartServer(addr string, handler http.Handler, timeout time.Duration) error

func TLSClient

func TLSClient(timeout time.Duration, tr *http.Transport) (*http.Client, error)

TLSClient 创建https http client.

func TLSTransport

func TLSTransport(tls *tls.Config) *http.Transport

func Transport

func Transport() *http.Transport

Transport 传输策略


type Conn

type Conn struct {
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	// contains filtered or unexported fields

Conn wraps a net.Conn, and sets a deadline for every read and write operation.

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

type Listener

type Listener struct {
	ReadTimeout  time.Duration
	WriteTimeout time.Duration

Listener wraps a net.Listener, and gives a place to store the timeout parameters. On Accept, it will wrap the net.Conn with our own Conn for us. Original implementation taken from https://gist.github.com/jbardin/9663312 Thanks! <3

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)


Path Synopsis

Jump to

Keyboard shortcuts

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