common

package
v0.0.0-...-67af0ea Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IsAutoForwardedFlag    = "IsAutoForward"          // IsAutoForwardedFlag marks whether the current request is auto forwarded
	FollowerAgentOfForward = "FollowerAgentOfForward" // FollowerAgentOfForward is where the request is auto forwarded from
)
View Source
const (
	OcsAgentResponseKey = "ocsAgentResponse"
	TraceIdKey          = "traceId"
)
View Source
const (
	ACCEPT_LANGUAGE = constant.ACCEPT_LANGUAGE
)

Variables

View Source
var OCS_CUSTOMIZE_HEADER = []string{
	ACCEPT_LANGUAGE,
}

OCS_CUSTOMIZE_HEADER is the customize header that will be delivered when forward request.

Functions

func AutoForwardToMaintainerWrapper

func AutoForwardToMaintainerWrapper(f func(*gin.Context)) func(*gin.Context)

func BodyDecrypt

func BodyDecrypt(skipRoutes ...string) func(*gin.Context)

func ForwardRequest

func ForwardRequest(c *gin.Context, agentInfo meta.AgentInfoInterface, param interface{})

ForwardRequest is used by handler to forward the request to other agent.

func HeaderDecrypt

func HeaderDecrypt(skipRoutes ...string) func(*gin.Context)

func IsApiRoute

func IsApiRoute(c *gin.Context) bool

func IsLocalRoute

func IsLocalRoute(c *gin.Context) bool

func NewContextWithTraceId

func NewContextWithTraceId(c *gin.Context) context.Context

NewContextWithTraceId extracts the traceId value from the Gin context and embeds it into a new standard context, which can be used in subsequent operations that require tracing.

func PaddingBody

func PaddingBody() func(*gin.Context)

func PostHandlers

func PostHandlers(excludeRoutes ...string) func(*gin.Context)

PostHandlers returns a Gin middleware function that logs the response and duration of API requests.

func PreHandlers

func PreHandlers(maskBodyRoutes ...string) func(*gin.Context)

PreHandlers returns a Gin middleware function to extract and log trace IDs from incoming HTTP requests, and to log request details.

func Recovery

func Recovery(c *gin.Context, err interface{})

Recovery is a utility function meant to be used with the Gin middleware for panic recovery.

func SendNoContentResponse

func SendNoContentResponse(c *gin.Context, err error)

func SendResponse

func SendResponse(c *gin.Context, data interface{}, err error)

SendResponse constructs a standardized response object and attaches it to the Gin context. It is typically used to ensure that all HTTP responses have a consistent format.

func SetApiFlag

func SetApiFlag(c *gin.Context)

func SetContentType

func SetContentType(c *gin.Context)

SetContentType is a Gin middleware that forces the Content-Type of all responses to "application/json". This is particularly useful to handle cases where gin might set the Content-Type to "text/plain" due to certain types of errors, such as JSON binding errors.

func SetLocalRouteFlag

func SetLocalRouteFlag(c *gin.Context)

func UnixSocketMiddleware

func UnixSocketMiddleware() func(*gin.Context)

UnixSocketMiddleware creates a Gin middleware to enforce authorization for requests coming from Unix domain sockets.

func Verify

func Verify(routeType ...secure.RouteType) func(*gin.Context)

func VerifyAgentRoutes

func VerifyAgentRoutes(c *gin.Context, curTs int64, header *secure.HttpHeader, passwordType secure.VerifyType)

func VerifyFile

func VerifyFile() func(*gin.Context)

func VerifyForSetAgentPassword

func VerifyForSetAgentPassword(c *gin.Context, curTs int64, header *secure.HttpHeader, passwordType secure.VerifyType)

func VerifyObRouters

func VerifyObRouters(c *gin.Context, curTs int64, header *secure.HttpHeader, passwordType secure.VerifyType)

func VerifyTaskRoutes

func VerifyTaskRoutes(c *gin.Context, curTs int64, header *secure.HttpHeader, passwordType secure.VerifyType)

Types

type UNIX_CONNECT_TYPE

type UNIX_CONNECT_TYPE string
const UNIX_CONNECT UNIX_CONNECT_TYPE = "unix_conn"

Jump to

Keyboard shortcuts

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