initial
This commit is contained in:
commit
25439eab5b
10 changed files with 185 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
.idea
|
||||
5
README.md
Normal file
5
README.md
Normal file
|
|
@ -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
|
||||
13
config.env
Normal file
13
config.env
Normal file
|
|
@ -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]
|
||||
41
config/config.go
Normal file
41
config/config.go
Normal file
|
|
@ -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", ""),
|
||||
},
|
||||
}
|
||||
}
|
||||
10
config/helper.go
Normal file
10
config/helper.go
Normal file
|
|
@ -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
|
||||
}
|
||||
48
config/logging.go
Normal file
48
config/logging.go
Normal file
|
|
@ -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
|
||||
}
|
||||
7
go.mod
Normal file
7
go.mod
Normal file
|
|
@ -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
|
||||
14
go.sum
Normal file
14
go.sum
Normal file
|
|
@ -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=
|
||||
24
internal/app/handler.go
Normal file
24
internal/app/handler.go
Normal file
|
|
@ -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")
|
||||
}
|
||||
22
proto/task.proto
Normal file
22
proto/task.proto
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
syntax = "proto3";
|
||||
import "google/protobuf/empty.proto";
|
||||
|
||||
package taskProcessor;
|
||||
option go_package = "./taskProcessor";
|
||||
|
||||
|
||||
message Task{
|
||||
string merch_uuid = 1;
|
||||
map<string, string> 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue