storj/pkg/auth/apikey.go

24 lines
564 B
Go
Raw Normal View History

2019-01-24 20:15:10 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package auth
import (
"context"
)
// The key type is unexported to prevent collisions with context keys defined in
// other packages.
type apikey struct{}
// WithAPIKey creates context with api key.
func WithAPIKey(ctx context.Context, key []byte) context.Context {
return context.WithValue(ctx, apikey{}, key)
}
// GetAPIKey returns api key from context is exists.
func GetAPIKey(ctx context.Context) ([]byte, bool) {
key, ok := ctx.Value(apikey{}).([]byte)
return key, ok
}