Upload files to "/"

This commit is contained in:
naudachu 2024-05-11 09:37:32 +00:00
commit aae82d7d80
1 changed files with 42 additions and 0 deletions

42
rctx.go Normal file
View File

@ -0,0 +1,42 @@
package rctx
import (
"context"
"github.com/google/uuid"
)
// ContextString
// Assign context implementation was stolen
// here: https://medium.com/@funfoolsuzi/logging-with-request-id-in-go-microservice-21485c6730da
type ContextString string
const (
ContextRequestIDKey ContextString = "requestID"
)
// AssignRequestID
//
// Assigns request id to the context.Context variable
func AssignRequestID(ctx context.Context) context.Context {
reqID := uuid.New()
return context.WithValue(ctx, ContextRequestIDKey, reqID.String())
}
// GetRequestID
//
// Gets request id from the context.Context variable
func GetRequestID(ctx context.Context) string {
reqID := ctx.Value(ContextRequestIDKey)
if ret, ok := reqID.(string); ok {
return ret
}
return ""
}