ctxtags

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const XRequestID = "X-Request-Id"

Variables

View Source
var NoopTags = &noopTags{}

NoopTags is a trivial, minimum overhead implementation of Tags for which all operations are no-ops.

Functions

func CtxTags

func CtxTags(opts ...Option) gin.HandlerFunc

func RequestID

func RequestID(c *gin.Context) map[string]interface{}

func ToContext

func ToContext(c *gin.Context, tags Tags) *gin.Context

Types

type Option

type Option func(*options)

func WithFieldExtractor

func WithFieldExtractor(f RequestFieldExtractorFunc) Option

WithFieldExtractor customizes the function for extracting log fields from protobuf messages, for unary and server-streamed methods only.

type RequestFieldExtractorFunc

type RequestFieldExtractorFunc func(ctx *gin.Context) map[string]interface{}

RequestFieldExtractorFunc is a user-provided function that extracts field information from a http request. It is called from tags middleware on arrival of request. Keys and values will be added to the context tags. If there are no fields, you should return a nil.

type Tags

type Tags interface {
	// Set sets the given key in the metadata tags.
	Set(key string, value interface{}) Tags
	// Has checks if the given key exists.
	Has(key string) bool
	// Values returns a map of key to values.
	// Do not modify the underlying map, please use Set instead.
	Values() map[string]interface{}
}

Tags is the interface used for storing request tags between Context calls. The default implementation is *not* thread safe, and should be handled only in the context of the request.

func FromContext

func FromContext(c context.Context) Tags

func NewTags

func NewTags() Tags

Jump to

Keyboard shortcuts

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