From 25439eab5b52e6ac4c9608abaf91771c58874434 Mon Sep 17 00:00:00 2001 From: nquidox Date: Wed, 18 Feb 2026 15:53:29 +0300 Subject: [PATCH] initial --- .gitignore | 1 + README.md | 5 +++++ config.env | 13 +++++++++++ config/config.go | 41 +++++++++++++++++++++++++++++++++++ config/helper.go | 10 +++++++++ config/logging.go | 48 +++++++++++++++++++++++++++++++++++++++++ go.mod | 7 ++++++ go.sum | 14 ++++++++++++ internal/app/handler.go | 24 +++++++++++++++++++++ proto/task.proto | 22 +++++++++++++++++++ 10 files changed, 185 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 config.env create mode 100644 config/config.go create mode 100644 config/helper.go create mode 100644 config/logging.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/app/handler.go create mode 100644 proto/task.proto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/README.md b/README.md new file mode 100644 index 0000000..51b103a --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Task Processor V3 + +1. Requests tasks from source by gRPC +2. Sorts and sends tasks to certain handlers +3. Recieves tasks results and sends it back to source \ No newline at end of file diff --git a/config.env b/config.env new file mode 100644 index 0000000..7f3743d --- /dev/null +++ b/config.env @@ -0,0 +1,13 @@ +#[APP] +APP_MODE=dev +APP_LOG_LVL=info + +#[HTTP] +HOST=0.0.0.0 +PORT=41082 + +#[TASKS SOURCE(GRPC)] +HOST= +PORT= + +#[RABBIT] diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..a60585e --- /dev/null +++ b/config/config.go @@ -0,0 +1,41 @@ +package config + +type Config struct { + App App + Http Http + TasksSource TasksSource +} + +type App struct { + Mode string + LogLvl string +} + +type Http struct { + Host string + Port string +} + +type TasksSource struct { + Host string + Port string +} + +func NewConfig() Config { + return Config{ + App: App{ + Mode: getEnv("APP_MODE", "dev"), + LogLvl: getEnv("APP_LOG_LVL", "debug"), + }, + + Http: Http{ + Host: getEnv("HOST", "0.0.0.0"), + Port: getEnv("PORT", "41082"), + }, + + TasksSource: TasksSource{ + Host: getEnv("TASK_API_HOST", ""), + Port: getEnv("TASK_API_PORT", ""), + }, + } +} diff --git a/config/helper.go b/config/helper.go new file mode 100644 index 0000000..ea28dbc --- /dev/null +++ b/config/helper.go @@ -0,0 +1,10 @@ +package config + +import "os" + +func getEnv(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +} diff --git a/config/logging.go b/config/logging.go new file mode 100644 index 0000000..29bbe39 --- /dev/null +++ b/config/logging.go @@ -0,0 +1,48 @@ +package config + +import ( + "fmt" + "github.com/sirupsen/logrus" + "os" + "path/filepath" + "strings" +) + +func LogSetup(mode, lvl string) { + l, err := logrus.ParseLevel(lvl) + if err != nil { + l = logrus.InfoLevel + } + + logrus.SetLevel(l) + + switch mode { + case "release": + case "dev": + { + logrus.SetReportCaller(true) + logrus.SetFormatter(&CustomFormatter{}) + logrus.SetOutput(os.Stdout) + } + } +} + +type CustomFormatter struct{} + +func (f *CustomFormatter) Format(entry *logrus.Entry) ([]byte, error) { + timestamp := entry.Time.Format("2006-01-02 15:04:05") + level := strings.ToUpper(entry.Level.String()) + msg := entry.Message + + file := "" + line := 0 + if entry.Caller != nil { + file = filepath.Base(entry.Caller.File) + line = entry.Caller.Line + } + + logLine := fmt.Sprintf("[%s][%s][%s:%d] %s\n", + level, timestamp, file, line, msg) + + return []byte(logLine), nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b0e8b95 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module task-processor + +go 1.25.6 + +require github.com/sirupsen/logrus v1.9.4 + +require golang.org/x/sys v0.41.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..82d5ca4 --- /dev/null +++ b/go.sum @@ -0,0 +1,14 @@ +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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= +github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= +golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/app/handler.go b/internal/app/handler.go new file mode 100644 index 0000000..b2ced79 --- /dev/null +++ b/internal/app/handler.go @@ -0,0 +1,24 @@ +package app + +import ( + log "github.com/sirupsen/logrus" + "task-processor/config" +) + +type App struct { + config config.Config +} + +type Deps struct { + Config config.Config +} + +func NewApp(deps Deps) *App { + return &App{ + config: deps.Config, + } +} + +func (app *App) Run() { + log.Info("App started") +} diff --git a/proto/task.proto b/proto/task.proto new file mode 100644 index 0000000..d3f8ea4 --- /dev/null +++ b/proto/task.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +import "google/protobuf/empty.proto"; + +package taskProcessor; +option go_package = "./taskProcessor"; + + +message Task{ + string merch_uuid = 1; + map origins = 2; +} + +message Result{ + string merch_uuid = 1; + string origin_name = 2; + int32 price = 3; +} + +service TaskProcessor { + rpc RequestTasks(google.protobuf.Empty) returns (stream Task); + rpc SendResults(stream Result) returns (google.protobuf.Empty); +}