crud

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

README

webimizer-crud

Http CRUD module for Golang

Get Go module by using go get command:

go get webimizer.dev/crud

Documentation

Index

Constants

View Source
const CrudCreateAll string = "CreateAll"

CRUD action constant: Create new item

View Source
const CrudCreateOne string = "CreateOne"

CRUD action constant: Create new item

View Source
const CrudDeleteAll string = "DeleteAll"

CRUD action constant: Delete all items

View Source
const CrudDeleteOne string = "DeleteOne"

CRUD action constant: Delete one item

View Source
const CrudReadAll string = "ReadAll"

CRUD action constant: Filter and return all items

View Source
const CrudReadOne string = "ReadOne"

CRUD action constant: Find and return one item

View Source
const CrudUpdateAll string = "UpdateAll"

CRUD action constant: Update all items

View Source
const CrudUpdateOne string = "UpdateOne"

CRUD action constant: Update one item

Variables

View Source
var GlobalAllowedOrigins []string

Global allowOrigins to use in all CRUD request (optional)

View Source
var GlobalNotAllowHandler webimizer.HttpNotAllowHandler

Global notAllowHandler to use in all CRUD requests if request is not accepted (required)

Functions

func AddCrudHandlers

func AddCrudHandlers(mux *http.ServeMux, one_slug string, all_slug string,
	permissions_map map[string][]string, crudInterface CrudInterface,
	authHandler AuthHandler, errorHandler ErrorHandler)

Add CRUD operations handlers to mux *http.ServeMux

Types

type AuthHandler

type AuthHandler func(rw http.ResponseWriter, r *http.Request) (UserRole, UserUUID, error)

HttpHandler for user authentication processing and return UserRole if success, otherwise return error

type CrudInterface

type CrudInterface interface {
	/* Create new item */
	CreateOne(rw http.ResponseWriter, r *http.Request, ur *UserRole, uuid *UserUUID) error
	/* Create new items */
	CreateAll(rw http.ResponseWriter, r *http.Request, ur *UserRole, uuid *UserUUID) error
	/* Find and return one item */
	ReadOne(rw http.ResponseWriter, r *http.Request, ur *UserRole, uuid *UserUUID) error
	/* Filter and return all items */
	ReadAll(rw http.ResponseWriter, r *http.Request, ur *UserRole, uuid *UserUUID) error
	/* Update one item */
	UpdateOne(rw http.ResponseWriter, r *http.Request, ur *UserRole, uuid *UserUUID) error
	/* Update all items */
	UpdateAll(rw http.ResponseWriter, r *http.Request, ur *UserRole, uuid *UserUUID) error
	/* Delete one item */
	DeleteOne(rw http.ResponseWriter, r *http.Request, ur *UserRole, uuid *UserUUID) error
	/* Delete all items */
	DeleteAll(rw http.ResponseWriter, r *http.Request, ur *UserRole, uuid *UserUUID) error
}

CrudInterface interface for use in CRUD operations by calling Create, ReadOne, ReadAll, Update or Delete func

type ErrorHandler

type ErrorHandler func(err error)

ErrorHandler to handle error messages

type UserRole

type UserRole string
UserRole string type, using to give role to user with specific permissions.

There is two constants you can use UserRoleAdmin and UserRoleUser. You can create your own UserRole too.

const UserRoleAdmin UserRole = "Admin"

CRUD UserRole Admin

const UserRoleUser UserRole = "User"

CRUD UserRole User

func (UserRole) String

func (ur UserRole) String() string

Get UserRole name (string)

func (UserRole) UserCan

func (ur UserRole) UserCan(permissions_map map[string][]string, permission string) bool

Check if user has specific permission by given permisions_map

type UserUUID

type UserUUID string

UserUUID string type, to define autheticated User UUID string

func (UserUUID) String

func (uuid UserUUID) String() string

Get UserUUID string value

Jump to

Keyboard shortcuts

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