1
0
Fork 0
forked from boyska/feedpanel
feedpanel/cmd/userpanel/main.go
2018-10-02 10:10:53 +02:00

38 lines
887 B
Go

package main
import (
"fmt"
"html/template"
"net/http"
"github.com/urfave/negroni"
)
var helloTmpl *template.Template
func init() {
helloTmpl = template.Must(template.New("hello").Parse(`
<html><body>Hello, {{.User}}
<p>Go to <a href="/tt-rss/">Feed Reader</a></p>
</body></html>`))
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
user := r.Context().Value(keyUser)
if user == nil {
panic("Authentication middleware failed!")
}
w.WriteHeader(200)
w.Header().Set("Content-type", "text/html")
helloTmpl.Execute(w, map[string]interface{}{"User": user})
})
ha := HeaderAuth{AllowedNames: []string{"feedati-fe"}, RequireUser: true}
n := negroni.New(negroni.NewRecovery(), negroni.NewLogger(), ha)
n.UseHandler(mux)
addr := ":8000"
fmt.Println("Listening on", addr)
http.ListenAndServe(addr, n)
}