rkmid

package
v2.2.22 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 8 Imported by: 134

Documentation

Index

Constants

View Source
const (
	HeaderAuthorization                   = "authorization"
	HeaderApiKey                          = "X-API-Key"
	HeaderRequestId                       = "X-Request-Id"
	HeaderTraceId                         = "X-Trace-Id"
	HeaderOrigin                          = "Origin"
	HeaderAccessControlAllowOrigin        = "Access-Control-Allow-Origin"
	HeaderAccessControlAllowCredentials   = "Access-Control-Allow-Credentials"
	HeaderAccessControlExposeHeaders      = "Access-Control-Expose-Headers"
	HeaderVary                            = "Vary"
	HeaderAccessControlRequestMethod      = "Access-Control-Request-Method"
	HeaderAccessControlRequestHeaders     = "Access-Control-Request-Headers"
	HeaderAccessControlAllowMethods       = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowHeaders       = "Access-Control-Allow-Headers"
	HeaderAccessControlMaxAge             = "Access-Control-Max-Age"
	HeaderContentEncoding                 = "Content-Encoding"
	HeaderContentLength                   = "Content-Length"
	HeaderContentType                     = "Content-Type"
	HeaderAcceptEncoding                  = "Accept-Encoding"
	HeaderXXSSProtection                  = "X-Xss-Protection"
	HeaderXContentTypeOptions             = "X-Content-Type-Options"
	HeaderXFrameOptions                   = "X-Frame-Options"
	HeaderXForwardedProto                 = "X-Forwarded-Proto"
	HeaderStrictTransportSecurity         = "Strict-Transport-Security"
	HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only"
	HeaderContentSecurityPolicy           = "Content-Security-Policy"
	HeaderReferrerPolicy                  = "Referrer-Policy"
	HeaderXCSRFToken                      = "X-CSRF-Token"
	HeaderCookie                          = "Cookie"
)

Variables

View Source
var (
	EntryNameKey      = &entryNameKey{}
	EntryTypeKey      = &entryTypeKey{}
	EventKey          = &eventKey{}
	LoggerKey         = &loggerKey{}
	TracerKey         = &tracerKey{}
	SpanKey           = &spanKey{}
	TracerProviderKey = &tracerProviderKey{}
	PropagatorKey     = &propagatorKey{}
	JwtTokenKey       = &jwtTokenKey{}
	CsrfTokenKey      = &csrfTokenKey{}

	// Domain environment variable
	Domain = zap.String("domain", getEnvValueOrDefault("DOMAIN", "*"))
	// LocalIp read local IP from localhost
	LocalIp = zap.String("localIp", getLocalIP())
	// LocalHostname read hostname from localhost
	LocalHostname = zap.String("localHostname", getLocalHostname())
)

Functions

func AddPathToIgnoreGlobal

func AddPathToIgnoreGlobal(prefix ...string)

func GenerateRequestId

func GenerateRequestId(req *http.Request) (requestId string)

GenerateRequestId generate request id based on google/uuid. UUIDs are based on RFC 4122 and DCE 1.1: Authentication and Security Services.

Fetch request id from request header if it exists, otherwise generate a new one. request id header is defined as constant HeaderRequestId.

Case 1: request id exists in request header

  • If request id exists, we will return it with nil error

Case 2: request id does not exist in request header, or header key exists but the value is empty

  • If request id does not exist, we will generate a new one and return it with nil error

Case 3: error occurs when generating a new request id

  • If error occurs, we will return empty string with error
  • Error handling is not required since we will return empty string if error occurs

A UUID is a 16 byte (128 bit) array. UUIDs may be used as keys to maps or compared directly.

func GenerateRequestIdWithPrefix

func GenerateRequestIdWithPrefix(prefix string) string

GenerateRequestIdWithPrefix generate request id based on google/uuid. UUIDs are based on RFC 4122 and DCE 1.1: Authentication and Security Services.

A UUID is a 16 byte (128 bit) array. UUIDs may be used as keys to maps or compared directly.

func GetErrorBuilder added in v2.2.0

func GetErrorBuilder() rkerror.ErrorBuilder

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 SetErrorBuilder added in v2.2.0

func SetErrorBuilder(builder rkerror.ErrorBuilder)

func ShouldIgnoreGlobal

func ShouldIgnoreGlobal(urlPath string) bool

Types

This section is empty.

Directories

Path Synopsis
Package rkmidauth provide auth related options
Package rkmidauth provide auth related options
Package rkmidcors provide cors related options
Package rkmidcors provide cors related options
Package rkmidcsrf provide auth related options
Package rkmidcsrf provide auth related options
Package rkmidjwt is a middleware for JWT
Package rkmidjwt is a middleware for JWT
Package rkmidlog provide options
Package rkmidlog provide options
Package rkmidmeta is a middleware for metadata
Package rkmidmeta is a middleware for metadata
Package rkmidpanic provide options
Package rkmidpanic provide options
Package rkmidprom has a couple of utility functions to start prometheus and pushgateway client locally.
Package rkmidprom has a couple of utility functions to start prometheus and pushgateway client locally.
Package rkmidlimit provide options
Package rkmidlimit provide options
Package rkmidsec provide auth related options
Package rkmidsec provide auth related options
Package rkmidtimeout provide options
Package rkmidtimeout provide options
Package rkmidtrace is a middleware for recording tracing
Package rkmidtrace is a middleware for recording tracing

Jump to

Keyboard shortcuts

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