diff options
author | xengineering <me@xengineering.eu> | 2024-10-13 20:01:27 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-10-13 20:01:27 +0200 |
commit | 4b1bddd92318e9a1d102b3e06c7925ba32422510 (patch) | |
tree | 9435820e89cd6db5374a58f7b634e27abe7bc61d | |
parent | 473052ed8f2c83052ed5b47a7f4cec68ac2621a6 (diff) | |
download | ceres-4b1bddd92318e9a1d102b3e06c7925ba32422510.tar ceres-4b1bddd92318e9a1d102b3e06c7925ba32422510.tar.zst ceres-4b1bddd92318e9a1d102b3e06c7925ba32422510.zip |
Simplify Server type
It is not required to create a struct definition with only one member.
The new solution is more elegant.
-rw-r--r-- | server.go | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -13,14 +13,12 @@ import ( "github.com/gorilla/mux" ) -type Server struct { - backend *http.Server -} +type Server http.Server //go:embed view/static/simple.css/simple.css view/static/ceres.js var static embed.FS -func NewServer(addr string, db *model.DB) Server { +func NewServer(addr string, db *model.DB) *Server { var r *mux.Router = mux.NewRouter() r.PathPrefix("/static/"). @@ -49,15 +47,15 @@ func NewServer(addr string, db *model.DB) Server { log.Printf("Configured server to listen on http://%s\n", srv.Addr) - return Server{backend: &srv} + return (*Server)(&srv) } -func (s Server) Start() { - s.backend.ListenAndServe() +func (s *Server) Start() { + (*http.Server)(s).ListenAndServe() } -func (s Server) Stop() { - err := s.backend.Shutdown(context.Background()) +func (s *Server) Stop() { + err := (*http.Server)(s).Shutdown(context.Background()) if err != nil { log.Printf("Failed to shutdown HTTP server: %v\n", err) } else { |