Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

web_graceful.go 969B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // +build !windows
  2. // Copyright 2016 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package cmd
  6. import (
  7. "crypto/tls"
  8. "log"
  9. "net/http"
  10. "github.com/facebookgo/grace/gracehttp"
  11. )
  12. func runHTTP(listenAddr string, m http.Handler) error {
  13. return gracehttp.Serve(&http.Server{
  14. Addr: listenAddr,
  15. Handler: m,
  16. })
  17. }
  18. func runHTTPS(listenAddr, certFile, keyFile string, m http.Handler) error {
  19. config := &tls.Config{
  20. MinVersion: tls.VersionTLS10,
  21. }
  22. if config.NextProtos == nil {
  23. config.NextProtos = []string{"http/1.1"}
  24. }
  25. config.Certificates = make([]tls.Certificate, 1)
  26. var err error
  27. config.Certificates[0], err = tls.LoadX509KeyPair(certFile, keyFile)
  28. if err != nil {
  29. log.Fatal(4, "Failed to load https cert file %s: %v", listenAddr, err)
  30. }
  31. return gracehttp.Serve(&http.Server{
  32. Addr: listenAddr,
  33. Handler: m,
  34. TLSConfig: config,
  35. })
  36. }