From f281d90c7b90e914d0daf6217afca152b57413be Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 8 Feb 2020 22:06:53 +0000 Subject: [PATCH] quickserv --- .gitignore | 1 + default.nix | 13 ++++++++++++ deps.nix | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 12 +++++++++++ go.sum | 12 +++++++++++ main.go | 23 +++++++++++++++++++++ 6 files changed, 118 insertions(+) create mode 100644 .gitignore create mode 100644 default.nix create mode 100644 deps.nix create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..819d819 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/result-bin diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..bc1d2d5 --- /dev/null +++ b/default.nix @@ -0,0 +1,13 @@ +{ pkgs ? import {} }: +with pkgs; + +buildGoPackage rec { + name = "quickserv"; + version = "1.0.0"; + goPackagePath = "tulpa.dev/Xe/quickserv"; + src = ./.; + goDeps = ./deps.nix; + + allowGoReference = false; + CGO_ENABLED = "0"; +} diff --git a/deps.nix b/deps.nix new file mode 100644 index 0000000..4131685 --- /dev/null +++ b/deps.nix @@ -0,0 +1,57 @@ +# file generated from go.mod using vgo2nix (https://github.com/adisbladis/vgo2nix) +[ + { + goPackagePath = "github.com/davecgh/go-spew"; + fetch = { + type = "git"; + url = "https://github.com/davecgh/go-spew"; + rev = "v1.1.1"; + sha256 = "0hka6hmyvp701adzag2g26cxdj47g21x6jz4sc6jjz1mn59d474y"; + }; + } + { + goPackagePath = "github.com/facebookarchive/flagenv"; + fetch = { + type = "git"; + url = "https://github.com/facebookarchive/flagenv"; + rev = "fcd59fca7456"; + sha256 = "0c7fw4y4gmdrn66dx7la637lx0hvs1w27x9j12wdx037n51r078g"; + }; + } + { + goPackagePath = "github.com/facebookgo/ensure"; + fetch = { + type = "git"; + url = "https://github.com/facebookgo/ensure"; + rev = "63f1cf65ac4c"; + sha256 = "05vi49g2967i5awcb1z69i2n5b5hwn06682kw90x81hbxlr0px36"; + }; + } + { + goPackagePath = "github.com/facebookgo/flagenv"; + fetch = { + type = "git"; + url = "https://github.com/facebookgo/flagenv"; + rev = "fcd59fca7456"; + sha256 = "0c7fw4y4gmdrn66dx7la637lx0hvs1w27x9j12wdx037n51r078g"; + }; + } + { + goPackagePath = "github.com/facebookgo/stack"; + fetch = { + type = "git"; + url = "https://github.com/facebookgo/stack"; + rev = "751773369052"; + sha256 = "07yr05mz7h007ldpij90zjflwgixp148sbyrdlh1fj5bikr4p8m3"; + }; + } + { + goPackagePath = "github.com/facebookgo/subset"; + fetch = { + type = "git"; + url = "https://github.com/facebookgo/subset"; + rev = "c811ad88dec4"; + sha256 = "1sjczgmq26mgqvh7267saypnn4sfdjx467wsm1pgdhyss77mc650"; + }; + } +] diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f7f3ba1 --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module tulpa.dev/Xe/quickserv + +go 1.13 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/facebookarchive/flagenv v0.0.0-20160425205200-fcd59fca7456 + github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c // indirect + github.com/facebookgo/flagenv v0.0.0-20160425205200-fcd59fca7456 // indirect + github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect + github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3106caf --- /dev/null +++ b/go.sum @@ -0,0 +1,12 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/facebookarchive/flagenv v0.0.0-20160425205200-fcd59fca7456 h1:1NzATV1A9LeTWAuAJGd7vE/wYSO08EJQTrwKcBBR6Cw= +github.com/facebookarchive/flagenv v0.0.0-20160425205200-fcd59fca7456/go.mod h1:Lbo+w7sC1xznzryrqUDoBBT2nLKV9JnDOzdiVMHYX/8= +github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= +github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= +github.com/facebookgo/flagenv v0.0.0-20160425205200-fcd59fca7456 h1:CkmB2l68uhvRlwOTPrwnuitSxi/S3Cg4L5QYOcL9MBc= +github.com/facebookgo/flagenv v0.0.0-20160425205200-fcd59fca7456/go.mod h1:zFhibDvPDWmtk4dAQ05sRobtyoffEHygEt3wSNuAzz8= +github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= +github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= +github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk= +github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= diff --git a/main.go b/main.go new file mode 100644 index 0000000..304e836 --- /dev/null +++ b/main.go @@ -0,0 +1,23 @@ +// Command quickserv serves a folder of files over HTTP quickly. +package main + +import ( + "flag" + "log" + "net/http" + + "github.com/facebookarchive/flagenv" +) + +var ( + port = flag.String("port", "3000", "port to use") + dir = flag.String("dir", ".", "directory to serve") +) + +func main() { + flagenv.Parse() + flag.Parse() + http.Handle("/", http.FileServer(http.Dir(*dir))) + log.Printf("Serving %s on port %s", *dir, *port) + log.Fatal(http.ListenAndServe(":"+*port, nil)) +}