Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .env

This file was deleted.

8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
HTTP_HOST=localhost
HTTP_PORT=8080
PG_DSN=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
HTTP_READ_TIMEOUT=5
HTTP_WRITE_TIMEOUT=10
HTTP_IDLE_TIMEOUT=30
JWT_SECRET_KEY=my_key
JWT_EXPIRES_IN=24
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ compose-up: ## Start services with docker-compose
compose-down: ## Stop services with docker-compose
docker-compose down

.PHONY: compose-down-v
compose-down-v: ## Stop services with docker-compose and remove volumes
docker-compose down -v

.PHONY: compose-logs
compose-logs: ## View logs of services
docker-compose logs -f
docker-compose logs -f

##@ All

.PHONY: up
up: compose-up migration-up
94 changes: 0 additions & 94 deletions app/service_provider.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"ignisgo/app"
"ignisgo/internal/app"
"log"
)

Expand Down
68 changes: 62 additions & 6 deletions config/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,53 @@ import (
"fmt"
"net"
"os"
"strconv"
"time"
)

const (
httpHost = "HTTP_HOST"
httpPort = "HTTP_PORT"
httpHost = "HTTP_HOST"
httpPort = "HTTP_PORT"
httpReadTimeout = "HTTP_READ_TIMEOUT"
httpWriteTimeout = "HTTP_WRITE_TIMEOUT"
httpIdleTimeout = "HTTP_IDLE_TIMEOUT"
)

type HTTPConfig interface {
Address() string
ReadTimeout() time.Duration
WriteTimeout() time.Duration
IdleTimeout() time.Duration
}

type httpConfig struct {
host string
port string
host string
port string
readTimeout time.Duration
writeTimeout time.Duration
idleTimeout time.Duration
}

// Address implements HTTPConfig.
func (cfg *httpConfig) Address() string {
return net.JoinHostPort(cfg.host, cfg.port)
}

// ReadTimeout implements HTTPConfig.
func (cfg *httpConfig) ReadTimeout() time.Duration {
return cfg.readTimeout
}

// WriteTimeout implements HTTPConfig.
func (cfg *httpConfig) WriteTimeout() time.Duration {
return cfg.writeTimeout
}

// IdleTimeout implements HTTPConfig.
func (cfg *httpConfig) IdleTimeout() time.Duration {
return cfg.idleTimeout
}

func NewHTTPConfig() (HTTPConfig, error) {
host := os.Getenv(httpHost)
if len(host) == 0 {
Expand All @@ -36,8 +62,38 @@ func NewHTTPConfig() (HTTPConfig, error) {
return nil, fmt.Errorf("env %v not found", httpPort)
}

readTimeout := os.Getenv(httpReadTimeout)
if len(readTimeout) == 0 {
return nil, fmt.Errorf("env %v not found", httpReadTimeout)
}
readTimeoutInt, err := strconv.Atoi(readTimeout)
if err != nil {
return nil, fmt.Errorf("env %v not found", httpReadTimeout)
}

writeTimeout := os.Getenv(httpWriteTimeout)
if len(writeTimeout) == 0 {
return nil, fmt.Errorf("env %v not found", httpWriteTimeout)
}
writeTimeoutInt, err := strconv.Atoi(writeTimeout)
if err != nil {
return nil, fmt.Errorf("env %v not found", httpWriteTimeout)
}

idleTimeout := os.Getenv(httpIdleTimeout)
if len(idleTimeout) == 0 {
return nil, fmt.Errorf("env %v not found", httpIdleTimeout)
}
idleTimeoutInt, err := strconv.Atoi(idleTimeout)
if err != nil {
return nil, fmt.Errorf("env %v not found", httpIdleTimeout)
}

return &httpConfig{
host: host,
port: port,
host: host,
port: port,
readTimeout: time.Duration(readTimeoutInt),
writeTimeout: time.Duration(writeTimeoutInt),
idleTimeout: time.Duration(idleTimeoutInt),
}, nil
}
52 changes: 52 additions & 0 deletions config/token_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package config

import (
"fmt"
"os"
"strconv"
"time"
)

const (
secretKey = "JWT_SECRET_KEY"
expiresIn = "JWT_EXPIRES_IN"
)

type TokenProviderConfig interface {
SecretKey() string
ExpiresIn() time.Duration
}

type tokenProviderConfig struct {
secretKey string
expiresIn time.Duration
}

func NewTokenProviderConfig() (TokenProviderConfig, error) {
secretKey := os.Getenv(secretKey)
if len(secretKey) == 0 {
return nil, fmt.Errorf("env %v not found", secretKey)
}

expiresIn := os.Getenv(expiresIn)
if len(expiresIn) == 0 {
return nil, fmt.Errorf("env %v not found", expiresIn)
}
expiresInInt, err := strconv.Atoi(expiresIn)
if err != nil {
return nil, fmt.Errorf("env %v not found", expiresIn)
}

return &tokenProviderConfig{
secretKey: secretKey,
expiresIn: time.Duration(expiresInInt),
}, nil
}

func (c *tokenProviderConfig) SecretKey() string {
return c.secretKey
}

func (c *tokenProviderConfig) ExpiresIn() time.Duration {
return c.expiresIn
}
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ module ignisgo
go 1.25.4

require (
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/google/uuid v1.6.0
github.com/jackc/pgx/v5 v5.8.0
github.com/joho/godotenv v1.5.1
golang.org/x/crypto v0.48.0
)

require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/text v0.29.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/text v0.34.0 // indirect
)
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
Expand All @@ -18,10 +22,12 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
7 changes: 6 additions & 1 deletion internal/adapter/db/queries/query.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- name: CreateUser :one
INSERT INTO users (
name, email
email, password
) VALUES (
$1, $2
)
Expand All @@ -10,6 +10,10 @@ RETURNING *;
SELECT * FROM users
WHERE id = $1 LIMIT 1;

-- name: GetUserByEmail :one
SELECT * FROM users
WHERE email = $1 LIMIT 1;

-- name: ListUsers :many
SELECT * FROM users
ORDER BY name;
Expand All @@ -18,6 +22,7 @@ ORDER BY name;
UPDATE users
set name = $2,
email = $3,
password = $4,
updated_at = NOW()
WHERE id = $1;

Expand Down
28 changes: 0 additions & 28 deletions internal/adapter/db/repository.go

This file was deleted.

Loading