apikey

package
v0.0.0-...-2d572df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Store Store
}

Config holds the configuration for serving the apikey endpoints

func (*Config) SetupHandlers

func (c *Config) SetupHandlers(router *mux.Router)

SetupHandlers adds the apikey HTTP handlers to the given router

type Create

type Create struct {
	Name string
}

Create defines the parameters passed when creating an

type New

type New struct {
	ID        string
	UserID    string `json:"userId" db:"user_id"`
	Name      string
	Key       string
	LastUsed  time.Time `json:"lastUsed" db:"last_used"`
	CreatedAt time.Time `json:"createdAt" db:"created_at"`
}

New represents a newly created API key and is the only struct exposing the Key itself

type SQLStore

type SQLStore struct {
	// contains filtered or unexported fields
}

SQLStore is an SQL-backed implementation of a Store

func NewSQLStore

func NewSQLStore(db *hnysqlx.DB) *SQLStore

NewSQLStore build a new Store

func NewTestSQLStore

func NewTestSQLStore(db *hnysqlx.DB, time time.Time, id, key string) *SQLStore

NewTestSQLStore allow build a Store with custom generators

func (*SQLStore) Create

func (store *SQLStore) Create(userID string, ck *Create) (*New, error)

Create persists a new key for a user

func (*SQLStore) Delete

func (store *SQLStore) Delete(userID, keyID string) (*Struct, error)

Delete removes a give key for a user

func (*SQLStore) GetByKey

func (store *SQLStore) GetByKey(key string) (*Struct, error)

GetByKey returns the related to a given Key

func (*SQLStore) List

func (store *SQLStore) List(userID string) ([]*Struct, error)

List returns all s associated with a user

type Store

type Store interface {
	Create(string, *Create) (*New, error)
	Delete(string, string) (*Struct, error)
	GetByKey(string) (*Struct, error)
	List(string) ([]*Struct, error)
}

The Store interface defines functions for interacting and managing API keys

type Struct

type Struct struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	UserID    string    `json:"userId" db:"user_id"`
	LastUsed  time.Time `json:"lastUsed" db:"last_used"`
	CreatedAt time.Time `json:"createdAt" db:"created_at"`
}

Struct represents a key that can be used via to interact with an API as an authenticated user.

The Key itself is not exposed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL