From a72002540d5e27cf7ec29bf04a624fead41967d0 Mon Sep 17 00:00:00 2001 From: nquidox Date: Mon, 20 Oct 2025 18:23:53 +0300 Subject: [PATCH] initial --- .gitignore | 1 + cmd/main.go | 14 ++++++++++++++ config.env | 3 +++ config/config.go | 21 +++++++++++++++++++++ config/getEnv.go | 24 ++++++++++++++++++++++++ config/logging.go | 35 +++++++++++++++++++++++++++++++++++ go.mod | 7 +++++++ go.sum | 15 +++++++++++++++ internal/app/app.go | 13 +++++++++++++ 9 files changed, 133 insertions(+) create mode 100644 .gitignore create mode 100644 cmd/main.go create mode 100644 config.env create mode 100644 config/config.go create mode 100644 config/getEnv.go create mode 100644 config/logging.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/app/app.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..3fec87f --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,14 @@ +package main + +import ( + "imageStorage/config" + "imageStorage/internal/app" +) + +func main() { + c := config.NewConfig() + config.LogSetup(c.App.LogLevel) + + a := app.NewApp() + a.Start() +} diff --git a/config.env b/config.env new file mode 100644 index 0000000..6babd58 --- /dev/null +++ b/config.env @@ -0,0 +1,3 @@ +GRPC_HOST= +GRPC_PORT= +LOG_LEVEL=Info \ No newline at end of file diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..058eaff --- /dev/null +++ b/config/config.go @@ -0,0 +1,21 @@ +package config + +type Config struct { + App AppConfig +} + +type AppConfig struct { + GrpcHost string + GrpcPort string + LogLevel string +} + +func NewConfig() *Config { + return &Config{ + App: AppConfig{ + GrpcHost: getEnv("GRPC_HOST", ""), + GrpcPort: getEnv("GRPC_PORT", ""), + LogLevel: getEnv("LOG_LEVEL", ""), + }, + } +} diff --git a/config/getEnv.go b/config/getEnv.go new file mode 100644 index 0000000..c40f185 --- /dev/null +++ b/config/getEnv.go @@ -0,0 +1,24 @@ +package config + +import ( + "os" + "strconv" +) + +func getEnv(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +} + +func getEnvInt(key string, fallback int) int { + if value, ok := os.LookupEnv(key); ok { + num, err := strconv.Atoi(value) + if err != nil { + return fallback + } + return num + } + return fallback +} diff --git a/config/logging.go b/config/logging.go new file mode 100644 index 0000000..5c8809c --- /dev/null +++ b/config/logging.go @@ -0,0 +1,35 @@ +package config + +import ( + "fmt" + log "github.com/sirupsen/logrus" + "os" + "path" + "runtime" +) + +func LogSetup(lvl string) { + l, err := log.ParseLevel(lvl) + if err != nil { + log.SetLevel(log.DebugLevel) + } + + log.SetFormatter( + &log.TextFormatter{ + FullTimestamp: true, + CallerPrettyfier: func(f *runtime.Frame) (string, string) { + filename := path.Base(f.File) + return fmt.Sprintf("%s()", f.Function), fmt.Sprintf(" %s:%d", filename, f.Line) + }, + }, + ) + + if l == log.DebugLevel { + log.SetLevel(l) + log.SetReportCaller(true) + } else { + log.SetLevel(l) + } + + log.SetOutput(os.Stdout) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..730e9c1 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module imageStorage + +go 1.25.3 + +require github.com/sirupsen/logrus v1.9.3 + +require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..21f9bfb --- /dev/null +++ b/go.sum @@ -0,0 +1,15 @@ +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/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.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/app/app.go b/internal/app/app.go new file mode 100644 index 0000000..aa6c70d --- /dev/null +++ b/internal/app/app.go @@ -0,0 +1,13 @@ +package app + +import log "github.com/sirupsen/logrus" + +type App struct{} + +func NewApp() *App { + return &App{} +} + +func (app *App) Start() { + log.Info("Application started") +}