Categorygithub.com/Coosis/minimal-backend
modulepackage
0.0.0-20240710070217-ff127ef448d6
Repository: https://github.com/coosis/minimal-backend.git
Documentation: pkg.go.dev

# README

What is this?

A backend boilerplate, uses mongodb at localhost:27017 by default.

How to use?

  1. Clone the repository.
  2. Build and run or simply do go run ..

Endpoints?

  1. 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"
}
  1. 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"
}
  1. 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}
}
  1. 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}"
}
  1. 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}"
}
  1. 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}"
}
  1. 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}"
}
  1. 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.

# Packages

No description provided by the author
No description provided by the author