Skip to content

maheshwar-mr/statussnatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Status Snatcher

Package to fetch the status code from net/http's ResponseWriter

Install

go install github.com/maheshwar-mr/statussnatcher

Usage

Sample setup for a logging middleware.

package middleware

import (
    "log"
    "net/http"
    "time"

    "github.com/maheshwar-mr/statussnatcher"
)

func Logger(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
        start := time.Now()
        ss := statussnatcher.New(w) //Create a new instance
        next.ServeHTTP(ss, r) //Calling ServeHTTP() of the handler
        log.Println(ss.StatusCode, r.Method, r.URL.Path, time.Since(start))
    })
}

About

Go package to fetch the status code of an HTTP ResponseWriter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages