Documentation
¶
Index ¶
- type BunStorage
- func (s *BunStorage) ChangeTokenName(ctx context.Context, token *models.Token, name string) (*models.Token, error)
- func (s *BunStorage) CreateShort(ctx context.Context, short *models.Short) (*models.Short, error)
- func (s *BunStorage) CreateShortLog(ctx context.Context, shortLog *models.ShortLog) error
- func (s *BunStorage) CreateToken(ctx context.Context, token *models.Token) (*models.Token, error)
- func (s *BunStorage) CreateUser(ctx context.Context, user *models.User) (*models.User, error)
- func (s *BunStorage) DeleteShort(ctx context.Context, short *models.Short) error
- func (s *BunStorage) DeleteToken(ctx context.Context, token *models.Token) error
- func (s *BunStorage) DeleteUser(ctx context.Context, user *models.User) error
- func (s *BunStorage) FindShort(ctx context.Context, name string) (*models.Short, error)
- func (s *BunStorage) FindShortByID(ctx context.Context, id string) (*models.Short, error)
- func (s *BunStorage) FindToken(ctx context.Context, value string) (*models.Token, error)
- func (s *BunStorage) FindTokenByID(ctx context.Context, id string) (*models.Token, error)
- func (s *BunStorage) FindUser(ctx context.Context, username string) (*models.User, error)
- func (s *BunStorage) FindUserByID(ctx context.Context, id string) (*models.User, error)
- func (s *BunStorage) ListShortLogs(ctx context.Context, short *models.Short) ([]*models.ShortLog, error)
- func (s *BunStorage) ListShorts(ctx context.Context, user *models.User) ([]*models.Short, error)
- func (s *BunStorage) ListTokens(ctx context.Context, user *models.User) ([]*models.Token, error)
- func (s *BunStorage) Ping(ctx context.Context) error
- func (s *BunStorage) RegisterStartHook(hook func(ctx context.Context, db *bun.DB) error)
- func (s *BunStorage) RegisterStopHook(hook func(ctx context.Context, db *bun.DB) error)
- func (s *BunStorage) Start(ctx context.Context) error
- func (s *BunStorage) Stop(ctx context.Context) error
- type ShortLogModel
- type ShortModel
- type TokenModel
- type UserModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BunStorage ¶
type BunStorage struct {
// StartHooks are ran after the database is connected and the tables are created.
StartHooks []func(ctx context.Context, db *bun.DB) error
// StopHooks are ran before the database is closed.
StopHook []func(ctx context.Context, db *bun.DB) error
// contains filtered or unexported fields
}
func NewBunStorage ¶
func NewBunStorage(cfg *config.Config, db *bun.DB) *BunStorage
func (*BunStorage) ChangeTokenName ¶
func (*BunStorage) CreateShort ¶
func (*BunStorage) CreateShortLog ¶
func (*BunStorage) CreateToken ¶
func (*BunStorage) CreateUser ¶
func (*BunStorage) DeleteShort ¶
func (*BunStorage) DeleteToken ¶
func (*BunStorage) DeleteUser ¶
func (*BunStorage) FindShortByID ¶
func (*BunStorage) FindTokenByID ¶
func (*BunStorage) FindUserByID ¶
func (*BunStorage) ListShortLogs ¶
func (*BunStorage) ListShorts ¶
func (*BunStorage) ListTokens ¶
func (*BunStorage) RegisterStartHook ¶
RegisterStartHook registers a hook to be ran after the database is connected and the tables are created.
func (*BunStorage) RegisterStopHook ¶
RegisterStopHook registers a hook to be ran before the database is closed.
type ShortLogModel ¶
type ShortLogModel struct {
bun.BaseModel `bun:"table:short_logs,alias:sl"`
// ID is the primary key
ID string `bun:",pk,unique,notnull" json:"id"`
// IPAddress is the IP address of the client that accessed the short
IPAddress string `bun:"" json:"ipAddress"`
// UserAgent is the User-Agent of the client that accessed the short
UserAgent string `bun:"" json:"userAgent"`
// Referer is the referer of the client that accessed the short
Referer string `bun:"" json:"referer"`
// CreatedAt is when the short was accessed
CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"createdAt"`
// ShortID is the ID of the short that was accessed
ShortID string `bun:",notnull" json:"-"`
}
type ShortModel ¶
type ShortModel struct {
bun.BaseModel `bun:"table:shorts,alias:s" json:"-"`
ID string `bun:",pk,unique,notnull" json:"id"`
// Name is the short's name, which is also the path to access it
Name string `bun:",unique,notnull" json:"name"`
// URL is the URL that the short will redirect to
URL string `bun:",notnull" json:"url"`
// Deleted is whether the short is soft-deleted or not
Deleted bool `bun:",notnull,default:false" json:"-"`
// CreatedAt is when the short was created (initialized by the storage)
CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"createdAt"`
// DeletedAt is when the short was deleted
DeletedAt time.Time `bun:"" json:"-"`
// UserID is the ID of the user that created the short
// This can be null if the short was deleted
UserID *string `json:"-"`
}
type TokenModel ¶
type TokenModel struct {
bun.BaseModel `bun:"table:tokens,alias:t"`
// ID is the primary key
ID string `bun:",pk,unique,notnull" json:"id"`
// Name is the user-friendly name of the token
Name string `bun:",notnull" json:"name"`
// Value is the actual token
Value string `bun:",unique,notnull" json:"value"`
// CreatedAt is when the token was created (initialized by the storage)
CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"createdAt"`
// UserID is the ID of the user that created the token
UserID *string `bun:",notnull" json:"-"`
}
type UserModel ¶
type UserModel struct {
bun.BaseModel `bun:"table:users,alias:u"`
// ID is the primary key
ID string `bun:",pk,unique,notnull" json:"id"`
// Username is the user's username
Username string `bun:",unique,notnull" json:"username"`
// Password is the user's password
Password string `bun:",notnull" json:"-"`
// CreatedAt is when the user was created (initialized by the storage)
CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"createdAt"`
}
Click to show internal directories.
Click to hide internal directories.