Skip to content
/ serv Public

A server and router implementation with a focus on security, flexibility and ease of use.

License

Notifications You must be signed in to change notification settings

go-pogo/serv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serv

Latest release Build status Go Report Card Documentation

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:

  • Server with sane and safe defaults;
  • Server State retrieval;
  • Router/ServeMux with easy (mass) Route registration;
  • Set custom "not found" http.Handler on ServeMux;
  • support for access logging.

go get github.com/go-pogo/serv
import "github.com/go-pogo/serv"

Examples

Basic server

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())
    }
}

Documentation

Additional detailed documentation is available at pkg.go.dev

Created with

License

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.

About

A server and router implementation with a focus on security, flexibility and ease of use.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 2

  •  
  •  

Languages