Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // All paths defined in secureRouter have to pass HTTP Basic auth
- secureRouter := router.MatcherFunc(func(r *http.Request, rm *mux.RouteMatch) bool {
- name, pass, ok := r.BasicAuth()
- if ok && name == configObject.AuthName && pass == configObject.AuthPass {
- return true
- }
- return false
- }).Subrouter()
- campaignsRouter := router.PathPrefix("/campaigns").Subrouter()
- campaignsRouter.HandleFunc("/", controllers.CampaignListActive).Methods("GET")
- campaignsRouter.HandleFunc("/active/", controllers.CampaignListActive).Methods("GET")
- campaignsRouter.HandleFunc("/", controllers.CampaignUpdateOrCreate).Methods("POST")
- // Will not match images, css or JS and will not pass HTTP Basic auth
- router.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
- w.Header().Set("WWW-Authenticate", `Basic realm="Spamler"`)
- w.WriteHeader(401)
- w.Write([]byte("401 Unauthorized\n"))
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement