main.go 874 B

1234567891011121314151617181920212223242526272829303132333435
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "net/url"
  7. "os"
  8. "mDoc/admin"
  9. "mDoc/tools"
  10. )
  11. func main() {
  12. port := tools.InterfaceToStr(tools.If(os.Getenv("PORT") == "", "9000", os.Getenv("PORT"))) // 环境变量亦可以设置服务端口
  13. adminMux := admin.InitApp()
  14. adminServer := &http.Server{
  15. Addr: ":" + port,
  16. Handler: adminMux,
  17. }
  18. // 管理服务
  19. go adminServer.ListenAndServe()
  20. fmt.Println("Admiin Served at http://localhost:" + port + "/admin")
  21. // 公共服务
  22. u, _ := url.Parse(os.Getenv("PUBLISH_URL"))
  23. publishPort := tools.InterfaceToStr(tools.If(u.Port() == "", "9001", u.Port()))
  24. publishMux := http.FileServer(http.Dir(admin.PublishDir))
  25. publishServer := &http.Server{
  26. Addr: ":" + publishPort,
  27. Handler: publishMux,
  28. }
  29. fmt.Println("Publish Served at http://localhost:" + publishPort)
  30. log.Fatal(publishServer.ListenAndServe())
  31. }