Basic Rest API Golang
Package | Description |
---|---|
Fiber | Fast router based on golang/fasthttp |
Gorm | ORM |
GoDotEnv | .env lib |
Faker | faker (for seeding) |
Uuid | generate uuid |
JWT GO | json web token |
Validator | json validator |
- copy
example.env
into.env
, Fill with yours value - create your database name from
.env
DB
value - add type user_role on your db
CREATE TYPE user_role AS ENUM ( 'ADMIN', 'USER');
- install air to achieve live reload
- or if you won't use air. you can run with
go run .
- run
this will run test and generate code coverage
./run_test.sh
- run seeder
go run cmd/seeder/main.go
- run migrate
go run cmd/migrate/main.go
- run delete all data from table
go run cmd/delete_all_row/main.go
.
└── go-basic-rest-api-revisit/
├── cmd/
│ └── seeder #db seeder
│ └── migrate #drop current existing db then create new
├── config #.env var value, json validator
├── fake #data faker
├── database #get database instance
├── handler #rest api handler / controller
├── service #rest api service [for bussiness logic]
├── middleware #rest api middleware, before visiting controller
├── app #app instance (init -> apply routes -> run)
├── model #rest api model
└── util #buch off helper function