rkmuxinter

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package rkmuxinter provides common utility functions for middleware of mux framework

Index

Constants

View Source
const (
	// RpcEntryNameKey entry name key
	RpcEntryNameKey = "muxEntryName"
	// RpcEntryNameValue entry name
	RpcEntryNameValue = "mux"
	// RpcEntryTypeValue entry type
	RpcEntryTypeValue = "mux"
	// RpcEventKey event key
	RpcEventKey = "muxEvent"
	// RpcLoggerKey logger key
	RpcLoggerKey = "muxLogger"
	// RpcTracerKey tracer key
	RpcTracerKey = "muxTracer"
	// RpcSpanKey span key
	RpcSpanKey = "muxSpan"
	// RpcTracerProviderKey trace provider key
	RpcTracerProviderKey = "muxTracerProvider"
	// RpcPropagatorKey propagator key
	RpcPropagatorKey = "muxPropagator"
	// RpcAuthorizationHeaderKey auth key
	RpcAuthorizationHeaderKey = "authorization"
	// RpcApiKeyHeaderKey api auth key
	RpcApiKeyHeaderKey = "X-API-Key"
	// RpcJwtTokenKey key of jwt token in context
	RpcJwtTokenKey = "muxJwt"
	// RpcCsrfTokenKey key of csrf token injected by csrf middleware
	RpcCsrfTokenKey = "muxCsrfToken"
)

Variables

View Source
var (
	// Realm environment variable
	Realm = zap.String("realm", rkcommon.GetEnvValueOrDefault("REALM", "*"))
	// Region environment variable
	Region = zap.String("region", rkcommon.GetEnvValueOrDefault("REGION", "*"))
	// AZ environment variable
	AZ = zap.String("az", rkcommon.GetEnvValueOrDefault("AZ", "*"))
	// Domain environment variable
	Domain = zap.String("domain", rkcommon.GetEnvValueOrDefault("DOMAIN", "*"))
	// LocalIp read local IP from localhost
	LocalIp = zap.String("localIp", rkcommon.GetLocalIP())
	// LocalHostname read hostname from localhost
	LocalHostname = zap.String("localHostname", rkcommon.GetLocalHostname())
)

Functions

func GetRemoteAddressSet

func GetRemoteAddressSet(req *http.Request) (remoteIp, remotePort string)

GetRemoteAddressSet returns remote endpoint information set including IP, Port. We will do as best as we can to determine it. If fails, then just return default ones.

func ShouldLog

func ShouldLog(req *http.Request) bool

ShouldLog determines whether should log the RPC

func WriteJson

func WriteJson(w http.ResponseWriter, code int, content interface{})

WriteJson with code and content. Internal error will be written if error occur.

Types

type RkResponseWriter

type RkResponseWriter struct {
	Writer http.ResponseWriter
	Code   int
	Size   atomic.Int
}

A RkResponseWriter is a helper to delay sealing a http.ResponseWriter on writing code.

func WrapResponseWriter

func WrapResponseWriter(w http.ResponseWriter) *RkResponseWriter

WrapResponseWriter if current writer is not RkResponseWriter

func (*RkResponseWriter) Flush

func (w *RkResponseWriter) Flush()

Flush flushes the response writer.

func (*RkResponseWriter) Header

func (w *RkResponseWriter) Header() http.Header

Header returns the http header.

func (*RkResponseWriter) Hijack

func (w *RkResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack implements the http.Hijacker interface. This expands the Response to fulfill http.Hijacker if the underlying http.ResponseWriter supports it.

func (*RkResponseWriter) Write

func (w *RkResponseWriter) Write(bytes []byte) (int, error)

Write writes bytes into w.

func (*RkResponseWriter) WriteHeader

func (w *RkResponseWriter) WriteHeader(code int)

WriteHeader writes code into w, and not sealing the writer.

Directories

Path Synopsis
Package rkmuxauth is auth middleware for mux framework
Package rkmuxauth is auth middleware for mux framework
Package rkmuxctx defines utility functions and variables used by gorilla/mux middleware
Package rkmuxctx defines utility functions and variables used by gorilla/mux middleware
Package rkmuxcors is a CORS middleware for mux framework
Package rkmuxcors is a CORS middleware for mux framework
Package rkmuxcsrf is a middleware for mux framework which validating csrf token for RPC
Package rkmuxcsrf is a middleware for mux framework which validating csrf token for RPC
Package rkmuxjwt is a middleware for mux framework which validating jwt token for RPC
Package rkmuxjwt is a middleware for mux framework which validating jwt token for RPC
log
zap
Package rkmuxlog is a middleware for mux framework for logging RPC.
Package rkmuxlog is a middleware for mux framework for logging RPC.
Package rkmuxmeta is a middleware of mux framework for adding metadata in RPC response
Package rkmuxmeta is a middleware of mux framework for adding metadata in RPC response
metrics
prom
Package rkmuxmetrics is a middleware for mux framework which record prometheus metrics for RPC
Package rkmuxmetrics is a middleware for mux framework which record prometheus metrics for RPC
Package rkmuxpanic is a middleware of mux framework for recovering from panic
Package rkmuxpanic is a middleware of mux framework for recovering from panic
Package rkmuxlimit is a middleware of mux framework for adding rate limit in RPC response
Package rkmuxlimit is a middleware of mux framework for adding rate limit in RPC response
Package rkmuxsec is a middleware of mux framework for adding secure headers in RPC response
Package rkmuxsec is a middleware of mux framework for adding secure headers in RPC response
Package rkmuxtimeout is a middleware of mux framework for timing out request in RPC response
Package rkmuxtimeout is a middleware of mux framework for timing out request in RPC response
tracing
telemetry
Package rkmuxtrace is aa middleware of mux framework for recording trace info of RPC
Package rkmuxtrace is aa middleware of mux framework for recording trace info of RPC

Jump to

Keyboard shortcuts

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