basicauth

package
v0.0.0-...-abf8f43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(realm string, users []User) func(http.Handler) http.Handler

Handler enforces basic authenthication.

Types

type User

type User struct {
	Username string
	Password string
}

User is a set of username and password.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL