users

package
v0.0.0-...-5e14d7d Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoginForm

type LoginForm struct {
	Email    string `schema:"email"`
	Password string `schema:"password"`
}

type RestApi

type RestApi struct {
	Routes routes.ApiRestRouteSet
	// contains filtered or unexported fields
}

func NewRestApi

func NewRestApi(userSvc UserService) RestApi

func (*RestApi) DeleteHandler

func (h *RestApi) DeleteHandler(w http.ResponseWriter, r *http.Request)

func (*RestApi) LoginHandler

func (h *RestApi) LoginHandler(w http.ResponseWriter, r *http.Request)

func (*RestApi) RegisterHandler

func (h *RestApi) RegisterHandler(w http.ResponseWriter, r *http.Request)

func (*RestApi) ShowAllHandler

func (h *RestApi) ShowAllHandler(w http.ResponseWriter, r *http.Request)

func (*RestApi) UpdateHandler

func (h *RestApi) UpdateHandler(w http.ResponseWriter, r *http.Request)

type SignupForm

type SignupForm struct {
	Name     string `schema:"name"`
	Email    string `schema:"email"`
	Password string `schema:"password"`
}

type User

type User struct {
	ID    int    `gorm:"primary_key" json:"id"`
	Email string `gorm:"not null;unique_index" json:"email"`
	Name  string `json:"name"`
	Hash  string `json:"-"` // skipped on json marshalling
}

type UserService

type UserService interface {
	Authenticate(email, password string) (*tokens.JWTToken, error)
	Register(name, email, password string) (*User, error)
	GetByID(id uint) (*User, error)
}

UserService

func NewUserService

func NewUserService(store UserStore) UserService

type UserStore

type UserStore interface {
	GetByID(int uint) (*User, error)
	GetByEmail(email string) (*User, error)

	Create(user *User) error

	// Close is used for closing the connection(s) to the store (database).
	Close()

	// AutoMigrate is a helper method used for database migration
	Migrate() error
}

UserStore is used for interacting with the persistence layer for users, and it is the contract (interface) to used by outside package components. For all `Get_` methods, it either returns the user that is found and a nil error, or an error that is either defined by the `models` package (such as `ErrNotFound`) or another, more low level error.

func NewUserStore

func NewUserStore(dbConnInfo string) (UserStore, error)

Jump to

Keyboard shortcuts

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