mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
implements an fb_exec_requests system table. The purpose of this table is to allow access to internal state to see what queries are running and have been run.
Co-authored-by: Travis Turner <travis@molecula.com>
(cherry picked from commit 47d8be26f5)
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
// Copyright 2022 Molecula Corp (DBA FeatureBase). All rights reserved.
|
|
package context
|
|
|
|
import "context"
|
|
|
|
// Empty struct to avoid allocations
|
|
type contextKeyOriginalIP struct{}
|
|
type contextKeyRequestUserID struct{}
|
|
type contextKeyRequestRequestID struct{}
|
|
|
|
// OriginalIP gets the original IP from the context.
|
|
func OriginalIP(ctx context.Context) (originalIP string, ok bool) {
|
|
originalIP, ok = ctx.Value(contextKeyOriginalIP{}).(string)
|
|
return
|
|
}
|
|
|
|
// WithOriginalIP makes a new context with the originalIP in the context.
|
|
func WithOriginalIP(ctx context.Context, originalIP string) context.Context {
|
|
return context.WithValue(ctx, contextKeyOriginalIP{}, originalIP)
|
|
}
|
|
|
|
func UserID(ctx context.Context) (userID string, ok bool) {
|
|
userID, ok = ctx.Value(contextKeyRequestUserID{}).(string)
|
|
return
|
|
}
|
|
|
|
func WithUserID(ctx context.Context, userID string) context.Context {
|
|
return context.WithValue(ctx, contextKeyRequestUserID{}, userID)
|
|
}
|
|
|
|
func RequestID(ctx context.Context) (userID string, ok bool) {
|
|
userID, ok = ctx.Value(contextKeyRequestRequestID{}).(string)
|
|
return
|
|
}
|
|
|
|
func WithRequestID(ctx context.Context, userID string) context.Context {
|
|
return context.WithValue(ctx, contextKeyRequestRequestID{}, userID)
|
|
}
|