This project is example of REST API project build with Go language (especially gin-gonic framework).
This Project implement:
- Gin gonic framework
- Repository-Service Pattern.
- unit testing using testify.
- Basic auth for authentication
- Validation for validate user input
- Config (this folder/package used as configuration such as server, database, etc)
- Entity (this folder/package used to describe data type such as payload or database entity)
- Service (this folder/package contain all business logic)
- Repository (this folder/package is used to store data or communicate to database)
github.com/gin-gonic/gin
github.com/go-playground/validator/v10
github.com/stretchr/testify
golang.org/x/crypto
- Clone/Download this project
- go run .
cd services/user
go test -v
- URL
- /user
- Method
- POST
- Auth
use basic auth, can use predefined admin data (if other admin doesn't register yet):
- username: super.admin
- password: admin12345
- Body / Parameter
-
{ "fullname": "farhan ramadhana", "email": "[email protected]", "password": "pass1234567890", // minimal 10 characters "role": "user" // role: user/admin }
-
- Success Response
-
"data": { "ID": "MT4NSqn3jLHc", "FirstName": "farhan", "MiddleName": "", "LastName": "ramadhana", "Username": "farhan.ramadhana", "Role": "user", "InitialName": "FR", "Email": "[email protected]", "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u", "UpdatedAt": "2021-04-30T07:55:31+07:00" }, "status": "ok"
-
- Error Response
-
{ "message": "", "status": "error" }
-
- Notes
- ID, FirstName, MiddleName, LastName, UserName, InitialName, and Updated Fields auto generated by System
- Password encrypted with Bcrypt
- URL
- /user
- Method
- GET
- Auth
use basic auth, can use predefined admin data (if other admin/user doesn't register yet):
- username: super.admin
- password: admin12345
- Success Response
-
"data": [{ "ID": "MT4NSqn3jLHc", "FirstName": "farhan", "MiddleName": "", "LastName": "ramadhana", "Username": "farhan.ramadhana", "Role": "user", "InitialName": "FR", "Email": "[email protected]", "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u", "UpdatedAt": "2021-04-30T07:55:31+07:00" }], "status": "ok"
-
- Error Response
-
{ "message": "", "status": "error" }
-
- URL
- /user/id/:id
- Method
- GET
- Auth
use basic auth, can use predefined admin data (if other admin/user doesn't register yet):
- username: super.admin
- password: admin12345
- Success Response
-
"data": { "ID": "MT4NSqn3jLHc", "FirstName": "farhan", "MiddleName": "", "LastName": "ramadhana", "Username": "farhan.ramadhana", "Role": "user", "InitialName": "FR", "Email": "[email protected]", "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u", "UpdatedAt": "2021-04-30T07:55:31+07:00" }, "status": "ok"
-
- Error Response
-
{ "message": "", "status": "error" }
-
- URL
- /user/email/:email
- Method
- GET
- Auth
use basic auth, can use predefined admin data (if other admin/user doesn't register yet):
- username: super.admin
- password: admin12345
- Success Response
-
"data": { "ID": "MT4NSqn3jLHc", "FirstName": "farhan", "MiddleName": "", "LastName": "ramadhana", "Username": "farhan.ramadhana", "Role": "user", "InitialName": "FR", "Email": "[email protected]", "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u", "UpdatedAt": "2021-04-30T07:55:31+07:00" }, "status": "ok"
-
- Error Response
-
{ "message": "", "status": "error" }
-
- URL
- /user/usernam/:username
- Method
- GET
- Auth
use basic auth, can use predefined admin data (if other admin/user doesn't register yet):
- username: super.admin
- password: admin12345
- Success Response
-
"data": { "ID": "MT4NSqn3jLHc", "FirstName": "farhan", "MiddleName": "", "LastName": "ramadhana", "Username": "farhan.ramadhana", "Role": "user", "InitialName": "FR", "Email": "[email protected]", "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u", "UpdatedAt": "2021-04-30T07:55:31+07:00" }, "status": "ok"
-
- Error Response
-
{ "message": "", "status": "error" }
-
- URL
- /user/:id
- Method
- DELETE
- Auth
use basic auth, can use predefined admin data (if other admin doesn't register yet):
- username: super.admin
- password: admin12345
- Success Response
-
"status": "ok"
-
- Error Response
-
{ "message": "", "status": "error" }
-
- URL
- /user/:id
- Method
- PATCH
- Auth
use basic auth, can use predefined admin data (if other admin doesn't register yet):
- username: super.admin
- password: admin12345
- Body / Parameter
-
{ "fullname": "farhan ramadhana", "email": "[email protected]", "password": "pass1234567890", // minimal 10 characters "role": "user" // role: user/admin }
-
- Success Response
-
"data": { "ID": "MT4NSqn3jLHc", "FirstName": "farhan", "MiddleName": "", "LastName": "ramadhana", "Username": "farhan.ramadhana", "Role": "user", "InitialName": "FR", "Email": "[email protected]", "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u", "UpdatedAt": "2021-04-30T07:55:31+07:00" }, "status": "ok"
-
- Error Response
-
{ "message": "", "status": "error" }
-
- Notes
- ID, FirstName, MiddleName, LastName, UserName, InitialName, and Updated Fields auto generated by System
- Password encrypted with Bcrypt