fiber.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/repository"
  7. "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/service/auth"
  8. "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/service/config"
  9. )
  10. const (
  11. appName = "dmitriygnatenko"
  12. metricsURI = "/metrics"
  13. )
  14. type ServiceProvider interface {
  15. ConfigService() *config.Service
  16. AuthService() *auth.Service
  17. CacheService() *cache.Cache
  18. TransactionManager() *db.TxManager
  19. ArticleRepository() *repository.ArticleRepository
  20. TagRepository() *repository.TagRepository
  21. ArticleTagRepository() *repository.ArticleTagRepository
  22. UserRepository() *repository.UserRepository
  23. LanguageRepository() *repository.LanguageRepository
  24. }
  25. func Init(sp ServiceProvider) (*fiber.App, error) {
  26. fiberApp := fiber.New(getConfig(sp))
  27. initStatic(fiberApp, sp)
  28. initMetrics(fiberApp, sp)
  29. initMiddleware(fiberApp, sp)
  30. initPublicHandlers(fiberApp, sp)
  31. initAdminHandlers(fiberApp, sp)
  32. return fiberApp, nil
  33. }
  34. func getConfig(sp ServiceProvider) fiber.Config {
  35. return fiber.Config{
  36. AppName: appName,
  37. DisableStartupMessage: true,
  38. Views: getViewsEngine(sp),
  39. ErrorHandler: getErrorHandler(),
  40. }
  41. }