http_server.go 585 B

1234567891011121314151617181920212223242526272829303132333435
  1. package http_server
  2. import (
  3. "fmt"
  4. "net/http"
  5. "pmail/controllers"
  6. "time"
  7. )
  8. const HttpPort = 80
  9. // 这个服务是为了拦截http请求转发到https
  10. var httpServer *http.Server
  11. func HttpStop() {
  12. if httpServer != nil {
  13. httpServer.Close()
  14. }
  15. }
  16. func HttpStart() {
  17. mux := http.NewServeMux()
  18. mux.HandleFunc("/", controllers.Interceptor)
  19. httpServer = &http.Server{
  20. Addr: fmt.Sprintf(":%d", HttpPort),
  21. Handler: mux,
  22. ReadTimeout: time.Second * 60,
  23. WriteTimeout: time.Second * 60,
  24. }
  25. err := httpServer.ListenAndServe()
  26. if err != nil {
  27. panic(err)
  28. }
  29. }