080ba47a06
Change-Id: I6a419c62700c568254ff67ae5b73efed2fc98aa2
24 lines
564 B
Go
24 lines
564 B
Go
// 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
|
|
}
|