lilcoders

package module
v0.0.0-...-a7cfde9 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGeneric is used for testing purposes and for errors handled later in the callstack
	ErrGeneric = errors.New("generic error")

	// ErrBadRequest (400) is returned for bad request (validation)
	ErrBadRequest = echo.NewHTTPError(400)

	// ErrUnauthorized (401) is returned when user is not authorized
	ErrUnauthorized = echo.ErrUnauthorized
)

Functions

This section is empty.

Types

type AccessRole

type AccessRole int

AccessRole represents access role type

const (
	// SuperAdminRole has all permissions
	SuperAdminRole AccessRole = 100

	// AdminRole has admin specific permissions
	AdminRole AccessRole = 110

	// CompanyAdminRole can edit company specific things
	CompanyAdminRole AccessRole = 120

	// LocationAdminRole can edit location specific things
	LocationAdminRole AccessRole = 130

	// UserRole is a standard user
	UserRole AccessRole = 200
)

type AuthToken

type AuthToken struct {
	Token        string `json:"token"`
	RefreshToken string `json:"refresh_token"`
}

AuthToken holds authentication token details with refresh token

type AuthUser

type AuthUser struct {
	ID         int
	CompanyID  int
	LocationID int
	Username   string
	Email      string
	Role       AccessRole
}

AuthUser represents data stored in JWT token for user

type Base

type Base struct {
	ID        int       `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	DeletedAt time.Time `json:"deleted_at,omitempty" pg:",soft_delete"`
}

Base contains common fields for all tables

func (*Base) BeforeInsert

func (b *Base) BeforeInsert(ctx context.Context) (context.Context, error)

BeforeInsert hooks into insert operations, setting createdAt and updatedAt to current time

func (*Base) BeforeUpdate

func (b *Base) BeforeUpdate(ctx context.Context) (context.Context, error)

BeforeUpdate hooks into update operations, setting updatedAt to current time

type Company

type Company struct {
	Base
	Name      string     `json:"name"`
	Active    bool       `json:"active"`
	Locations []Location `json:"locations,omitempty"`
	Owner     User       `json:"owner"`
}

Company represents company model

type ListQuery

type ListQuery struct {
	Query string
	ID    int
}

ListQuery holds company/location data used for list db queries

type Location

type Location struct {
	Base
	Name    string `json:"name"`
	Active  bool   `json:"active"`
	Address string `json:"address"`

	CompanyID int `json:"company_id"`
}

Location represents company location model

type Logger

type Logger interface {
	// source, msg, error, params
	Log(echo.Context, string, string, error, map[string]interface{})
}

Logger represents logging interface

type Pagination

type Pagination struct {
	Limit  int `json:"limit,omitempty"`
	Offset int `json:"offset,omitempty"`
}

Pagination data

type PaginationReq

type PaginationReq struct {
	Limit int `query:"limit"`
	Page  int `query:"page" validate:"min=0"`
}

PaginationReq holds pagination http fields and tags

func (PaginationReq) Transform

func (p PaginationReq) Transform() Pagination

Transform checks and converts http pagination into database pagination model

type RBACService

type RBACService interface {
	User(echo.Context) AuthUser
	EnforceRole(echo.Context, AccessRole) error
	EnforceUser(echo.Context, int) error
	EnforceCompany(echo.Context, int) error
	EnforceLocation(echo.Context, int) error
	AccountCreate(echo.Context, AccessRole, int, int) error
	IsLowerRole(echo.Context, AccessRole) error
}

RBACService represents role-based access control service interface

type RefreshToken

type RefreshToken struct {
	Token string `json:"token"`
}

RefreshToken holds authentication token details

type Role

type Role struct {
	ID          AccessRole `json:"id"`
	AccessLevel AccessRole `json:"access_level"`
	Name        string     `json:"name"`
}

Role model

type User

type User struct {
	Base
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Username  string `json:"username"`
	Password  string `json:"-"`
	Email     string `json:"email"`

	Mobile  string `json:"mobile,omitempty"`
	Phone   string `json:"phone,omitempty"`
	Address string `json:"address,omitempty"`

	Active bool `json:"active"`

	LastLogin          time.Time `json:"last_login,omitempty"`
	LastPasswordChange time.Time `json:"last_password_change,omitempty"`

	Token string `json:"-"`

	Role *Role `json:"role,omitempty"`

	RoleID     AccessRole `json:"-"`
	CompanyID  int        `json:"company_id"`
	LocationID int        `json:"location_id"`
}

User represents user domain model

func (*User) ChangePassword

func (u *User) ChangePassword(hash string)

ChangePassword updates user's password related fields

func (*User) UpdateLastLogin

func (u *User) UpdateLastLogin(token string)

UpdateLastLogin updates last login field

Directories

Path Synopsis
cmd
api command
migration command
pkg
api
GORSK - Go(lang) restful starter kit API Docs for GORSK v1 Terms Of Service: N/A Schemes: http Version: 2.0.0 License: MIT http://opensource.org/licenses/MIT Contact: Abhishek Srivastava <abhi.f18@gmail.com> Host: localhost:8080 Consumes: - application/json Produces: - application/json Security: - bearer: [] SecurityDefinitions: bearer: type: apiKey name: Authorization in: header swagger:meta
GORSK - Go(lang) restful starter kit API Docs for GORSK v1 Terms Of Service: N/A Schemes: http Version: 2.0.0 License: MIT http://opensource.org/licenses/MIT Contact: Abhishek Srivastava <abhi.f18@gmail.com> Host: localhost:8080 Consumes: - application/json Produces: - application/json Security: - bearer: [] SecurityDefinitions: bearer: type: apiKey name: Authorization in: header swagger:meta
api/user
Package user contains user application services
Package user contains user application services

Jump to

Keyboard shortcuts

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