util

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeText = "text/plain; charset=utf-8"
	ContentTypeJSON = "application/json; charset=utf-8"
)

Variables

View Source
var Transport = &http.Transport{DialContext: TimeoutDialer(30*time.Second, 30*time.Second)}

Functions

func AnyOf

func AnyOf(s string, p ...string) bool

AnyOf tells s equals any element of p...

func CORSMiddleware

func CORSMiddleware(c *gin.Context)

CORSMiddleware ...

func CompactJSON

func CompactJSON(b []byte) []byte

CompactJSON compact a json byte slice or wrap it to raw value.

func ConvertHeader

func ConvertHeader(query map[string][]string) map[string]string

ConvertHeader convert s head map[string][]string to map[string]string.

func DetectContentType

func DetectContentType(b []byte) string

DetectContentType detects the contentType of b.

func GetFormBody

func GetFormBody(c *gin.Context) map[string]string

GetFormBody ...

func GetHeaders

func GetHeaders(c *gin.Context) map[string]string

GetHeaders ...

func GetMultiPartFormValue

func GetMultiPartFormValue(c *gin.Context) interface{}

GetMultiPartFormValue ...

func GetRequestBody

func GetRequestBody(c *gin.Context) interface{}

GetRequestBody ...

func GinData

func GinData(c *gin.Context, b []byte)

GinData writes some data into the body stream and updates the HTTP code.

func HasContentType

func HasContentType(r *http.Request, mimetype string) bool

HasContentType determine whether the request `content-type` includes a server-acceptable mime-type Failure should yield an HTTP 415 (`http.StatusUnsupportedMediaType`)

func HasPrefix

func HasPrefix(s string, p ...string) bool

HasPrefix tells s has any prefix of p...

func IsJSONBytes

func IsJSONBytes(b []byte) bool

IsJSONBytes tests bytes b is in JSON format.

func IsRelativeForward

func IsRelativeForward(statusCode int, locationHeader string) bool

IsRelativeForward tells the statusCode is 301/302 and locationHeader is relative

func JSON

func JSON(v interface{}) []byte

JSON jsonifies the value.

func JoinLowerKeys

func JoinLowerKeys(s ...string) string

JoinLowerKeys ...

func OpenExplorerWithContext

func OpenExplorerWithContext(contextPath, port string)

OpenExplorerWithContext ...

func Or

func Or(s, or string) string

Or returns or if s is empty.

func ReverseProxy

func ReverseProxy(originalPath, targetHost, targetPath string) *httputil.ReverseProxy

ReverseProxy reverse proxy originalPath to targetHost with targetPath. And the relative forwarding is rewritten.

func TimeFmt

func TimeFmt(t time.Time) string

TimeFmt format time.

func TryBind

func TryBind(c *gin.Context) interface{}

TryBind ...

func UnquoteCover

func UnquoteCover(s, start, end string) string

UnquoteCover unquotes string from s.

Types

type Dialer

type Dialer func(ctx context.Context, net, addr string) (c net.Conn, err error)

Dialer defines dialer function alias

func TimeoutDialer

func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) Dialer

TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field. https://gist.github.com/c4milo/275abc6eccbfd88ad56ca7c77947883a HTTP client with support for read and write timeouts which are missing in Go's standard library.

type GinCopyWriter

type GinCopyWriter struct {
	gin.ResponseWriter
	Buf bytes.Buffer
}

func NewGinCopyWriter

func NewGinCopyWriter(w gin.ResponseWriter) *GinCopyWriter

NewGinCopyWriter creates a new GinCopyWriter.

func (*GinCopyWriter) Body

func (w *GinCopyWriter) Body(maxSize int) string

func (*GinCopyWriter) Bytes

func (w *GinCopyWriter) Bytes() []byte

func (*GinCopyWriter) Write

func (w *GinCopyWriter) Write(data []byte) (n int, err error)

func (*GinCopyWriter) WriteString

func (w *GinCopyWriter) WriteString(s string) (n int, err error)

type ReplaceItem

type ReplaceItem struct {
	Reg *regexp.Regexp
	Val string
}

type Replacer

type Replacer struct {
	Items []ReplaceItem
}

func ParseReplacer

func ParseReplacer(expr string) (*Replacer, error)

func (*Replacer) Replace

func (r *Replacer) Replace(str string) string

type Throttle

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

Throttle ...

func MakeThrottle

func MakeThrottle(tokensNum int, duration time.Duration) *Throttle

MakeThrottle ...

func (*Throttle) Allow

func (t *Throttle) Allow() bool

Allow ...

func (*Throttle) Stop

func (t *Throttle) Stop()

Stop ...

Jump to

Keyboard shortcuts

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