redirects

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The database table name for redirects.
	TableName = "redirects"
)

Variables

View Source
var (
	// ErrRedirectExists is returned by validate when
	// a redirect from path already exists.
	ErrRedirectExists = errors.New("redirect already exists")
)

Functions

This section is empty.

Types

type Repository

type Repository interface {
	List(meta params.Params) (domain.Redirects, int, error)
	Find(id int) (domain.Redirect, error)
	FindByFrom(from string) (domain.Redirect, error)
	Create(redirect domain.Redirect) (domain.Redirect, error)
	Update(redirect domain.Redirect) (domain.Redirect, error)
	Delete(id int) error
	Exists(id int) bool
	ExistsByFrom(from string) bool
}

Repository defines methods for redirects to interact with the database.

type Store

type Store struct {
	*config.Config
}

Store defines the data layer for redirects.

func New

func New(cfg *config.Config) *Store

New

Creates a new redirects store.

func (*Store) Create

func (s *Store) Create(r domain.Redirect) (domain.Redirect, error)

Create

Returns a new redirect upon creation. Returns errors.CONFLICT if the the redirect (from_path) already exists. Returns errors.INTERNAL if the SQL query was invalid or the function could not get the newly created ID.

func (*Store) Delete

func (s *Store) Delete(id int) error

Delete

Deletes a redirect. Returns nil if the redirect was successfully deleted. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.NOTFOUND if the redirect was not found.

func (*Store) Exists

func (s *Store) Exists(id int) bool

Exists

Returns a bool indicating if the redirect exists by ID. Logs errors.INTERNAL if there was an error executing the query.

func (*Store) ExistsByFrom

func (s *Store) ExistsByFrom(from string) bool

ExistsByFrom

Returns a bool indicating if the redirect exists by from path. Logs errors.INTERNAL if there was an error executing the query.

func (*Store) Find

func (s *Store) Find(id int) (domain.Redirect, error)

Find

Returns a redirect by searching with the given ID. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the redirect was not found by the given ID.

func (*Store) FindByFrom

func (s *Store) FindByFrom(from string) (domain.Redirect, error)

Find

Returns a redirect by searching with the given from path. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the redirect was not found by the given ID.

func (*Store) List

func (s *Store) List(meta params.Params) (domain.Redirects, int, error)

List

Returns a slice of redirects with the total amount. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.NOTFOUND if there are no categories available.

func (*Store) Update

func (s *Store) Update(r domain.Redirect) (domain.Redirect, error)

Update

Returns an updated redirect. Returns errors.CONFLICT if the validation failed. Returns errors.INTERNAL if the SQL query was invalid or the function could not obtain the newly created ID.

Jump to

Keyboard shortcuts

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