Documentation ¶
Index ¶
- func MysqlConnect(dbUser, dbPassword, dbHost, dbName string) (*sqlx.DB, error)
- func MysqlDropDB(dbUser, dbPassword, dbHost, dbName string) error
- func MysqlInitStorage(dbUser, dbPassword, dbHost, dbName string, createDb bool) error
- type InMemoryStorage
- func (s *InMemoryStorage) Delete(id string) error
- func (s *InMemoryStorage) GetOne(id string) (*model.Link, error)
- func (s *InMemoryStorage) GetOneByShortName(shortName string) (*model.Link, error)
- func (s *InMemoryStorage) Insert(c model.Link) (*model.Link, error)
- func (s *InMemoryStorage) PaginatedGetAll(pageNumber, pageSize int) (results []*model.Link, total int, err error)
- func (s *InMemoryStorage) Update(c model.Link) error
- type MysqlStorage
- func (m *MysqlStorage) Delete(id string) error
- func (m *MysqlStorage) GetOne(id string) (*model.Link, error)
- func (m *MysqlStorage) GetOneByShortName(shortName string) (*model.Link, error)
- func (m *MysqlStorage) Insert(c model.Link) (*model.Link, error)
- func (m *MysqlStorage) PaginatedGetAll(pageNumber, pageSize int) (results []*model.Link, total int, err error)
- func (m *MysqlStorage) Update(c model.Link) error
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MysqlConnect ¶
MysqlConnect creates mysql connection
func MysqlDropDB ¶
MysqlDropDB drops the application database
func MysqlInitStorage ¶
MysqlInitStorage initializes MySQL storage by creating the database (optionally) and the tables
Types ¶
type InMemoryStorage ¶
type InMemoryStorage struct {
// contains filtered or unexported fields
}
InMemoryStorage stores all of the links, needs to be injected into User and Link Resource. In the real world, you would use a database for that.
func (*InMemoryStorage) GetOne ¶
func (s *InMemoryStorage) GetOne(id string) (*model.Link, error)
GetOne link
func (*InMemoryStorage) GetOneByShortName ¶
func (s *InMemoryStorage) GetOneByShortName(shortName string) (*model.Link, error)
GetOneByShortName returns a link byt its short name
func (*InMemoryStorage) PaginatedGetAll ¶
func (s *InMemoryStorage) PaginatedGetAll(pageNumber, pageSize int) (results []*model.Link, total int, err error)
PaginatedGetAll returns a slice of links according to desired pagination and total number of items
type MysqlStorage ¶
type MysqlStorage struct {
// contains filtered or unexported fields
}
MysqlStorage defines a storage implementation that uses MySQL
func (*MysqlStorage) GetOne ¶
func (m *MysqlStorage) GetOne(id string) (*model.Link, error)
GetOne link
func (*MysqlStorage) GetOneByShortName ¶
func (m *MysqlStorage) GetOneByShortName(shortName string) (*model.Link, error)
GetOneByShortName returns a link byt its short name
func (*MysqlStorage) PaginatedGetAll ¶
func (m *MysqlStorage) PaginatedGetAll(pageNumber, pageSize int) (results []*model.Link, total int, err error)
PaginatedGetAll returns a slice of links according to desired pagination and total number of items
type Storage ¶
type Storage interface { PaginatedGetAll(pageNumber, pageSize int) (results []*model.Link, total int, err error) GetOne(id string) (*model.Link, error) GetOneByShortName(shortName string) (*model.Link, error) Insert(c model.Link) (*model.Link, error) Delete(id string) error Update(c model.Link) error }
Storage defines an interface that must be implemented in order to be used as a backend to store the links
func NewInMemoryStorage ¶
func NewInMemoryStorage() Storage
NewInMemoryStorage initializes the storage
func NewMysqlStorage ¶
NewMysqlStorage initializes the MySQL storage