refactor: rename UCAN -> Token
When using this package, `ucan.Token` reads better than `ucan.UCAN` to me. Encourages the reader to think in terms of "tokens", from the "ucan" package. Performed this refactoring with a few commands (and a few comment edits): $ gofmt -r 'UCAN -> Token' -w . $ gofmt -r 'NewAttenuatedUCAN -> NewAttenuatedToken' -w . $ gofmt -r 'NewOriginUCAN -> NewOriginToken' -w . $ gofmt -r 'UCANParser -> TokenParser' -w . $ gofmt -r 'NewUCANParser -> NewTokenParser' -w . $ gofmt -r 'UCANCtxKey -> TokenCtxKey' -w . Changed example test "ExampleWalkthrough" to "Example" to make go vet happy BREAKING CHANGE: UCAN symbol is now "Token"
This commit is contained in:
20
context.go
20
context.go
@@ -8,19 +8,19 @@ import (
|
||||
// package
|
||||
type CtxKey string
|
||||
|
||||
// UCANCtxKey is the key for adding an access UCAN to a context.Context
|
||||
const UCANCtxKey CtxKey = "UCAN"
|
||||
// TokenCtxKey is the key for adding an access UCAN to a context.Context
|
||||
const TokenCtxKey CtxKey = "UCAN"
|
||||
|
||||
// CtxWithUCAN adds a UCAN value to a context
|
||||
func CtxWithUCAN(ctx context.Context, t UCAN) context.Context {
|
||||
return context.WithValue(ctx, UCANCtxKey, t)
|
||||
// CtxWithToken adds a UCAN value to a context
|
||||
func CtxWithToken(ctx context.Context, t Token) context.Context {
|
||||
return context.WithValue(ctx, TokenCtxKey, t)
|
||||
}
|
||||
|
||||
// FromCtx extracts a Dataset reference from a given
|
||||
// context if one is set, returning nil otherwise
|
||||
func FromCtx(ctx context.Context) *UCAN {
|
||||
iface := ctx.Value(UCANCtxKey)
|
||||
if ref, ok := iface.(*UCAN); ok {
|
||||
// FromCtx extracts a token from a given context if one is set, returning nil
|
||||
// otherwise
|
||||
func FromCtx(ctx context.Context) *Token {
|
||||
iface := ctx.Value(TokenCtxKey)
|
||||
if ref, ok := iface.(*Token); ok {
|
||||
return ref
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user