http

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

HTTP utils for basic authentication etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuthHandler

type BasicAuthHandler struct {
	Username        string
	Password        string
	Realm           string
	OriginalHandler http.Handler
}

Wraps an original http.Handler with credentials to do http basic authentication and a realm text to be displayed in 401 responses.

Usage:

authHandler := httpUtil.BasicAuthHandler{
    Username: "user123",
    Password: "secret",
    Realm:    "Please provide username and password",
    OriginalHandler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
        // ..
    }),
}

http.Handle("/sample", authHandler)

func (BasicAuthHandler) ServeHTTP

func (h BasicAuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

BasicAuthHandler satisfies http.Handler interface and after checking the credentials delegates to the original handler.

Jump to

Keyboard shortcuts

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