Upload files to "/"
This commit is contained in:
commit
aae82d7d80
|
|
@ -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 ""
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue