This project is a Go-based web application utilizing Gin Gonic for the web framework, GORM for ORM, and PostgreSQL as the database. It includes features such as user and role management with JWT-based authentication and more.
belajar-go/
│
├── cmd/
│ └── main.go
│
├── configs/
│ └── dbConfig.go
│
├── internal/
│ ├── delivery/
│ │ ├── handlers/
│ │ │ └── bookHandler/
│ │ │ └── bookHandler.go
│ │ │
│ │ ├── data/
│ │ │ ├── request/
│ │ │ │ └── bookReq/
│ │ │ │ └── bookRequest.go
│ │ │ │
│ │ │ └── response/
│ │ │ ├── bookRes
│ │ │ │ └── bookResponse.go
│ │ │ └── response.go
│ │ │
│ │ └── router/
│ │ ├── bookRouter/
│ │ │ └── bookRouter.go
│ │ │
│ │ └── router.go
│ │
│ ├── domain/
│ │ ├── models/
│ │ │ └── books.go
│ │ │
│ │ ├── repositories/
│ │ │ ├── bookRepo/
│ │ │ │ └── bookRepo.go
│ │ │ │
│ │ │ └── repoInterface/
│ │ │ └── bookRepoInterface.go
│ │ │
│ │ └── services/
│ │ ├── bookService/
│ │ │ └── bookService.go
│ │ │
│ │ └── serviceInterface/
│ │ └── bookServiceInterface.go
│ │
│ └── infrastructure/
│ └── database/
│ ├── database.go
│ └── migrations.go
│
├── pkg/
│ ├── utils/
│ │ └── base.go
│ │
│ └── helpers/
│ └── errorPanic.go
│
├── .env.example
├── .gitignore
├── go.mod
└── go.sum
- Go 1.22+
- PostgreSQL
CompileDaemon
for live reloading during development
-
Clone the repository:
git clone https://github.com/yourusername/belajar-go.git cd belajar-go
-
Copy the example environment variables file and configure it:
cp .env.example .env
-
Install the dependencies:
go mod download
Update the .env
file with your database credentials and other configurations.
- Create the database:
createdb belajar_go
You can use CompileDaemon
to automatically rebuild and restart the application when you make changes to the source code.
-
Install
CompileDaemon
:go install github.com/githubnemo/CompileDaemon@latest
-
Start the application:
CompileDaemon --build="go build cmd/main.go" --command=./main
GET /books
- Get all booksPOST /books
- Create a new bookGET /books/:id
- Get a book by IDPUT /books/:id
- Update a book by IDDELETE /books/:id
- Delete a book by ID
- cmd/: Entry point of the application.
- configs/: Configuration files.
- internal/: Internal application code.
- delivery/: Contains the HTTP handlers and routers.
- domain/: Contains the business logic and models.
- infrastructure/: Contains the database setup and migrations.
- pkg/: Utility packages and helpers.
- .env.example: Example environment variables file.
- go.mod: Go module file.
- go.sum: Go module dependencies file.