craban/server/web/web.go
Miguel de la Cruz ca0bfa2398 Rename to craban
2021-09-12 18:57:42 +02:00

39 lines
626 B
Go

package web
import (
"fmt"
"net/http"
)
type WebServer struct {
*http.Server
}
func NewWebServer(port int) (*WebServer, error) {
mux := http.NewServeMux()
// ToDo: configure routes
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello craban!!")
})
s := &WebServer{
&http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: mux,
},
}
return s, nil
}
func (w *WebServer) Start() error {
if err := w.Server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
return err
}
return nil
}
func (w *WebServer) Close() error {
return w.Server.Close()
}