File size: 2,228 Bytes
7e1ff30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a2399ed
 
7e1ff30
 
 
a2399ed
7e1ff30
a2399ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76a3612
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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