main.go 834 B

123456789101112131415161718192021222324252627282930313233343536
  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "os"
  6. "github.com/namsral/flag"
  7. "git.lattuga.net/boyska/feedpanel/panelui"
  8. "github.com/urfave/negroni"
  9. )
  10. func main() {
  11. port := os.Getenv("PORT")
  12. if port == "" {
  13. port = "8000"
  14. }
  15. fs := flag.NewFlagSetWithEnvPrefix(os.Args[0], "PANEL", 0)
  16. allowedName := fs.String("allowed-name", "", "Name allowed to forward auth")
  17. addr := fs.String("listen-addr", ":"+port, "Address to listen on")
  18. fs.Parse(os.Args[1:])
  19. var allowedNames []string
  20. if *allowedName != "" {
  21. allowedNames = []string{*allowedName}
  22. } else {
  23. allowedNames = []string{}
  24. }
  25. ha := panelui.HeaderAuth{AllowedNames: allowedNames, RequireUser: true}
  26. n := negroni.New(negroni.NewRecovery(), negroni.NewLogger(), ha)
  27. n.UseHandler(panelui.GetMux())
  28. fmt.Println("Listening on", *addr)
  29. http.ListenAndServe(*addr, n)
  30. }