Skip to content

Instantly share code, notes, and snippets.

@mash
Created April 27, 2022 06:43
Show Gist options
  • Save mash/1bcbbc56e28b673093c03483b277f3ba to your computer and use it in GitHub Desktop.
Save mash/1bcbbc56e28b673093c03483b277f3ba to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net"
"net/http"
"os"
)
func main() {
dir, _ := os.Getwd()
port := os.Getenv("PORT")
if port == "" {
port = "0"
}
l, err := net.Listen("tcp4", ":"+port)
if err != nil {
log.Fatal(err)
}
fmt.Printf("listening on :%s\nOpen http://%s\n", l.Addr(), l.Addr().String())
log.Fatal(http.Serve(l, http.FileServer(http.Dir(dir))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment