Documentation ¶
Overview ¶
Package integrate contains integrate helper functions used by servers which protoc-gen-grpc-gateway generates.
Index ¶
- Constants
- func Compress(b *bytes.Buffer, s *bytes.Buffer) (int, error)
- func HttpMux(mux *runtime.ServeMux) http.Handler
- func IsKnownResource(s string) bool
- func NewGatewayHook(mux *runtime.ServeMux, host string) runtime.GatewayServiceHook
- func SetAllowCredentials(allow bool)
- func SetAllowHostsRegexp(hosts []string)
- type CorsMiddleware
- type GzipMiddleware
- type ResponseRecorder
Constants ¶
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 IsKnownResource ¶
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 ¶
http请求处理中间件
func (*CorsMiddleware) ServeHTTP ¶
func (m *CorsMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GzipMiddleware ¶
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) 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 .