Documentation ¶
Index ¶
- Constants
- func CORS(next http.Handler) http.Handler
- func CountryFromContext(ctx context.Context) string
- func DebugIDFromContext(ctx context.Context) uint64
- func EchoHandler(next http.Handler) echo.HandlerFunc
- func EchoIPContext() echo.MiddlewareFunc
- func EchoSentryHubContext() echo.MiddlewareFunc
- func IPFromContext(ctx context.Context) string
- func IsDevelFromContext(ctx context.Context) bool
- func NewCountryContext(ctx context.Context, country string) context.Context
- func NewDebugIDContext(ctx context.Context, debugID uint64) context.Context
- func NewIPContext(ctx context.Context, ip string) context.Context
- func NewIsDevelContext(ctx context.Context, isDevel bool) context.Context
- func NewNotificationContext(ctx context.Context) context.Context
- func NewPlatformContext(ctx context.Context, platform string) context.Context
- func NewSentryHubContext(ctx context.Context, sentryHub *sentry.Hub) context.Context
- func NewSqlGroupContext(ctx context.Context, group string) context.Context
- func NewSqlQueryLogger() *sqlQueryLogger
- func NewUserAgentContext(ctx context.Context, ua string) context.Context
- func NewVersionContext(ctx context.Context, version string) context.Context
- func NewXRequestIDContext(ctx context.Context, requestId string) context.Context
- func NotificationFromContext(ctx context.Context) bool
- func PlatformFromContext(ctx context.Context) string
- func SqlGroupFromContext(ctx context.Context) string
- func UserAgentFromContext(ctx context.Context) string
- func VersionFromContext(ctx context.Context) string
- func WithAPILogger(pf Printf, serverName string) zenrpc.MiddlewareFunc
- func WithDevel(isDevel bool) zenrpc.MiddlewareFunc
- func WithErrorLogger(pf Printf, serverName string) zenrpc.MiddlewareFunc
- func WithHeaders() zenrpc.MiddlewareFunc
- func WithMetrics(appName string) zenrpc.MiddlewareFunc
- func WithNoCancelContext() zenrpc.MiddlewareFunc
- func WithSQLLogger(db *pg.DB, isDevel bool, allowDebugFunc, allowSqlDebugFunc AllowDebugFunc) zenrpc.MiddlewareFunc
- func WithSentry(serverName string) zenrpc.MiddlewareFunc
- func WithTiming(isDevel bool, allowDebugFunc AllowDebugFunc) zenrpc.MiddlewareFunc
- func XRequestID(next http.Handler) http.Handler
- func XRequestIDFromContext(ctx context.Context) string
- type AllowDebugFunc
- type Duration
- type Printf
Constants ¶
const (
DefaultServerName = ""
)
Variables ¶
This section is empty.
Functions ¶
func CountryFromContext ¶ added in v1.1.6
CountryFromContext returns country from context.
func DebugIDFromContext ¶ added in v1.1.1
func EchoHandler ¶
EchoHandler is wrapper for Echo.
func EchoIPContext ¶ added in v1.1.3
func EchoIPContext() echo.MiddlewareFunc
EchoIPContext middleware applies client ip to context for zenrpc middleware.
func EchoSentryHubContext ¶ added in v1.1.3
func EchoSentryHubContext() echo.MiddlewareFunc
EchoSentryHubContext middleware applies sentry hub to context for zenrpc middleware.
func IPFromContext ¶
IPFromContext returns IP from context.
func IsDevelFromContext ¶
IsDevelFromContext returns isDevel flag from context.
func NewCountryContext ¶ added in v1.1.6
NewCountryContext creates new context with country.
func NewDebugIDContext ¶ added in v1.1.1
NewDebugIDContext creates new context with debug ID.
func NewIPContext ¶
NewIPContext creates new context with IP.
func NewIsDevelContext ¶ added in v1.1.1
NewIsDevelContext creates new context with isDevel flag.
func NewNotificationContext ¶ added in v1.1.4
NewNotificationContext creates new context with JSONRPC2 notification flag.
func NewPlatformContext ¶ added in v1.1.0
NewPlatformContext creates new context with platform.
func NewSentryHubContext ¶
NewSentryHubContext creates new context with Sentry Hub.
func NewSqlGroupContext ¶ added in v1.1.0
NewSqlGroupContext creates new context with SQL Group for debug SQL logging.
func NewSqlQueryLogger ¶ added in v1.1.1
func NewSqlQueryLogger() *sqlQueryLogger
func NewUserAgentContext ¶ added in v1.1.0
NewUserAgentContext creates new context with User-Agent.
func NewVersionContext ¶ added in v1.1.0
NewVersionContext creates new context with version.
func NewXRequestIDContext ¶ added in v1.1.0
NewXRequestIDContext creates new context with X-Request-ID.
func NotificationFromContext ¶ added in v1.1.4
NotificationFromContext returns JSONRPC2 notification flag from context.
func PlatformFromContext ¶
PlatformFromContext returns platform from context.
func SqlGroupFromContext ¶ added in v1.1.1
SqlGroupFromContext returns sql group from context.
func UserAgentFromContext ¶
UserAgentFromContext returns userAgent from context.
func VersionFromContext ¶
VersionFromContext returns version from context.
func WithAPILogger ¶
WithAPILogger logs via Printf function (e.g. log.Printf) all requests.
func WithDevel ¶
func WithDevel(isDevel bool) zenrpc.MiddlewareFunc
WithDevel sets bool flag to context for detecting development environment.
func WithErrorLogger ¶
WithErrorLogger logs all errors (ErrorCode==500 or < 0) via Printf func and sends them to Sentry. It also removes sensitive error data from response. It is good to use pkg/errors for stack trace support in sentry.
func WithHeaders ¶
func WithHeaders() zenrpc.MiddlewareFunc
WithHeaders sets User-Agent, Platform, Version, X-Country headers to context. User-Agent strips to 2048 chars, Platform and Version – to 64, X-Country - to 16.
func WithMetrics ¶
func WithMetrics(appName string) zenrpc.MiddlewareFunc
WithMetrics logs duration of RPC requests via Prometheus. Default AppName is zenrpc. It exposes two metrics: `appName_rpc_error_requests_count` and `appName_rpc_responses_duration_seconds`. Labels: method, code, platform, version.
func WithNoCancelContext ¶
func WithNoCancelContext() zenrpc.MiddlewareFunc
WithNoCancelContext ignores Cancel func from context. This is useful for passing context to `go-pg`.
func WithSQLLogger ¶
func WithSQLLogger(db *pg.DB, isDevel bool, allowDebugFunc, allowSqlDebugFunc AllowDebugFunc) zenrpc.MiddlewareFunc
WithSQLLogger adds `SQL` or `DurationSQL` fields in JSON-RPC 2.0 Response `extensions` field (not in spec). `DurationSQL` field is set then `isDevel=true` or AllowDebugFunc(allowDebugFunc) returns `true` and http request is set. `SQL` field is set then `isDevel=true` or AllowDebugFunc(allowDebugFunc, allowSqlDebugFunc) returns `true` and http request is set.
func WithSentry ¶
func WithSentry(serverName string) zenrpc.MiddlewareFunc
WithSentry sets additional parameters for current Sentry scope. Extras: params, duration, ip. Tags: platform, version, method.
func WithTiming ¶
func WithTiming(isDevel bool, allowDebugFunc AllowDebugFunc) zenrpc.MiddlewareFunc
WithTiming adds timings in JSON-RPC 2.0 Response via `extensions` field (not in spec). Middleware is active when `isDevel=true` or AllowDebugFunc returns `true` and http request is set. `DurationLocal` – total method execution time in ms. If `DurationRemote` or `DurationDiff` are set then `DurationLocal` excludes these values.
func XRequestID ¶ added in v1.1.0
XRequestID add X-Request-ID header if not exists.
func XRequestIDFromContext ¶ added in v1.1.0
XRequestIDFromContext returns X-Request-ID from context.