fiber.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package fiber
  2. import (
  3. cache "git.dmitriygnatenko.ru/dima/go-common/cache/ttl_memory_cache"
  4. "git.dmitriygnatenko.ru/dima/go-common/db"
  5. "github.com/gofiber/fiber/v2"
  6. "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/repositories"
  7. "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/auth"
  8. "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/config"
  9. )
  10. const (
  11. appName = "dmitriygnatenko"
  12. templatesPath = "./../../internal/templates"
  13. staticPath = "../../web"
  14. metricsURI = "/metrics"
  15. )
  16. type ServiceProvider interface {
  17. ConfigService() *config.Service
  18. AuthService() *auth.Service
  19. CacheService() *cache.Cache
  20. TransactionManager() *db.TxManager
  21. ArticleRepository() *repositories.ArticleRepository
  22. TagRepository() *repositories.TagRepository
  23. ArticleTagRepository() *repositories.ArticleTagRepository
  24. UserRepository() *repositories.UserRepository
  25. }
  26. func Init(sp ServiceProvider) (*fiber.App, error) {
  27. fiberApp := fiber.New(getConfig(sp))
  28. initStatic(fiberApp)
  29. initMetrics(fiberApp, sp)
  30. initMiddleware(fiberApp, sp)
  31. initPublicHandlers(fiberApp, sp)
  32. initAdminHandlers(fiberApp, sp)
  33. return fiberApp, nil
  34. }
  35. func getConfig(sp ServiceProvider) fiber.Config {
  36. return fiber.Config{
  37. AppName: appName,
  38. DisableStartupMessage: true,
  39. Views: getViewsEngine(sp),
  40. ErrorHandler: getErrorHandler(),
  41. }
  42. }