main.go 414 B

12345678910111213141516171819202122232425262728
  1. package main
  2. import (
  3. "net/http"
  4. "os"
  5. "github.com/skratchdot/open-golang/open"
  6. )
  7. var run = open.Run
  8. func main() {
  9. port := getPort()
  10. wd, _ := os.Getwd()
  11. go run("http://127.0.0.1:" + port)
  12. http.ListenAndServe(":"+port, http.FileServer(http.Dir(wd)))
  13. }
  14. func getPort() string {
  15. port := os.Getenv("PORT")
  16. if len(os.Args) > 1 {
  17. port = os.Args[1]
  18. }
  19. if len(port) == 0 {
  20. port = "3000"
  21. }
  22. return port
  23. }