Documentation
¶
Overview ¶
api provides a mechanism for managing and validating API keys.
Index ¶
Examples ¶
Constants ¶
View Source
const ( DefaultAPIKeyLength = 56 MasterUser = "master" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Guard ¶
type Guard struct {
errors.ClErrCheck
errors.AuthErrCheck
// contains filtered or unexported fields
}
Example ¶
db := &DBMock{}
// mocking key generation to demonstrate resulting API key
keyGen := &KeyGenMock{ExpSRBs: []byte("an-api-key")}
g, _ := api.NewGuard(
db,
api.WithKeyGenerator(keyGen), // This is optional
)
// Generate API key
APIKey, _ := g.NewAPIKey("my-unique-user-id")
fmt.Println(string(APIKey.Value()))
// Validate API Key
userID, _ := g.APIKeyValid(APIKey.Value())
fmt.Println(userID)
Output: bXktdW5pcXVlLXVzZXItaWQ=.an-api-key my-unique-user-id
type KeyGenerator ¶
type Option ¶
func WithAPIKeyLen ¶
func WithKeyGenerator ¶
func WithKeyGenerator(kg KeyGenerator) Option
func WithMasterKey ¶
Click to show internal directories.
Click to hide internal directories.