Documentation ¶
Index ¶
- Variables
- type ApiKey
- type Database
- func (db Database) CreateApiKey(key ...uuid.UUID) (*ApiKey, error)
- func (db Database) CreateShortLink(apiKey uuid.UUID, shortname string, url string) (*ShortLink, error)
- func (db Database) GetApiKeyBy(key string, value interface{}) (*ApiKey, error)
- func (db Database) GetApiKeyByApiKey(apiKey uuid.UUID) *ApiKey
- func (db Database) GetShortLinkBy(key string, value interface{}) (*ShortLink, error)
- func (db Database) GetShortLinkByApiKey(apiKey uuid.UUID) *ShortLink
- func (db Database) GetShortLinkByShortname(shortname string) *ShortLink
- func (db Database) GetShortLinkByURL(url string) *ShortLink
- type Dialector
- type Model
- type ShortLink
Constants ¶
This section is empty.
Variables ¶
var ( ErrDialectorNotFound = fmt.Errorf("url-shortener/internal/database: dialector not found") ErrKeyNotFound = errors.New("url-shortener/internal/database: key not found") ErrApiKeyNotExists = errors.New("url-shortener/internal/database: api key doesn't exist") ErrShortLinkExists = errors.New("url-shortener/internal/database: short link already exists") ErrShortLinkNotExists = errors.New("url-shortener/internal/database: short link doesn't exist") )
Functions ¶
This section is empty.
Types ¶
type ApiKey ¶
type ApiKey struct { Model ApiKey uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()" json:"api_key"` AvailableCredits int `gorm:"default:5" json:"available_credits"` UtilizedCredits int `gorm:"default:0" json:"utilized_credits"` ShortLinks []ShortLink `gorm:"foreignKey:ApiKey" json:"short_links"` }
ApiKey represents an api_keys table in the database.
type Database ¶
Database represents a database instance.
func New ¶
New initializes a new Database instance based on the provided Dialector.
It takes a Dialector as a parameter and returns a Database.
func (Database) CreateApiKey ¶
CreateApiKey creates a new API key in the database.
func (Database) CreateShortLink ¶
func (db Database) CreateShortLink(apiKey uuid.UUID, shortname string, url string) (*ShortLink, error)
CreateShortLink creates a short link in the database.
func (Database) GetApiKeyBy ¶
GetApiKeyBy retrieves an API key by a specified key and value.
func (Database) GetApiKeyByApiKey ¶
GetApiKeyByApiKey returns an API key based on the provided API key.
func (Database) GetShortLinkBy ¶
GetShortLinkBy retrieves a ShortLink from the Database based on the specified key and value.
func (Database) GetShortLinkByApiKey ¶
GetShortLinkByApiKey retrieves a ShortLink by the provided API key.
func (Database) GetShortLinkByShortname ¶
GetShortLinkByShortname retrieves a ShortLink from the Database based on the given shortname.
func (Database) GetShortLinkByURL ¶
GetShortLinkByURL retrieves a short link by the given URL.
type Dialector ¶
type Dialector string
Dialector represents a database dialect.
const ( // DialectorPostgres represents the Postgres dialect. DialectorPostgres Dialector = "postgres" )