diff options
| -rw-r--r-- | main.go | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -17,6 +17,7 @@ type App struct { Store Template *template.Template Domain string + Header string } func logMux(handler http.Handler) http.Handler { @@ -40,7 +41,7 @@ func (app *App) validate(r *http.Request) (*Session, bool) { func (app *App) validateHandler(w http.ResponseWriter, r *http.Request) { if s, ok := app.validate(r); ok { - w.Header().Set("X-Remote-User", strconv.FormatInt(s.UserId, 10)) + w.Header().Set(app.Header, strconv.FormatInt(s.UserId, 10)) w.WriteHeader(http.StatusOK) } else { w.WriteHeader(http.StatusUnauthorized) @@ -112,6 +113,11 @@ func main() { } address := flag.String("a", ":8080", "bind the server to `address`") templateDir := flag.String("t", "templates", "template `directory`") + header := flag.String( + "header", + "X-Remote-User", + "http `header` containing the user id", + ) flag.Parse() if flag.NArg() < 2 { fmt.Print("Argument missing. ") @@ -123,7 +129,7 @@ func main() { template := template.Must( template.New("").ParseGlob(filepath.Join(*templateDir, "*.tmpl")), ) - app := &App{store, template, flag.Args()[1]} + app := &App{store, template, flag.Args()[1], *header} http.HandleFunc("/validate", app.validateHandler) http.HandleFunc("/login", app.loginHandler) http.HandleFunc("/logout", app.logoutHandler) |
