integrate

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package integrate contains integrate helper functions used by servers which protoc-gen-grpc-gateway generates.

Index

Constants

View Source
const (
	// 公共头信息
	XSource     = "x-source"      // 请求来源。web,client(包括4个客户端)
	XClient     = "x-client"      // 客户端资源号。如:mga、mip
	XUid        = "x-uid"         // 用户id
	XCid        = "x-cid"         // 企业id
	XAid        = "x-aid"         // 个人账户id
	XSid        = "x-sid"         // 登录sessionId(client端使用),web端使用cookie
	XDid        = "x-did"         // 设备唯一id(客户端使用)
	XAppVersion = "x-app-version" // 客户端版本号, 如:3.4.0(客户端使用)
	XTs         = "x-ts"          // 请求时间戳,单位(毫秒)
	XSign       = "x-sign"        // 签名串。需要加签验证的接口必填
	XRequestId  = "x-request-id"  // 唯一请求id,跟踪日志使用
	XLocale     = "x-locale"      // 语言 简体中文:zh_CN; 繁体中文:zh_TW;英文:en_US
	XClientId   = "x-client-id"   // 开放平台请求所需的client id
	XCorpCode   = "x-corp-code"   // 开放平台请求所需的corp code

	Authorization = "Authorization" // Token authorization header.

	// 请求来源
	// Need to update IsKnownSource when adding a new resource
	ResourceWeb    = "web"    // web端请求
	ResourceClient = "client" // client端请求,包含windowns、mac、Android、ios4个客户端
	ResourceThird  = "third"  // Request from third party

	// 接到请求的时间
	RequestReceivedTime = "request-received-time"
	// http header:x-forwarded-for
	XForwardedFor = "x-forwarded-for"
)

Variables

This section is empty.

Functions

func Compress

func Compress(b *bytes.Buffer, s *bytes.Buffer) (int, error)

compress returns bytes len that param s after the compression.

func HttpMux

func HttpMux(mux *runtime.ServeMux) http.Handler

HttpMux 返回所需的封装Handler.

func IsKnownResource

func IsKnownResource(s string) bool

IsKnownResource returns if the given resource is known or not.

func NewGatewayHook

func NewGatewayHook(mux *runtime.ServeMux, host string) runtime.GatewayServiceHook

NewGatewayHook returns a new gatewayHook.

func SetAllowCredentials

func SetAllowCredentials(allow bool)

SetAllowCredentials sets to allow CORS credentials.

func SetAllowHostsRegexp

func SetAllowHostsRegexp(hosts []string)

SetAllowHostsRegexp sets the allowed hosts for CORS. Note: this should only be used by custom gateway and ldap gateway.

Types

type CorsMiddleware

type CorsMiddleware struct {
	Handler http.Handler
}

http请求处理中间件

func (*CorsMiddleware) ServeHTTP

func (m *CorsMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

type GzipMiddleware

type GzipMiddleware struct {
	Handler http.Handler
}

gzip 处理中间件

func (*GzipMiddleware) ServeHTTP

func (m *GzipMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ResponseRecorder

type ResponseRecorder struct {
	Code      int           // the HTTP response code from WriteHeader
	HeaderMap http.Header   // the HTTP response headers
	Body      *bytes.Buffer // if non-nil, the bytes.Buffer to append written data to
	Flushed   bool
	// contains filtered or unexported fields
}

ResponseRecorder is an implementation of http.ResponseWriter.

func NewRecorder

func NewRecorder() *ResponseRecorder

NewRecorder returns an initialized ResponseRecorder.

func (*ResponseRecorder) Flush

func (rw *ResponseRecorder) Flush()

Flush sets rw.Flushed to true.

func (*ResponseRecorder) Header

func (rw *ResponseRecorder) Header() http.Header

Header returns the response headers.

func (*ResponseRecorder) Write

func (rw *ResponseRecorder) Write(buf []byte) (int, error)

Write always succeeds and writes to rw.Body, because of bytes.Buffer.Write's error is always nil .

func (*ResponseRecorder) WriteHeader

func (rw *ResponseRecorder) WriteHeader(code int)

WriteHeader sets rw.Code.

func (*ResponseRecorder) WriteString

func (rw *ResponseRecorder) WriteString(str string) (int, error)

WriteString always succeeds and writes to rw.Body, because of bytes.Buffer.WriteString's error is always nil .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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