2025-10-20 18:23:53 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2025-10-20 22:21:55 +03:00
|
|
|
"context"
|
2025-10-22 21:34:17 +03:00
|
|
|
"github.com/davidbyttow/govips/v2/vips"
|
2025-10-20 22:21:55 +03:00
|
|
|
log "github.com/sirupsen/logrus"
|
2025-10-20 18:23:53 +03:00
|
|
|
"imageStorage/config"
|
|
|
|
|
"imageStorage/internal/app"
|
2025-10-20 22:21:55 +03:00
|
|
|
"imageStorage/internal/convert"
|
2025-10-25 17:41:19 +03:00
|
|
|
"imageStorage/internal/httpDelivery"
|
2025-10-20 22:21:55 +03:00
|
|
|
"imageStorage/internal/mainHandler"
|
2025-10-25 17:41:19 +03:00
|
|
|
"imageStorage/internal/router"
|
|
|
|
|
"imageStorage/internal/utils"
|
2025-10-20 22:21:55 +03:00
|
|
|
"os"
|
|
|
|
|
"os/signal"
|
|
|
|
|
"syscall"
|
2025-10-20 18:23:53 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
2025-10-25 17:41:19 +03:00
|
|
|
c := config.NewConfig()
|
|
|
|
|
//c := config.DevConfig()
|
2025-10-20 18:23:53 +03:00
|
|
|
config.LogSetup(c.App.LogLevel)
|
2025-10-20 22:21:55 +03:00
|
|
|
log.Infof("Log level: %s", c.App.LogLevel)
|
2025-10-20 18:23:53 +03:00
|
|
|
|
2025-10-22 21:34:17 +03:00
|
|
|
vips.Startup(&vips.Config{
|
|
|
|
|
MaxCacheMem: 100 << 20,
|
|
|
|
|
})
|
|
|
|
|
defer vips.Shutdown()
|
|
|
|
|
|
2025-10-20 22:21:55 +03:00
|
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
2025-10-25 17:41:19 +03:00
|
|
|
u := utils.NewHandler(c.App.Domain, c.App.Volume)
|
|
|
|
|
|
|
|
|
|
r := router.SetRouter("debug")
|
|
|
|
|
mainRoute := r.Group("/")
|
|
|
|
|
|
|
|
|
|
delivery := httpDelivery.NewHandler(u)
|
|
|
|
|
delivery.RegisterRoutes(mainRoute)
|
|
|
|
|
|
2025-10-20 22:21:55 +03:00
|
|
|
converter := convert.NewHandler()
|
|
|
|
|
imageServerHandler := mainHandler.NewHandler(mainHandler.Deps{
|
|
|
|
|
Converter: converter,
|
2025-10-25 17:41:19 +03:00
|
|
|
Volume: c.App.Volume,
|
|
|
|
|
Utils: u,
|
2025-10-20 22:21:55 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
a := app.NewApp(app.Deps{
|
|
|
|
|
Config: c,
|
|
|
|
|
GrpcServer: imageServerHandler,
|
2025-10-25 17:41:19 +03:00
|
|
|
HttpServer: r,
|
2025-10-20 22:21:55 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if err := a.Start(ctx); err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
2025-10-20 18:23:53 +03:00
|
|
|
}
|