Wiki

Clone wiki

http_auth / Home

http_auth

MIT licensed HTTP Digest authentication for Golang.

Example

package main

import "bitbucket.org/taruti/http_auth"
import "http"

var s = http_digest.NewServer("MyRealm",func(user,realm string) string { 
	return http_digest.CalculateHA1(user,realm,"mypass")
})

func rootHandler(w http.ResponseWriter, r *http.Request) {
	if !s.Auth(w,r) { return }
	w.Write([]byte("<html><title>Hello</title><h1>Hello</h1></html>"))
}

func main() {
	http.HandleFunc("/", rootHandler)
	http.ListenAndServe(":8080", nil)	
}

Updated