What is this?
A backend boilerplate, uses mongodb at localhost:27017 by default.
How to use?
- Clone the repository.
- Build and run or simply do
go run .
.
Endpoints?
POST /auth/add
- Add a user
curl -X POST http://localhost:8080/auth/add \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'username=test' \
-d 'pswdhash=testhash'
Response:
{
"message": "User {username} added"
}
POST /auth/del
- Delete a user
curl -X POST http://localhost:8080/auth/del \
-H "Content-Type: application/x-www-form-urlencoded" \
-H 'Authorization: bearer sometoken' \
-d 'username=test' \
Response:
{
"message": "User {username} deleted"
}
POST /auth/login
- Login, returns a JWT token with a 24 hour expiry
curl -X POST http://localhost:8080/auth/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'username=test' \
-d 'pswdhash=testhash'
Response:
{
"username": {username},
"token": {token}
}
POST /auth/addtogroup
- Add a user to a group
curl -X POST http://localhost:8080/auth/addtogroup \
-H "Content-Type: application/x-www-form-urlencoded" \
-H 'Authorization: bearer sometoken' \
-d 'groupname=testgroup' \
-d 'username=test'
Response:
{
"message": "User {username} added to group {groupname}"
}
POST /auth/rmfromgroup
- Remove a user from a group
curl -X POST http://localhost:8080/auth/rmfromgroup \
-H "Content-Type: application/x-www-form-urlencoded" \
-H 'Authorization: bearer sometoken' \
-d 'groupname=testgroup' \
-d 'username=test'
Response:
{
"message": "User {username} removed from group {groupname}"
}
POST /auth/addrighttogroup
- Add a right to a group
curl -X POST http://localhost:8080/auth/addrighttogroup \
-H "Content-Type: application/x-www-form-urlencoded" \
-H 'Authorization: bearer sometoken' \
-d 'groupname=testgroup' \
-d 'right=testright'
Response:
{
"message": "Right {right} added to group {groupname}"
}
POST /auth/rmrightfromgroup
- Remove a right from a group
curl -X POST http://localhost:8080/auth/rmrightfromgroup \
-H "Content-Type: application/x-www-form-urlencoded" \
-H 'Authorization: bearer sometoken' \
-d 'groupname=testgroup' \
-d 'right=testright'
Response:
{
"message": "Right {right} removed from group {groupname}"
}
POST /auth/createadmin
- Create an admin user(only accessible through localhost)
curl -X POST http://localhost:8080/auth/createadmin \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'username=admin' \
-d 'pswdhash=adminhash'
Group Rights:
admin
- Can do everything
delete_user
- Can delete users
edit_group
- Can edit groups and its users and permissions
Database structure
db
|-users
| |-User
| |-_id
| |-username
| |-pswdhash
| |-usergroup
|-groups
| |-UserGroup
| |-_id
| |-groupname
| |-users
| |-permissions
Logging
logger
module is used for logging, log entries are of the spec date time file:line message
, all logs are written to logs.log
file, as well as stdout.