Golang Rest API with Fiber, PostgreSQL, Gorm & JWT
go get github.com/gofiber/fiber/v2
go get -u gorm.io/gorm
go get -u gorm.io/driver/postgres
go get golang.org/x/crypto/bcrypt
go run main.go
- Motorcycle (CRUD)
- User (Register, Login)
- Uncomment function MigrateMotorcycles & MigrateUsers on models/motorcycles.go & models/users.go
- And also uncomment file which calls the migrate function on the main.go
/api/create_motorcycle
{
"model_name":"Supra Fit",
"machine_type": "2 silinder",
"year":2012,
"color":"matte blue"
}
{
"data": {
"model_name": "Supra Fit",
"machine_type": "2 silinder",
"year": 2012,
"color": "matte blue"
},
"message": "motorcycle succesfully created"
}
/api/motorcycles
{
"data": [
{
"id": 3,
"model_name": "CBR 150R Streetfire",
"machine_type": "4 Langkah, DOHC 4 Katup",
"year": 2002,
"color": "red"
},
{
"id": 4,
"model_name": "CBR 250RR",
"machine_type": "4 Stroke, 8-Valve, Parallel Twin Cylinder",
"year": 2016,
"color": "red"
},
{
"id": 5,
"model_name": "Genio",
"machine_type": "4 Langkah, SOHC, eSP",
"year": 2019,
"color": "matte blue"
],
"message": "successfully get motorcycles"
}
/api/motorcycle/1
{
"data": {
"id": 1,
"model_name": "CBR 150R",
"machine_type": "4 Langkah, DOHC",
"year": 2002,
"color": "blue"
},
"message": "successfully get motorcycle"
}
/api/update_motorcycle/15
{
"model_name":"Supra Fit 125",
"machine_type": "2 silinder",
"year":2012,
"color":"blue"
}
{
"message": "motorcycle successfully updated"
}
/api/delete_motorcycle/15
{
"message": "motorcycle successfully deleted"
}
/api/register
{
"name":"Moh. Ari",
"email":"ari@gmail.com",
"password":"ari"
}
{
"data": {
"id": 8,
"name": "Moh. Ari",
"email": "ari@gmail.com"
},
"message": "user succesfully created"
}
/api/login