basic

package
v0.0.0-...-98b9f36 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotAuthorized is used when the the access is not permisted
	ErrNotAuthorized = errors.New(http.StatusUnauthorized, "not authorized")
	// ErrUserNotFound is used when an user is not found
	ErrUserNotFound = errors.New(http.StatusNotFound, "user not found")
	// ErrUserExists is used when an user already exists
	ErrUserExists = errors.New(http.StatusNotFound, "user already exists")
	// ErrInvalidAdminRouter is used when an invalid admin router is given
	ErrInvalidAdminRouter = errors.New(http.StatusNotFound, "invalid admin router given")
)

Functions

func NewBasicAuth

func NewBasicAuth(repo Repository) func(http.Handler) http.Handler

NewBasicAuth is a HTTP basic auth middleware

Types

type Handler

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

Handler is the api rest handlers

func NewHandler

func NewHandler(repo Repository) *Handler

NewHandler creates a new instance of Handler

func (*Handler) Create

func (c *Handler) Create() http.HandlerFunc

Create is the create handler

func (*Handler) Delete

func (c *Handler) Delete() http.HandlerFunc

Delete is the delete handler

func (*Handler) Index

func (c *Handler) Index() http.HandlerFunc

Index is the find all handler

func (*Handler) Show

func (c *Handler) Show() http.HandlerFunc

Show is the find by handler

func (*Handler) Update

func (c *Handler) Update() http.HandlerFunc

Update is the update handler

type InMemoryRepository

type InMemoryRepository struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

InMemoryRepository represents a in memory repository

func NewInMemoryRepository

func NewInMemoryRepository() *InMemoryRepository

NewInMemoryRepository creates a in memory repository

func (*InMemoryRepository) Add

func (r *InMemoryRepository) Add(user *User) error

Add adds an user to the repository

func (*InMemoryRepository) FindAll

func (r *InMemoryRepository) FindAll() ([]*User, error)

FindAll fetches all the users available

func (*InMemoryRepository) FindByUsername

func (r *InMemoryRepository) FindByUsername(username string) (*User, error)

FindByUsername find an user by username

func (*InMemoryRepository) Remove

func (r *InMemoryRepository) Remove(username string) error

Remove removes an user from the repository

type MongoRepository

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

MongoRepository represents a mongodb repository

func NewMongoRepository

func NewMongoRepository(session *mgo.Session) (*MongoRepository, error)

NewMongoRepository creates a mongo API definition repo

func (*MongoRepository) Add

func (r *MongoRepository) Add(user *User) error

Add adds an user to the repository

func (*MongoRepository) FindAll

func (r *MongoRepository) FindAll() ([]*User, error)

FindAll fetches all the API definitions available

func (*MongoRepository) FindByUsername

func (r *MongoRepository) FindByUsername(username string) (*User, error)

FindByUsername find an user by username

func (*MongoRepository) Remove

func (r *MongoRepository) Remove(username string) error

Remove an user from the repository

type Repository

type Repository interface {
	FindAll() ([]*User, error)
	FindByUsername(username string) (*User, error)
	Add(user *User) error
	Remove(username string) error
}

Repository represents an user repository

type User

type User struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

User represents an user

Jump to

Keyboard shortcuts

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