add: user accomplished
This commit is contained in:
@@ -28,3 +28,27 @@ func TokenFrom(c context.Context) (string, error) {
|
||||
}
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func WithUserID(c context.Context, id int64) context.Context {
|
||||
return context.WithValue(c, "user_id", id)
|
||||
}
|
||||
|
||||
func UserIDFrom(c context.Context) (int64, error) {
|
||||
if userID, ok := c.Value("user_id").(int64); !ok {
|
||||
return 0, errors.New("user_id not found in context")
|
||||
} else {
|
||||
return userID, nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithRequestID(c context.Context, requestID string) context.Context {
|
||||
return context.WithValue(c, "request_id", requestID)
|
||||
}
|
||||
|
||||
func RequestIDFrom(c context.Context) (string, error) {
|
||||
if requestID, ok := c.Value("request_id").(string); !ok {
|
||||
return "", errors.New("request_id not found in context")
|
||||
} else {
|
||||
return requestID, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user