diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..051d09d --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +eval "$(lorri direnv)" diff --git a/go.mod b/go.mod index 237d372..6fdd8b4 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,8 @@ require ( github.com/eaburns/peggy v1.0.1 github.com/facebookgo/flagenv v0.0.0-20160425205200-fcd59fca7456 github.com/perlin-network/life v0.0.0-20191010061010-fa85cafea8ac + github.com/pkg/errors v0.9.1 // indirect github.com/rs/cors v1.7.0 - within.website/ln v0.7.0 + within.website/ln v0.9.1 within.website/x v1.1.8 ) diff --git a/go.sum b/go.sum index d90aba5..bd9b783 100644 --- a/go.sum +++ b/go.sum @@ -83,6 +83,8 @@ github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rK github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= @@ -153,5 +155,7 @@ within.website/johaus v1.1.0/go.mod h1:0RBs2TucQ3CZQiVoqNj9Wch7mtZY05uvNO14v0lKc within.website/ln v0.6.0/go.mod h1:ifURKqsCJekcsdUE+hyCdcuhQqQ+9v9DfA++ZqYxZFE= within.website/ln v0.7.0 h1:cZUc53cZF/+hWuEAv1VbqlYJ5czuPFHKfH0hLKmlIUA= within.website/ln v0.7.0/go.mod h1:ifURKqsCJekcsdUE+hyCdcuhQqQ+9v9DfA++ZqYxZFE= +within.website/ln v0.9.1 h1:Qi8IjeCnU43jXijKtr5qtcbjuiCVAudOIxqTim7svnc= +within.website/ln v0.9.1/go.mod h1:I+Apk8qxMStNXTZdyDMqDqe6CB8Hn6+W/Gyf5QbY+2E= within.website/x v1.1.8 h1:OSiR9OQo+nRf17tiZV559bgKFB7x6xfcjPj9vVcJxVo= within.website/x v1.1.8/go.mod h1:L6lqE0SSvN7RMnVFMuKsArOEzuRkT1R2HKYJgu/un7Q= diff --git a/http.go b/http.go index 9977087..f096e3f 100644 --- a/http.go +++ b/http.go @@ -5,7 +5,9 @@ import ( "flag" "fmt" "io/ioutil" + "net" "net/http" + "os" "github.com/rs/cors" "within.website/ln/ex" @@ -22,7 +24,24 @@ func doHTTP() error { http.Handle("/play", doTemplate(playgroundTemplate)) http.HandleFunc("/api/playground", runPlayground) - return http.ListenAndServe(":"+*port, ex.HTTPLog(cors.Default().Handler(http.DefaultServeMux))) + srv := &http.Server{ + Addr: ":" + *port, + Handler: ex.HTTPLog(cors.Default().Handler(http.DefaultServeMux)), + } + + if *sockpath != "" { + os.RemoveAll(*sockpath) + + l, err := net.Listen("unix", *sockpath) + if err != nil { + return fmt.Errorf("can't listen on %s: %v", *sockpath, err) + } + defer l.Close() + + return srv.Serve(l) + } else { + return srv.ListenAndServe() + } } func httpError(w http.ResponseWriter, err error, code int) { diff --git a/main.go b/main.go index 9a22a2a..cc6808a 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ var ( outFname = flag.String("o", "", "if specified, write the webassembly binary created by -p here") watFname = flag.String("o-wat", "", "if specified, write the uncompiled webassembly created by -p here") port = flag.String("port", "", "HTTP port to listen on") + sockpath = flag.String("sockpath", "", "Unix domain socket to listen on") writeTao = flag.Bool("koan", false, "if true, print the h koan and then exit") writeVersion = flag.Bool("v", false, "if true, print the version of h and then exit") ) @@ -100,7 +101,7 @@ func main() { return } - if *port != "" { + if *port != "" || *sockpath != "" { err := doHTTP() if err != nil { panic(err) diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..1550d66 --- /dev/null +++ b/shell.nix @@ -0,0 +1,13 @@ +{ pkgs ? import {} }: + +pkgs.mkShell { + buildInputs = with pkgs; [ + go + goimports + gopls + wabt + + # keep this line if you use bash + bashInteractive + ]; +}