Documentation
¶
Overview ¶
Package clients The code of this file is copied from github.com/gin-gonic/gin
Index ¶
- Constants
- Variables
- func ClientIP(request *http.Request) string
- func Middleware() func(http.Handler) http.Handler
- func MiddlewareFunc() func(http.HandlerFunc) http.HandlerFunc
- func RemoteIP(r *http.Request) string
- func SetForwardedByClientIP(forwardedByClientIP bool)
- func SetRemoteIPHeaders(remoteIPHeaders []string)
- func SetTrustedPlatform(trustedPlatform string)
- func SetTrustedProxies(trustedProxies []string) error
- func StreamClientInterceptor() grpc.StreamClientInterceptor
- func StreamServerInterceptor() grpc.StreamServerInterceptor
- func UnaryClientInterceptor() grpc.UnaryClientInterceptor
- func UnaryServerInterceptor() grpc.UnaryServerInterceptor
- func WithContext(ctx context.Context, info *ClientInfo) context.Context
- type ClientInfo
- type IPResolver
- type ServerStream
Constants ¶
const ( HeaderClientID = "x-client-id" HeaderVersion = "x-client-version" HeaderClientIP = "x-client-ip" HeaderUA = "x-client-ua" HeaderRequestID = "x-request-id" )
Variables ¶
var DefaultIPResolver = &IPResolver{}
Functions ¶
func MiddlewareFunc ¶
func MiddlewareFunc() func(http.HandlerFunc) http.HandlerFunc
func RemoteIP ¶
RemoteIP parses the IP from Request.RemoteAddr, normalizes and returns the IP (without the port).
func SetForwardedByClientIP ¶
func SetForwardedByClientIP(forwardedByClientIP bool)
func SetRemoteIPHeaders ¶
func SetRemoteIPHeaders(remoteIPHeaders []string)
func SetTrustedPlatform ¶
func SetTrustedPlatform(trustedPlatform string)
func SetTrustedProxies ¶
func StreamClientInterceptor ¶
func StreamClientInterceptor() grpc.StreamClientInterceptor
func StreamServerInterceptor ¶
func StreamServerInterceptor() grpc.StreamServerInterceptor
func UnaryClientInterceptor ¶
func UnaryClientInterceptor() grpc.UnaryClientInterceptor
func UnaryServerInterceptor ¶
func UnaryServerInterceptor() grpc.UnaryServerInterceptor
func WithContext ¶
func WithContext(ctx context.Context, info *ClientInfo) context.Context
Types ¶
type ClientInfo ¶
type ClientInfo struct { ID string `json:"id"` IP string `json:"ip"` UA string `json:"ua"` Version string `json:"v"` RequestID string `json:"rid"` }
func FromContext ¶
func FromContext(ctx context.Context) *ClientInfo
func (*ClientInfo) MD ¶
func (c *ClientInfo) MD() metadata.MD
type IPResolver ¶
type IPResolver struct { // TrustedPlatform if set to a constant of value gin.Platform*, trusts the headers set by // that platform, for example to determine the client IP TrustedPlatform string // ForwardedByClientIP if enabled, client IP will be parsed from the request's headers that // match those stored at `(*gin.Engine).RemoteIPHeaders`. If no IP was // fetched, it falls back to the IP obtained from // `(*gin.Context).Request.RemoteAddr`. ForwardedByClientIP bool // RemoteIPHeaders list of headers used to obtain the client IP when // `(*gin.Engine).ForwardedByClientIP` is `true` and // `(*gin.Context).Request.RemoteAddr` is matched by at least one of the // network origins of list defined by `(*gin.Engine).SetTrustedProxies()`. RemoteIPHeaders []string // contains filtered or unexported fields }
func (*IPResolver) ClientIP ¶
func (c *IPResolver) ClientIP(request *http.Request) string
ClientIP implements one best effort algorithm to return the real client IP. It calls c.RemoteIP() under the hood, to check if the remote IP is a trusted proxy or not. If it is it will then try to parse the headers defined in Engine.RemoteIPHeaders (defaulting to [X-Forwarded-For, X-Real-Ip]). If the headers are not syntactically valid OR the remote IP does not correspond to a trusted proxy, the remote IP (coming from Request.RemoteAddr) is returned.
func (*IPResolver) SetTrustedProxies ¶
func (c *IPResolver) SetTrustedProxies(trustedProxies []string) error
SetTrustedProxies set a list of network origins (IPv4 addresses, IPv4 CIDRs, IPv6 addresses or IPv6 CIDRs) from which to trust request's headers that contain alternative client IP when `(*gin.Engine).ForwardedByClientIP` is `true`. `TrustedProxies` feature is enabled by default, and it also trusts all proxies by default. If you want to disable this feature, use Engine.SetTrustedProxies(nil), then Context.ClientIP() will return the remote address directly.
type ServerStream ¶
type ServerStream struct {
grpc.ServerStream
}
func (*ServerStream) Context ¶
func (s *ServerStream) Context() context.Context