27 lines
441 B
Go
27 lines
441 B
Go
package apiresponse
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const TraceIDHeader = "X-Trace-Id"
|
|
|
|
type ctxKey int
|
|
|
|
const traceIDKey ctxKey = iota
|
|
|
|
func WithTraceID(ctx context.Context, id string) context.Context {
|
|
return context.WithValue(ctx, traceIDKey, id)
|
|
}
|
|
|
|
func TraceIDFromContext(ctx context.Context) string {
|
|
id, _ := ctx.Value(traceIDKey).(string)
|
|
return id
|
|
}
|
|
|
|
func GenerateTraceID() string {
|
|
return uuid.NewString()
|
|
}
|