This commit is contained in:
nquidox 2025-10-20 18:23:53 +03:00
commit a72002540d
9 changed files with 133 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.idea

14
cmd/main.go Normal file
View file

@ -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()
}

3
config.env Normal file
View file

@ -0,0 +1,3 @@
GRPC_HOST=
GRPC_PORT=
LOG_LEVEL=Info

21
config/config.go Normal file
View file

@ -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", ""),
},
}
}

24
config/getEnv.go Normal file
View file

@ -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
}

35
config/logging.go Normal file
View file

@ -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)
}

7
go.mod Normal file
View file

@ -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

15
go.sum Normal file
View file

@ -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=

13
internal/app/app.go Normal file
View file

@ -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")
}