controller

package
v0.0.0-...-79dbf9b Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessService

type AccessService interface {
	ValidateToken(IDToken string) (string, error)
}

AccessService represents a service to verifying access tokens

type Auth

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

Auth is a controller that is in charge of authenticating and authorizing requests

func NewAuth

func NewAuth(log *zerolog.Logger, access AccessService) *Auth

NewAuth creates an Auth controller with the given endpoint

func (*Auth) Authorize

func (a *Auth) Authorize(next echo.HandlerFunc) echo.HandlerFunc

Authorize returns the user info for the given access token in the Authorization header It is a middleware, which is why it returns a function that, if successful, calls the function bound to the route.

type Blog

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

Blog is a controller that is in charge of handling the CRUD of blog posts

func NewBlog

func NewBlog(log *zerolog.Logger, blogPostRepository BlogRepository) *Blog

NewBlog creates a Blog controller with the given blog post repository

func (*Blog) Create

func (b *Blog) Create(ctx echo.Context) error

Create creates a new blog post

func (*Blog) Delete

func (b *Blog) Delete(ctx echo.Context) error

Delete removes a blog post from its id

func (*Blog) Find

func (b *Blog) Find(ctx echo.Context) error

Find retrieves all blog posts filtered by some criteria

func (*Blog) Read

func (b *Blog) Read(ctx echo.Context) error

Read retrieves a blog post from its id

func (*Blog) Update

func (b *Blog) Update(ctx echo.Context) error

Update edits a blog post from its id

type BlogRepository

type BlogRepository interface {
	Store(post *model.BlogPost) (*model.BlogPost, error)
	Retrieve(id uint) (*model.BlogPost, error)
	Find(contains *string, limit *uint) ([]*model.BlogPost, error)
	Update(post *model.BlogPost) error
	Delete(id uint) error
}

BlogRepository represents a repository that allows to create, read, update and delete blog posts

type Hasher

type Hasher interface {
	Hash(password string) (string, error)
}

Hasher represents a service that hashes passwords

type TokenGenerator

type TokenGenerator interface {
	Login(user *model.User) (string, error)
	GenerateID() string
}

TokenGenerator represents a service to generate tokens from user info

type User

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

User is a controller that is in charge of handling the CRUD of users

func NewUser

func NewUser(log *zerolog.Logger, userRepository UserRepository, tokens TokenGenerator, hasher Hasher) *User

NewUser creates a User controller with the given user repository

func (*User) Login

func (u *User) Login(ctx echo.Context) error

Login gives a token to the user upon providing their credentials

func (*User) Register

func (u *User) Register(ctx echo.Context) error

Register creates a new user

type UserRepository

type UserRepository interface {
	Store(user *model.User) (*model.User, error)
	AdminExists() bool
}

UserRepository represents a repository that allows to create users and verify whether or not the admin user has already been setup

Jump to

Keyboard shortcuts

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