Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move user ID handling to
userid
package
- Loading branch information
Showing
3 changed files
with
22 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package userid | ||
|
||
import "context" | ||
|
||
type userIDKey struct{} | ||
|
||
// NewContext returns a new context with the given user ID added to the | ||
// context. | ||
// TODO(hs): this doesn't seem to be used / set currently; implement | ||
// when/where it makes sense. | ||
func NewContext(ctx context.Context, userID string) context.Context { | ||
return context.WithValue(ctx, userIDKey{}, userID) | ||
} | ||
|
||
// FromContext returns the user ID from the context if it exists | ||
// and is not empty. | ||
func FromContext(ctx context.Context) (string, bool) { | ||
v, ok := ctx.Value(userIDKey{}).(string) | ||
return v, ok && v != "" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters