feat: add custom jwt secret
Docker Build and Push / Build and Push Docker Image (push) Successful in 17m11s

This commit is contained in:
2026-02-26 10:35:54 +07:00
parent 8d87bdc6d4
commit 8ae0c2ef8e
3 changed files with 15 additions and 7 deletions
+8 -6
View File
@@ -44,9 +44,10 @@ Contoh:
```env
DATABASE_URL=postgresql://postgres:password@localhost:5432/ristek?sslmode=disable
PORT=8080
JWT_SECRET=your_secret_key
```
> **Catatan:** Variabel `ADDRESS` bersifat opsional (default: `0.0.0.0`).
> **Catatan:** Variabel `ADDRESS` dan `JWT_SECRET` bersifat opsional.
### 4. Install Dependencies
@@ -78,8 +79,9 @@ http://localhost:8080/swagger/index.html
## Environment Variables
| Variable | Wajib | Default | Keterangan |
|----------------|-------|-------------|---------------------------------------|
| `DATABASE_URL` | ✅ | — | PostgreSQL connection string |
| `PORT` | ❌ | `8080` | Port HTTP server |
| `ADDRESS` | ❌ | `0.0.0.0` | Bind address HTTP server |
| Variable | Wajib | Default | Keterangan |
|----------------|-------|-----------|---------------------------------------|
| `DATABASE_URL` | ✅ | — | PostgreSQL connection string |
| `PORT` | ❌ | `8080` | Port HTTP server |
| `ADDRESS` | ❌ | `0.0.0.0` | Bind address HTTP server |
| `JWT_SECRET` | ❌ | `yomama` | Secret key untuk signing JWT token |
+6
View File
@@ -11,11 +11,13 @@ type Config interface {
Addr() string
Port() string
DatabaseURL() string
JwtSecret() string
}
type config struct {
addr string
port string
databaseURL string
jwtSecret string
}
func (c *config) Addr() string {
@@ -30,10 +32,13 @@ func (c *config) DatabaseURL() string {
return c.databaseURL
}
func (c *config) JwtSecret() string { return c.jwtSecret }
func parse() (*config, error) {
domain := getenv("ADDRESS", "0.0.0.0")
sshPort := getenv("PORT", "8080")
databaseURL := getenv("DATABASE_URL", "")
jwtSecret := getenv("JWT_SECRET", "yomama")
if databaseURL == "" {
return nil, fmt.Errorf("DATABASE_URL environment variable not set")
@@ -43,6 +48,7 @@ func parse() (*config, error) {
addr: domain,
port: sshPort,
databaseURL: databaseURL,
jwtSecret: jwtSecret,
}, nil
}
+1 -1
View File
@@ -73,7 +73,7 @@ func main() {
return
}
j := jwt.New("yomama")
j := jwt.New(conf.JwtSecret())
go func() {
s := server.New(conf.Addr(), conf.Port(), repo, j)
err = s.Start()