xgin

package
v0.0.0-...-80fcaa9 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//User-Agent
	USER_AGENT string = "xpkg/v2"
)

Variables

View Source
var DefaultTransport = &http.Transport{
	DialContext: (&net.Dialer{
		Timeout:   1 * time.Second,
		KeepAlive: 30 * time.Second,

		DualStack: true,
	}).DialContext,
	MaxIdleConns:          100,
	IdleConnTimeout:       90 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
	TLSHandshakeTimeout:   3 * time.Second,
}

DefaultTransport http keepalive 30s var tp http.RoundTripper

View Source
var ProxyTransport = &http.Transport{
	Proxy: http.ProxyFromEnvironment,
	DialContext: (&net.Dialer{
		Timeout:   30 * time.Second,
		KeepAlive: -1,
		DualStack: true,
	}).DialContext,
	ForceAttemptHTTP2:     true,
	DisableKeepAlives:     true,
	MaxIdleConns:          1,
	IdleConnTimeout:       90 * time.Second,
	TLSHandshakeTimeout:   10 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
}
var DefaultTransport = &http.Transport{
	Proxy: http.ProxyFromEnvironment,
	DialContext: (&net.Dialer{
		Timeout:   30 * time.Second,
		KeepAlive: 30 * time.Second,
		DualStack: true,
	}).DialContext,
	ForceAttemptHTTP2:     true,
	MaxIdleConns:          100,
	IdleConnTimeout:       90 * time.Second,
	TLSHandshakeTimeout:   10 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
}
View Source
var (
	SingleHostReverseProxy = map[string]*httputil.ReverseProxy{}
)

Functions

func AuthHandler

func AuthHandler(handler xoidc.OidcAuthFuncHandler) gin.HandlerFunc

func BaseHandler

func BaseHandler(handler ...HandlerFunc) gin.HandlerFunc

func Bind

func Bind(c *gin.Context, out interface{}) error

func BindJSON

func BindJSON(c *gin.Context, out interface{}) error

func CopyBody

func CopyBody(c *gin.Context) (io.ReadCloser, error)

func DoHandler

func DoHandler(handler ...HandlerFunc) gin.HandlerFunc

DoHandler 返回JSON数据

func EncodeHTTPHeader

func EncodeHTTPHeader(data map[string][]string) string

func GetALLParams

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

GetALLParams 获取所有请求参数

func GetPar

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

func GetQueryPar

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

GetQueryPar 获取所有请求参数

func GinContext

func GinContext(c *gin.Context) context.Context

GinContext get context

func GinInterceptorOpenTracing

func GinInterceptorOpenTracing(tr opentracing.Tracer) gin.HandlerFunc

func GinLog

func GinLog(c *gin.Context) *logrus.Entry

func NewSingleHostReverseProxy

func NewSingleHostReverseProxy(data *url.URL) *httputil.ReverseProxy

func PostFormPar

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

func PostFormPar(c *gin.Context) map[string]string { 获取所有请求参数

func ProxyURL

func ProxyURL(c *gin.Context, targeturl string, fn FilterHandler) bool

func ProxyURLV2

func ProxyURLV2(c *gin.Context, targeturl string, fn FilterHandler) (string, bool)

func ReadBody

func ReadBody(c *gin.Context) []byte

func ReadBodyv2

func ReadBodyv2(rc io.ReadCloser) (io.ReadCloser, string, error)

func RealIP

func RealIP(ctx *gin.Context) string

RealIP X-Real-Ip

func RunEngine

func RunEngine(sv ServerInfo, fn GinHandler) error

func RunRouter

func RunRouter(engine *gin.Engine, sv ServerInfo) (err error)

func ShiftRequest

func ShiftRequest(c *gin.Context, api string, sec int, retry int, header xtools.ES) (result string, err error)

func ShiftSvcPath

func ShiftSvcPath(c *gin.Context, svc string) (string, error)

func TraceID

func TraceID(c *gin.Context) string

Types

type ContentType

type ContentType string
const (
	APPLICATION_JSON ContentType = "application/json"
	//text/html;text/plain; charset=utf-8
	TEXT_HTML  ContentType = "text/html"
	TEXT_PLAIN ContentType = "text/plain; charset=utf-8"
	//application/javascript
	APPLICATION_JAVASCRIPT ContentType = "application/javascript"
	//application/xml
	APPLICATION_XML ContentType = "application/xml"
	//application/x-www-form-urlencoded
	APPLICATION_URLENCODED ContentType = "application/x-www-form-urlencoded"
)

type FilterHandler

type FilterHandler func(ctx context.Context, opt FilterOption) bool

type FilterOption

type FilterOption struct {
	Path  string            `json:"path"`
	Query map[string]string `json:"query"`
	Body  []byte            `json:"body"`
}

func (*FilterOption) GetBodyJSON

func (c *FilterOption) GetBodyJSON(out interface{}) error

func (*FilterOption) GetVal

func (c *FilterOption) GetVal(key string) (string, bool)

type GinHandler

type GinHandler func(xg *gin.Engine)

type HandlerFunc

type HandlerFunc func(c *gin.Context) (ret IRet)

type IRet

type IRet interface {
	GetCode() codes.Code
	GetRet() (string, ContentType)
	SetTrace(trace string) IRet
}

func Error

func Error(c *gin.Context, err error) IRet

func NewRet

func NewRet(err error, data interface{}) IRet

func Succ

func Succ(c *gin.Context, data interface{}) IRet

func Trace

func Trace(c *gin.Context, ret IRet) IRet

type Ret

type Ret struct {
	Ret   codes.Code  `json:"ret"`
	Msg   string      `json:"msg,omitempty"`
	Data  interface{} `json:"data,omitempty"`
	Trace string      `json:"trace,omitempty"`
}

func (*Ret) GetCode

func (c *Ret) GetCode() codes.Code

func (*Ret) GetRet

func (c *Ret) GetRet() (string, ContentType)

func (*Ret) SetTrace

func (c *Ret) SetTrace(str string) IRet

type RetString

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

func NewRetString

func NewRetString(data string) *RetString

func NewRetStringv2

func NewRetStringv2(data string, ct ContentType) *RetString

func (*RetString) GetCode

func (c *RetString) GetCode() codes.Code

func (*RetString) GetRet

func (c *RetString) GetRet() (string, ContentType)

func (*RetString) SetTrace

func (c *RetString) SetTrace(str string) IRet

type ServerInfo

type ServerInfo struct {
	ServerdAddr          string `yaml:"ServerdAddr"`
	ServerTimeout        int    `yaml:"ServerTimeout"`
	KeepaliveIdleTimeout int    `yaml:"KeepaliveIdleTimeout"`
}

Jump to

Keyboard shortcuts

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