Skip to content

fivethirty/middest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

middest

test status

Go middleware collection created with hypermedia applications in mind.

Modules

  • ctxlog: Structured request logging
  • recoverer: Panic recovery with
  • requestsize: Request body size limiting
  • contenttype: Content type filtering
  • errs: Error handling utilities
  • handlers: Helper for composing middleware

Usage

package main

import (
    "net/http"
    "github.com/fivethirty/middest/handlers"
    "github.com/fivethirty/middest/ctxlog"
    "github.com/fivethirty/middest/recoverer"
)

func main() {
    logger := ctxlog.DefaultLogger
    
    middlewares := []func(http.Handler) http.Handler{
        recoverer.New(logger),
        ctxlog.New(logger),
    }
    
    handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        w.WriteHeader(http.StatusOK)
        w.Write([]byte("Hello, World!"))
    })
    
    http.HandleFunc("/", handlers.WithMiddleware(middlewares, handler))
    http.ListenAndServe(":8080", nil)
}

About

middleware for go servers

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors