minimal-backend

command module
v0.0.0-...-ff127ef Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: MIT Imports: 8 Imported by: 0

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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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