| package contexts
|
|
|
| import (
|
| "context"
|
| "sync"
|
|
|
| "github.com/looplj/axonhub/internal/ent"
|
| "github.com/looplj/axonhub/internal/ent/request"
|
| )
|
|
|
|
|
| type contextContainer struct {
|
| ProjectID *int
|
| TraceID *string
|
| RequestID *string
|
| OperationName *string
|
| APIKey *ent.APIKey
|
| User *ent.User
|
| Source *request.Source
|
| Thread *ent.Thread
|
| Trace *ent.Trace
|
| Errors []error
|
| mu sync.RWMutex
|
|
|
|
|
| ChannelAPIKey *string
|
| }
|
|
|
|
|
| func getContainer(ctx context.Context) *contextContainer {
|
| if container, ok := ctx.Value(containerContextKey).(*contextContainer); ok {
|
| return container
|
| }
|
|
|
|
|
| container := &contextContainer{}
|
|
|
| return container
|
| }
|
|
|
|
|
| func withContainer(ctx context.Context, container *contextContainer) context.Context {
|
| if ctx.Value(containerContextKey) == nil {
|
| return context.WithValue(ctx, containerContextKey, container)
|
| }
|
|
|
| return ctx
|
| }
|
|
|