1
0
Fork 0
forked from boyska/feedpanel
feedpanel/cmd/userpanel/main.go

39 lines
887 B
Go
Raw Normal View History

2018-09-30 11:06:46 +02:00
package main
import (
"fmt"
2018-10-02 10:10:53 +02:00
"html/template"
2018-09-30 11:06:46 +02:00
"net/http"
2018-09-30 14:05:25 +02:00
"github.com/urfave/negroni"
2018-09-30 11:06:46 +02:00
)
2018-10-02 10:10:53 +02:00
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>`))
}
2018-09-30 11:06:46 +02:00
func main() {
2018-09-30 14:05:25 +02:00
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)
2018-10-02 10:10:53 +02:00
w.Header().Set("Content-type", "text/html")
helloTmpl.Execute(w, map[string]interface{}{"User": user})
2018-09-30 11:06:46 +02:00
})
2018-09-30 14:05:25 +02:00
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)
2018-09-30 11:06:46 +02:00
}