Documentation ¶
Index ¶
- Constants
- Variables
- func AddGenericRoute(path string, handler func(writer http.ResponseWriter, request *http.Request))
- func AddRouteWithMethod(path string, method string, ...)
- func AddUserResourceLevel(perm Permission) error
- func AddValidatedRouteWithMethod(path string, method string, handler http.HandlerFunc)
- func DeletePermissionByRole(roleID int) error
- func DeleteResourceLevel(userID int, resourceID int, roleID int) error
- func DeleteResourceLevelByRole(resourceID int, roleID int) error
- func FetchResourceIDByName(name string) (int, error)
- func PermissionLevel(resourceName string, userID int) (int, error)
- func UpdateResourceLevelByRole(roleID int, resourceID int, level int) error
- func ValidateAdmin(next http.HandlerFunc) http.HandlerFunc
- func ValidateLevel(next http.HandlerFunc, levelRequired int) http.HandlerFunc
- type Claims
- type Permission
Constants ¶
const DELETE int = 4
DELETE for delete level permissions
const READ int = 1
READ for read level pemissions
const WRITE int = 2
WRITE for write level permissions
Variables ¶
var AppRouter *mux.Router
AppRouter - used to control routing throughout the app
var Config config.Configuration
Config - used for access to config properties
Functions ¶
func AddGenericRoute ¶
func AddGenericRoute(path string, handler func(writer http.ResponseWriter, request *http.Request))
AddGenericRoute - Adds a route that listens for any requst method
func AddRouteWithMethod ¶
func AddRouteWithMethod(path string, method string, handler func(writer http.ResponseWriter, request *http.Request))
AddRouteWithMethod - Adds a route where you can specify the HTTP request method the route listens on
func AddUserResourceLevel ¶
func AddUserResourceLevel(perm Permission) error
AddUserResourceLevel creates a user permission level for a resource
func AddValidatedRouteWithMethod ¶
func AddValidatedRouteWithMethod(path string, method string, handler http.HandlerFunc)
AddValidatedRouteWithMethod - Adds a middleware-validated route where you can specify the HTTP request method the route listens on
func DeletePermissionByRole ¶
DeletePermissionByRole deletes all user permisisons for a specific role
func DeleteResourceLevel ¶
DeleteResourceLevel deletes the user resource level
func DeleteResourceLevelByRole ¶
DeleteResourceLevelByRole deletes all of a single resource's permissions for a role
func FetchResourceIDByName ¶
FetchResourceIDByName returns a resource record's id associated with the given name
func PermissionLevel ¶
PermissionLevel will tell you what permission level the users has for a given resource 1 - Read 2 - Write 4 - Delete
eg 3 = Read and Write, 5 = Read and Delete, 6 = Write and Delete (weird), 7 = Full permissions
func UpdateResourceLevelByRole ¶
UpdateResourceLevelByRole updates user permissions for a role
func ValidateAdmin ¶
func ValidateAdmin(next http.HandlerFunc) http.HandlerFunc
ValidateAdmin is middleware for validating whether or not the user is an admin user
func ValidateLevel ¶
func ValidateLevel(next http.HandlerFunc, levelRequired int) http.HandlerFunc
ValidateLevel confirms that the user has read-access to the resource defined by the first element of the path. i.e. "user" in /user/do/stuff
Types ¶
type Claims ¶
type Claims struct { IsAdmin bool `json:"isAdmin"` UserID int `json:"userID"` jwt.StandardClaims }
Claims contains infomation to embed in the token
type Permission ¶
type Permission struct { UserID int `json:"userID"` ResourceID int `json:"resourceID"` Level int `json:"level"` RoleID int `json:"roleID"` }
Permission tells you the user's level of access to a resource
func FetchAllUserPermissions ¶
func FetchAllUserPermissions(userID int) ([]Permission, error)
FetchAllUserPermissions returns all resource levels for a given user
func FetchUserResourcePermission ¶
func FetchUserResourcePermission(userID int, resourceID int) (Permission, error)
FetchUserResourcePermission returns the highest level for a given user and resource
func UpdateResourceLevel ¶
func UpdateResourceLevel(perm Permission) (Permission, error)
UpdateResourceLevel updates a user permission level for a resource