api-qobiltu-dev / space /README.md
lifedebugger's picture
Deploy files from GitHub repository
704aee6
# Golang API Boilerplate
This is a boilerplate for a RESTful API written in Golang.
## Features
- [x] JWT Authentication
- [x] PostgreSQL Database
- [x] GORM ORM
- [x] Gin Framework
- [x] Docker Support
- [x] Environment Variables
- [x] Logging
- [x] Error Handling
## Getting Started
1. Clone the repository
2. Run `go get` to download the dependencies
3. Create a file named `.env` and add the following variables:
* `DB_HOST`
* `DB_USER`
* `DB_PASSWORD`
* `DB_NAME`
* `DB_PORT`
* `SALT`
* `HOST_ADDRESS`
* `HOST_PORT`
* `LOG_PATH`
4. Run `go run main.go` to start the server
5. Open your browser and navigate to `http://localhost:HOST_PORT`
## API Endpoints
### Authentication
- `POST /login`: Login with email and password
- `POST /register`: Register a new user
- `GET /logout`: Logout
### Users
- `GET /users`: Get all users
- `GET /users/:id`: Get a user by ID
- `PUT /users/:id`: Update a user
- `DELETE /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_HOST`
- `DB_USER`
- `DB_PASSWORD`
- `DB_NAME`
- `DB_PORT`
- `SALT`
- `HOST_ADDRESS`
- `HOST_PORT`
- `LOG_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