1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-14 11:23:02 +02:00
ferret/e2e/server/server.go

39 lines
612 B
Go
Raw Normal View History

2018-10-14 21:38:14 +02:00
package server
import (
"context"
"fmt"
"github.com/labstack/echo"
2018-11-12 21:53:36 +02:00
"path/filepath"
2018-10-14 21:38:14 +02:00
)
type (
Settings struct {
Port uint64
Dir string
}
Server struct {
engine *echo.Echo
settings Settings
}
)
func New(settings Settings) *Server {
e := echo.New()
e.Debug = false
e.HideBanner = true
e.Static("/", settings.Dir)
2018-11-12 21:53:36 +02:00
e.File("/", filepath.Join(settings.Dir, "index.html"))
2018-10-14 21:38:14 +02:00
return &Server{e, settings}
}
func (s *Server) Start() error {
return s.engine.Start(fmt.Sprintf("0.0.0.0:%d", s.settings.Port))
}
func (s *Server) Stop(ctx context.Context) error {
return s.engine.Shutdown(ctx)
}