guard/example/basicauth/main.go

18 lines
306 B
Go
Raw Permalink Normal View History

2021-11-19 06:35:53 +00:00
package main
import (
"net/http"
"kumoly.io/lib/guard"
)
func main() {
mux := http.NewServeMux()
g := guard.New()
g.SetBasicAuth("evan", "evan")
mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
rw.Write([]byte("ok"))
})
http.ListenAndServe("127.0.0.1:8000", g.Guard(mux))
}