zhttp

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func AddParameterToURL

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

AddParameterToURL add parameter to URL

func Client

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

func ClientSetCookie

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

ClientSetCookie client set cookie.

func CloseRsp

func CloseRsp(response *http.Response)

func CreateToken

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

CreateToken create token

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

func GetParameterFromURL

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

GetParameterFromURL get parameter from URL

func GetRequest2

func GetRequest2(method string, url string, body io.Reader) (*http.Request, error)

func GetSkipTlsConfig

func GetSkipTlsConfig() *tls.Config

func GetTlsConfig

func GetTlsConfig(caFilePath string) (*tls.Config, error)

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 create a request

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 analyse token

func ServerDelCookie

func ServerDelCookie(rw http.ResponseWriter, name string)

ServerDelCookie server revoke cookie.

func ServerGetCookie

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

ServerGetCookie server get cookie value from request by key

func ServerSetCookie

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

ServerSetCookie server set cookie.

func SetHeader

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

SetHeader set request header, like contentType = "application/json;charset=utf-8" and so on.

func StartServer

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

func TLSTransport

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

func Transport

func Transport() *http.Transport

Types

type Conn

type Conn struct {
	net.Conn
	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 {
	net.Listener
	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)

Jump to

Keyboard shortcuts

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