Spaces:
Configuration error
Configuration error
Golang API Boilerplate
This is a boilerplate for a RESTful API written in Golang.
Features
- JWT Authentication
- PostgreSQL Database
- GORM ORM
- Gin Framework
- Docker Support
- Environment Variables
- Logging
- Error Handling
Getting Started
- Clone the repository
- Run
go getto download the dependencies - Create a file named
.envand add the following variables:DB_HOSTDB_USERDB_PASSWORDDB_NAMEDB_PORTSALTHOST_ADDRESSHOST_PORT
LOG_PATH
- Run
go run main.goto start the server - Open your browser and navigate to
http://localhost:HOST_PORT
API Endpoints
Authentication
POST /login: Login with email and passwordPOST /register: Register a new userGET /logout: Logout
Users
GET /users: Get all usersGET /users/:id: Get a user by IDPUT /users/:id: Update a userDELETE /users/:id: Delete a user
Docker Support
You can build a Docker image by running docker build -t my-api . and then run it with docker run -p 8080:8080 my-api.
Environment Variables
You can set the following environment variables:
DB_HOSTDB_USERDB_PASSWORDDB_NAMEDB_PORTSALTHOST_ADDRESSHOST_PORTLOG_PATH
Logging
The API uses the log package to log errors. You can set the LOG_PATH environment variable to specify the log file path.
Error Handling
The API uses the errors package to handle errors. You can set the ERROR_PATH environment variable to specify the error file path.
Command Documentation
GO Command
Update Golang Project version
go mod edit -go 1.24 go mod tidy
Update all package
go get -u ./... go mod tidy
Docker Command
Enter docker container
docker exec -it api-qobiltu sh
Docker Running Process
docker ps
Rebuild Docker Image
docker-compose down -v docker-compose up --build -d
View Log container
docker logs --tail=50 -f api-qobiltu docker logs postgres-db
Menghapus Resource docker yang tidak dipakai
docker system prune docker system prune -a --volumes