package
0.0.0-20240827064526-5863c7c96d8a
Repository: https://github.com/cloudlena/adapters.git
Documentation: pkg.go.dev

# README

Basic Authentication

The basic authentication handler checks for basic authentication.

Usage

package main

import (
        "fmt"
        "log"
        "net/http"

        "github.com/cloudlena/adapters/basicauth"
)

// IndexHandler says what it loves.
func IndexHandler() http.Handler {
        return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
        })
}

func main() {
        users := []basicauth.User{
                {Username: "user", Password: "pass"},
        }
        authMiddleware := basicauth.Handler("My Realm", users)
        http.Handle("/", authMiddleware(IndexHandler()))
        log.Fatal(http.ListenAndServe(":8080", nil))
}