demo.go 735 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. "os"
  6. "time"
  7. "code.osinet.fr/fgm/web_auth_demo/server"
  8. )
  9. func main() {
  10. app, err := server.New(
  11. os.Getenv("AUTH_USERNAME"),
  12. os.Getenv("AUTH_PASSWORD"),
  13. os.Getenv("AUTH_CERT"),
  14. os.Getenv("AUTH_CERT_KEY"),
  15. )
  16. if err != nil {
  17. log.Fatal(err)
  18. }
  19. mux := http.NewServeMux()
  20. mux.HandleFunc("/unprotected", app.UnprotectedHandler)
  21. mux.HandleFunc("/protected", app.BasicAuth(app.ProtectedHandler))
  22. srv := &http.Server{
  23. Addr: ":4000",
  24. Handler: mux,
  25. ReadTimeout: 10 * time.Second,
  26. WriteTimeout: 30 * time.Second,
  27. IdleTimeout: time.Minute,
  28. }
  29. log.Printf("Starting TLS server on %s", srv.Addr)
  30. err = srv.ListenAndServeTLS(app.Cert, app.Key)
  31. log.Fatal(err)
  32. }