added cmd and deploy layer

This commit is contained in:
mzfarshad 2026-04-14 16:29:03 +03:30
parent 50d7c2a2dc
commit 2037e58a1d
10 changed files with 72 additions and 5 deletions

View File

@ -0,0 +1 @@
package command

View File

@ -0,0 +1 @@
package command

View File

@ -0,0 +1 @@
package command

View File

@ -0,0 +1,44 @@
package main
import (
"fmt"
"git.gocasts.ir/ebhomengo/niki/adapter/redis"
"git.gocasts.ir/ebhomengo/niki/logger"
"git.gocasts.ir/ebhomengo/niki/pkg/httpserver"
"git.gocasts.ir/ebhomengo/niki/shoppingbasketapp"
"git.gocasts.ir/ebhomengo/niki/shoppingbasketapp/repository"
"time"
)
func main() {
cfg := shoppingbasketapp.Config{
Redis: redis.Config{
Host: "localhost",
Port: 6379,
Password: "",
DB: 0,
},
Repo: repository.Config{
KartKeyPrefix: "shopping-basket-cart:",
TTL: 3600 * time.Second,
},
HTTPServer: httpserver.Config{
Host: "localhost",
Port: 8080,
ShutdownTimeout: 10 * time.Second,
},
Logger: logger.Config{
FilePath: "logs/shoppingbasket/service.log",
UseLocalTime: true,
FileMaxSizeInMB: 10,
FileMaxAgeInDays: 30,
},
}
app, err := shoppingbasketapp.Setup(cfg)
if err != nil {
panic(fmt.Sprintf("error initialize to setup app: %s", err.Error()))
}
app.Start()
}

View File

@ -0,0 +1,20 @@
redis:
host: "localhost"
port: 6379
password: ""
db: 0
repo:
kart_key_prefix: "shopping-basket-cart:"
ttl: 3600s
http_server:
host: "localhost"
port: 8080
shutdown_context_timeout: 10s
logger:
file_path: "logs/shoppingbasket/service.log"
use_local_time: true
file_max_size_in_mb: 10
file_max_age_in_days: 30

View File

@ -16,10 +16,10 @@ const (
) )
type Config struct { type Config struct {
FilePath string FilePath string `koanf:"file_path"`
UseLocalTime bool UseLocalTime bool `koanf:"use_local_time"`
FileMaxSizeInMB int FileMaxSizeInMB int `koanf:"file_max_size_in_mb"`
FileMaxAgeInDays int FileMaxAgeInDays int `koanf:"file_max_age_in_days"`
} }
var l *slog.Logger var l *slog.Logger

View File

@ -25,7 +25,7 @@ type Application struct {
Logger *slog.Logger Logger *slog.Logger
} }
func (app Application) Setup(cfg Config) (Application, error) { func Setup(cfg Config) (Application, error) {
l := logger.New(cfg.Logger, &slog.HandlerOptions{ l := logger.New(cfg.Logger, &slog.HandlerOptions{
Level: slog.LevelDebug, Level: slog.LevelDebug,
}) })