forked from ebhomengo/niki
1
0
Fork 0
niki/delivery/http_server/server.go

38 lines
686 B
Go
Raw Normal View History

2023-12-16 07:20:01 +00:00
package httpserver
import (
"fmt"
"git.gocasts.ir/ebhomengo/niki/config"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
2023-12-16 07:20:01 +00:00
type Server struct {
config config.Config
Router *echo.Echo
2023-12-16 07:20:01 +00:00
}
func New(cfg Config) Server {
2023-12-16 07:20:01 +00:00
return Server{
Router: echo.New(),
2024-01-01 07:22:14 +00:00
config: cfg,
2023-12-16 07:20:01 +00:00
}
}
func (s Server) Serve() {
s.Router.Use(middleware.RequestID())
s.Router.Use(middleware.Recover())
// Routes
s.Router.GET("/health-check", s.healthCheck)
// Start server
address := fmt.Sprintf(":%d", s.config.HTTPServer.Port)
fmt.Printf("start echo server on %s\n", address)
if err := s.Router.Start(address); err != nil {
fmt.Println("router start error", err)
}
2023-12-20 15:39:25 +00:00
}