hoser

package module
v0.0.0-...-799afea Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: MIT Imports: 2 Imported by: 0

README

Build Status GoDoc Coverage Status Go Report Card

hoser

Simple user and user rights management - a Go package

Package hoser impelements a Bolthold (BoltDB) store (easy to add other stores) implementation of a User interface and a to-be growing variety of tools. The HTTP service and any related middleware is/will be compatible with the Golang standard http package and routers/muxes like Chi which follow the same signature.

What's a "hoser"?

It's inappropriate to consider system users as lusers, but it happens, and a hoser is akin to the same idea. It's all in fun and in short of a short name for this package. If you don't like it, take off, eh?

Bob and Doug Mackenzie characters from SCTV show The Great White North

Wikipedia provides some background; this CBC article has a worthwhile quote:

The Bob and Doug bit started out in the 1980s as a bit of a rebellion against a network order to include more Canadian content, but ended up becoming a pop-culture sensation ensuring "eh" entered the Canadian lexicon.

For that, Thomas is sorry.

"I apologize to the country, to everyone individually in Canada," Thomas said with a laugh. "I'm so sorry we brought hosers and 'take off' into the linguistic compendium of Canada."

Documentation

Overview

Package hoser provides a basic User concept incorporating a simple role/permissions capability; a UserService interface to manage users and a concrete implementation backed by BoltHold, a wrapper around the capable BoltDB.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Permissions

type Permissions map[string]bool

Permissions is a map[string]bool representing the permissions or roles a user may have. p["is_admin"] = true

func (Permissions) Grant

func (p Permissions) Grant(permission string)

Grant adds the permission to the user

func (Permissions) IsGranted

func (p Permissions) IsGranted(permission string) bool

IsGranted returns true if the user has the permission

func (Permissions) Ungrant

func (p Permissions) Ungrant(permission string)

Ungrant removes the permission from the user

type User

type User struct {
	ID          uint64      `json:"id" boltholdKey:"ID"` // Primary key
	FirstName   string      `json:"first_name" validate:"required"`
	LastName    string      `json:"last_name" validate:"required"`
	Email       string      `json:"email" validate:"required,email" boltholdIndex:"Email"`
	Password    string      `json:"-" validate:"required"` // Hashed password
	Salt        string      `json:"-"`
	Permissions Permissions `json:"-"`
	CreatedAt   time.Time   `json:"created_at"`
	UpdatedAt   time.Time   `json:"updated_at"`
}

User is a representation of an application user Email is used as the primary lookup key Create new user instances using the NewUser() constructor.

func NewUser

func NewUser() *User

NewUser constructs and returns a User

func (*User) Validate

func (u *User) Validate() error

Validate user data according to User 'validate' struct tags

type UserService

type UserService interface {
	User(string) (*User, error) // Retrieve user by the key which is Email
	UserID(int) (*User, error)
	AddUser(*User) error
	UpdateUser(*User) error
}

UserService retrieves, creates and manages Users in a storage

Directories

Path Synopsis
Package bolthold provides a BoltHold-backed implementation of the hoser.UserService interface.
Package bolthold provides a BoltHold-backed implementation of the hoser.UserService interface.
Package http provides a client for a UserService suitable for incorporating within web applications.
Package http provides a client for a UserService suitable for incorporating within web applications.

Jump to

Keyboard shortcuts

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