Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateKey(keyType KeyType) (string, error)
- func IsValidAuthLevel(lvl AuthLevel) bool
- func NewSqlDB(uri string) *bun.DB
- type AuthLevel
- type AuthProvider
- type CtxAuthKey
- type KeyType
- type KeyUsage
- type MemoryProvider
- func (a *MemoryProvider) Authenticate(r *http.Request) (AuthLevel, error)
- func (a *MemoryProvider) Register() (string, error)
- func (a *MemoryProvider) UpdateUsage(key string, usageDelta KeyUsage) error
- func (a *MemoryProvider) WithDefaultExpiry(defaultExpiry time.Duration) *MemoryProvider
- func (a *MemoryProvider) WithKeyType(keyType KeyType) *MemoryProvider
- type NoAuthProvider
- type Provider
- type SqlAuthProvider
Constants ¶
View Source
const ( KeyTypeUUIDString = "uuid" KeyTypeHex16String = "hex16" KeyTypeHex32String = "hex32" KeyTypeHex64String = "hex64" KeyTypeHex128String = "hex128" KeyTypeHex256String = "hex256" )
string key types
Variables ¶
View Source
var ( ErrCheckingAuth = errors.New("unable to check auth") ErrInvalidKey = errors.New("invalid key") )
Functions ¶
func GenerateKey ¶
func IsValidAuthLevel ¶
Types ¶
type AuthProvider ¶
type AuthProvider string
const ( AuthProviderNoAuth AuthProvider = "noauth" AuthProviderMemory AuthProvider = "memory" AuthProviderSql AuthProvider = "sql" )
func ToProvider ¶
func ToProvider(s string) AuthProvider
type MemoryProvider ¶
type MemoryProvider struct { nocopy.NoCopy // keys is a map of API keys to their corresponding secret. Keys map[string]*memoryKey // contains filtered or unexported fields }
func NewMemoryProvider ¶
func NewMemoryProvider() *MemoryProvider
func (*MemoryProvider) Authenticate ¶
func (a *MemoryProvider) Authenticate(r *http.Request) (AuthLevel, error)
func (*MemoryProvider) Register ¶
func (a *MemoryProvider) Register() (string, error)
func (*MemoryProvider) UpdateUsage ¶
func (a *MemoryProvider) UpdateUsage(key string, usageDelta KeyUsage) error
func (*MemoryProvider) WithDefaultExpiry ¶
func (a *MemoryProvider) WithDefaultExpiry(defaultExpiry time.Duration) *MemoryProvider
func (*MemoryProvider) WithKeyType ¶
func (a *MemoryProvider) WithKeyType(keyType KeyType) *MemoryProvider
type NoAuthProvider ¶
type NoAuthProvider struct{}
func NewNoAuthProvider ¶
func NewNoAuthProvider() *NoAuthProvider
func (*NoAuthProvider) Authenticate ¶
func (a *NoAuthProvider) Authenticate(r *http.Request) (AuthLevel, error)
with no auth, highest auth level is defualt
func (*NoAuthProvider) Register ¶
func (a *NoAuthProvider) Register() (string, error)
func (*NoAuthProvider) UpdateUsage ¶
func (a *NoAuthProvider) UpdateUsage(key string, usageDelta KeyUsage) error
type SqlAuthProvider ¶
type SqlAuthProvider struct {
// contains filtered or unexported fields
}
func NewSqlAuthProvider ¶
func NewSqlAuthProvider(db *bun.DB) *SqlAuthProvider
func (*SqlAuthProvider) Authenticate ¶
func (a *SqlAuthProvider) Authenticate(r *http.Request) (AuthLevel, error)
func (*SqlAuthProvider) Register ¶
func (a *SqlAuthProvider) Register() (string, error)
func (*SqlAuthProvider) UpdateUsage ¶
func (a *SqlAuthProvider) UpdateUsage(key string, usageDelta KeyUsage) error
func (*SqlAuthProvider) WithKeyType ¶
func (a *SqlAuthProvider) WithKeyType(keyType KeyType) *SqlAuthProvider
Click to show internal directories.
Click to hide internal directories.