forked from ebhomengo/niki
38 lines
716 B
Go
38 lines
716 B
Go
package httpserver
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
config "git.gocasts.ir/ebhomengo/niki/config"
|
|
echo "github.com/labstack/echo/v4"
|
|
middleware "github.com/labstack/echo/v4/middleware"
|
|
)
|
|
|
|
type Server struct {
|
|
config config.Config
|
|
Router *echo.Echo
|
|
}
|
|
|
|
func New(cfg config.Config) Server {
|
|
return Server{
|
|
Router: echo.New(),
|
|
config: cfg,
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|