mirror of
https://github.com/Theodor-Springmann-Stiftung/lenz-web.git
synced 2026-03-21 05:45:32 +00:00
Started server
This commit is contained in:
11
server/endpoints.go
Normal file
11
server/endpoints.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/Theodor-Springmann-Stiftung/lenz-web/templates"
|
||||
"github.com/labstack/echo/v5"
|
||||
)
|
||||
|
||||
func MapStatic(e *echo.Echo) {
|
||||
// INFO: Static files here:
|
||||
e.StaticFS("/public", templates.PublicFS)
|
||||
}
|
||||
36
server/server.go
Normal file
36
server/server.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/lenz-web/app"
|
||||
"github.com/labstack/echo/v5"
|
||||
)
|
||||
|
||||
// WARNING: this is not thread-safe. You can not write and read from the server at the same time!
|
||||
type Server struct {
|
||||
server *echo.Echo
|
||||
cfg app.Config
|
||||
tmpl *template.Template
|
||||
}
|
||||
|
||||
func NewServer(app *app.App) (*Server, error) {
|
||||
s := &Server{
|
||||
server: echo.New(),
|
||||
cfg: app.Config(),
|
||||
tmpl: app.Templates(),
|
||||
}
|
||||
|
||||
// INFO: Endpoint mapping here:
|
||||
MapStatic(s.server)
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Server) Start() error {
|
||||
addr := s.cfg.Address + ":" + s.cfg.Port
|
||||
if err := s.server.Start(addr); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user