fiber.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. LanguageRepository() *repositories.LanguageRepository
  26. }
  27. func Init(sp ServiceProvider) (*fiber.App, error) {
  28. fiberApp := fiber.New(getConfig(sp))
  29. initStatic(fiberApp)
  30. initMetrics(fiberApp, sp)
  31. initMiddleware(fiberApp, sp)
  32. initPublicHandlers(fiberApp, sp)
  33. initAdminHandlers(fiberApp, sp)
  34. return fiberApp, nil
  35. }
  36. func getConfig(sp ServiceProvider) fiber.Config {
  37. return fiber.Config{
  38. AppName: appName,
  39. DisableStartupMessage: true,
  40. Views: getViewsEngine(sp),
  41. ErrorHandler: getErrorHandler(),
  42. }
  43. }