Skip to content

lipchyk/httpbasicauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

httpbasicauth

CircleCI codecov

An HTTP Basic Auth middleware for Go

Usage

import (
    "net/http"
    "github.com/yspro/httpbasicauth"
)

// credentials
creds := httpbasicauth.SimpleCredentialMap{"u$eR": "$ecret"}
middleware := httpbasicauth.Handle(creds, "Restricted Zone")

yourhandler := http.HandlerFunc(
    func(w http.ResponseWriter, r *http.Request) {
        io.WriteString(w, "Hello World")
    },
)

http.Handle("/secret", middleware(yourhandler))
err := http.ListenAndServe(":8080", nil)
if err != nil {
    panic(err)
}