go-http-skeleton/web/server.go
Jan Eitzinger f15d6b2163
Initial checkin of templ skeleton
HTML based on Jason Knight HTML template code
2024-08-03 08:51:30 +02:00

37 lines
573 B
Go

package web
import (
"context"
"embed"
"fmt"
"net/http"
"git.clustercockpit.org/moebiusband/go-http-skeleton/internal/util"
"github.com/benbjohnson/hashfs"
)
//go:embed static/*
var staticFS embed.FS
var staticSys = hashfs.NewFS(staticFS)
func RunBlocking(port int) util.CtxErrFunc {
return func(ctx context.Context) error {
r := http.NewServeMux()
setupRoutes(r)
srv := &http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: r,
}
go func() {
<-ctx.Done()
srv.Shutdown(context.Background())
}()
return srv.ListenAndServe()
}
}