contexti

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPool

func GetPool[REQ any]() sync.Pool

func SetTranceId

func SetTranceId(traceId string) context.Context

func TraceId

func TraceId(ctx context.Context) zap.Field

Types

type DeviceInfo

type DeviceInfo struct {
	//设备
	Device     string `json:"device" gorm:"size:255"`
	Os         string `json:"os" gorm:"size:255"`
	AppCode    string `json:"appCode" gorm:"size:255"`
	AppVersion string `json:"appVersion" gorm:"size:255"`
	IP         string `json:"ip" gorm:"size:255"`
	Lng        string `json:"lng" gorm:"type:numeric(10,6)"`
	Lat        string `json:"lat" gorm:"type:numeric(10,6)"`
	Area       string `json:"area" gorm:"size:255"`
	UserAgent  string `json:"userAgent" gorm:"size:255"`
}

func Device

func Device(infoHeader, area, localHeader, userAgent, ip string) *DeviceInfo

func DeviceFromHeader

func DeviceFromHeader(r http.Header) *DeviceInfo

type HttpContext

type HttpContext RequestContext[http.Request]

func (*HttpContext) SendHeader

func (c *HttpContext) SendHeader(md metadata.MD) error

func (*HttpContext) SetCookie

func (c *HttpContext) SetCookie(v string) error

func (*HttpContext) SetHeader

func (c *HttpContext) SetHeader(md metadata.MD) error

func (*HttpContext) SetTrailer

func (c *HttpContext) SetTrailer(md metadata.MD) error

func (*HttpContext) WriteHeader

func (c *HttpContext) WriteHeader(k, v string) error

type RequestContext

type RequestContext[REQ any] struct {
	context.Context
	TraceID string
	Token   string
	*DeviceInfo
	request.RequestAt
	Request *REQ
	grpc.ServerTransportStream
	Internal string
	Values   map[string]any
}

func CtxFromContext

func CtxFromContext[REQ any](ctx context.Context) *RequestContext[REQ]

func CtxWithRequest

func CtxWithRequest(r *http.Request, tracing bool) (*RequestContext[http.Request], *trace.Span)

func NewCtx

func NewCtx[REQ any](ctx context.Context) *RequestContext[REQ]

func (*RequestContext[REQ]) ContextWrapper

func (c *RequestContext[REQ]) ContextWrapper() context.Context

func (*RequestContext[REQ]) Error

func (c *RequestContext[REQ]) Error(args ...interface{})

func (*RequestContext[REQ]) ErrorLog

func (c *RequestContext[REQ]) ErrorLog(err, originErr error, funcName string) error

func (*RequestContext[REQ]) HandleError

func (c *RequestContext[REQ]) HandleError(err error)

func (*RequestContext[REQ]) Method

func (c *RequestContext[REQ]) Method() string

func (*RequestContext[REQ]) NewDB

func (c *RequestContext[REQ]) NewDB(db *gorm.DB) *gorm.DB

func (*RequestContext[REQ]) StartSpan

func (c *RequestContext[REQ]) StartSpan(name string, o ...trace.StartOption) (*RequestContext[REQ], *trace.Span)

func (*RequestContext[REQ]) WithContext

func (c *RequestContext[REQ]) WithContext(ctx context.Context)

Jump to

Keyboard shortcuts

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