Package serv provides a server and router implementation based on the http
package, with a focus on security, flexibility and ease of use.
Included features:
Serverwith sane and safe defaults;ServerStateretrieval;Router/ServeMuxwith easy (mass)Routeregistration;- Set custom "not found"
http.HandleronServeMux; - support for access logging.
go get github.com/go-pogo/servimport "github.com/go-pogo/serv"package main
import (
"context"
"log"
"github.com/go-pogo/errors"
"github.com/go-pogo/serv"
)
func main() {
mux := serv.NewServeMux()
srv, err := serv.New(serv.Port(8080), mux, serv.WithDefaultLogger())
if err != nil {
log.Fatalln("Unable to create server:", err.Error())
}
ctx, stopFn := context.WithCancel(context.Background())
go func() {
defer stopFn()
if err := srv.Run(); err != nil {
log.Println("Server error:", err.Error())
}
}()
<-ctx.Done()
if err = srv.Shutdown(context.Background()); err != nil {
log.Println("Error during shutdown:", err.Error())
}
}Additional detailed documentation is available at pkg.go.dev
Copyright © 2021-2025 Roel Schut. All rights reserved.
This project is governed by a BSD-style license that can be found in the LICENSE file.