From 6be1619d66c45aaf52f068cee19ee2c21df65e7b Mon Sep 17 00:00:00 2001 From: anxi0uz Date: Tue, 3 Mar 2026 18:25:55 +0500 Subject: [PATCH] some shit --- configs/config.toml | 24 +++++++++++++++++++++++ configs/oapi-cfg.yaml | 5 +++++ internal/api/api.swagger.yaml | 5 +++++ internal/database/postgres.go | 22 +++++++++++++++++++-- internal/database/redis.go | 3 +-- migrations/20260303130358_init.sql | 4 ++-- migrations/20260303130413_create_user.sql | 15 ++++++++++++-- 7 files changed, 70 insertions(+), 8 deletions(-) diff --git a/configs/config.toml b/configs/config.toml index e69de29..6414f77 100644 --- a/configs/config.toml +++ b/configs/config.toml @@ -0,0 +1,24 @@ +[logiflow] +logLevel = 1 + +[database] +host = "postgres" +port = 5432 +sslmode = "disable" + +[server] +host = "0.0.0.0" +port = 3001 +readTimeout = "10s" +writeTimeout = "30s" +idleTimeout = "60s" + +[redis] +addr = "redis:6379" +db = 0 +refreshTokenTTL = "168h" +accessTokenTTL = "24h" + +[jwt] +issuer = "logiflow-server" +audience = "logiflow-client" diff --git a/configs/oapi-cfg.yaml b/configs/oapi-cfg.yaml index e69de29..2e52ad2 100644 --- a/configs/oapi-cfg.yaml +++ b/configs/oapi-cfg.yaml @@ -0,0 +1,5 @@ +package: api +generate: + chi-server: true + models: true +output: internal/api/gen.go diff --git a/internal/api/api.swagger.yaml b/internal/api/api.swagger.yaml index e69de29..24b3496 100644 --- a/internal/api/api.swagger.yaml +++ b/internal/api/api.swagger.yaml @@ -0,0 +1,5 @@ +openapi: 3.0.3 +info: + title: logiflow + description: API для информационной системы для логистической компании + version: 1.0.0 diff --git a/internal/database/postgres.go b/internal/database/postgres.go index 488fcd4..5b17535 100644 --- a/internal/database/postgres.go +++ b/internal/database/postgres.go @@ -1,5 +1,23 @@ package database -import "github.com/jackc/pgx/v5/pgxpool" +import ( + "context" + "log/slog" -func NewConnectionPool(connectionString string) (*pgxpool.Pool, error) + "github.com/jackc/pgx/v5/pgxpool" +) + +func NewConnectionPool(ctx context.Context, connectionString string) (*pgxpool.Pool, error) { + pool, err := pgxpool.New(ctx, connectionString) + if err != nil { + slog.ErrorContext(ctx, "Cant create pool of connection", slog.String("Error", err.Error())) + return nil, err + } + + if err := pool.Ping(ctx); err != nil { + slog.ErrorContext(ctx, "Cant ping connection", slog.String("Error", err.Error())) + return nil, err + } + + return pool, nil +} diff --git a/internal/database/redis.go b/internal/database/redis.go index 26abf91..09c9082 100644 --- a/internal/database/redis.go +++ b/internal/database/redis.go @@ -5,7 +5,6 @@ import ( "log/slog" "github.com/anxi0uz/logiflow/internal/config" - "github.com/redis/go-redis" "github.com/redis/go-redis/v9" ) @@ -16,7 +15,7 @@ func NewRedisConnection(ctx context.Context, cfg *config.Config) (*redis.Client, DB: cfg.Redis.DB, }) - _, err := rdb.Ping().Result() + _, err := rdb.Ping(ctx).Result() if err != nil { slog.ErrorContext(ctx, "Cant ping redis", slog.String("Error", err.Error())) return nil, err diff --git a/migrations/20260303130358_init.sql b/migrations/20260303130358_init.sql index b9c449e..c902c87 100644 --- a/migrations/20260303130358_init.sql +++ b/migrations/20260303130358_init.sql @@ -1,9 +1,9 @@ -- +goose Up -- +goose StatementBegin -SELECT 'up SQL query'; +CREATE EXTENSION IF NOT EXISTS pg_tgrm; -- +goose StatementEnd -- +goose Down -- +goose StatementBegin -SELECT 'down SQL query'; +DROP EXTENSION IF EXISTS pg_tgrm; -- +goose StatementEnd diff --git a/migrations/20260303130413_create_user.sql b/migrations/20260303130413_create_user.sql index b9c449e..39fb695 100644 --- a/migrations/20260303130413_create_user.sql +++ b/migrations/20260303130413_create_user.sql @@ -1,9 +1,20 @@ -- +goose Up -- +goose StatementBegin -SELECT 'up SQL query'; +CREATE TABLE IF NOT EXISTS users ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + email VARCHAR(255) UNIQUE NOT NULL, + slug VARCHAR(120) UNIQUE NOT NULL, + password_hash VARCHAR(255) NOT NULL, + full_name VARCHAR(150), + avatar_url VARCHAR(512), + role VARCHAR(50) DEFAULT 'student', + created_at TIMESTAMPTZ DEFAULT NOW(), + updated_at TIMESTAMPTZ, + last_login_at TIMESTAMPTZ +); -- +goose StatementEnd -- +goose Down -- +goose StatementBegin -SELECT 'down SQL query'; +DROP TABLE IF EXISTS users; -- +goose StatementEnd