lipchyk / httpbasicauth

Http Basic Auth middleware for Golang/Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Http Basic Auth middleware for Golang/Go

License:MIT License


Languages

Language:Go 98.3%Language:Makefile 1.7%