diff options
Diffstat (limited to 'bin-src/httpd.go')
-rw-r--r-- | bin-src/httpd.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/bin-src/httpd.go b/bin-src/httpd.go new file mode 100644 index 0000000..6b653bd --- /dev/null +++ b/bin-src/httpd.go @@ -0,0 +1,35 @@ +package main + +import ( + "errors" + "fmt" + "net" + "net/http" + "os" + "path/filepath" +) + +func mainWithError() error { + listenerFile := os.NewFile(uintptr(3), "listener") + if listenerFile == nil { + return errors.New("FD3 is not open") + } + + listener, err := net.FileListener(listenerFile) + if err != nil { + return err + } + + if err := os.Chdir(filepath.Dir(filepath.Dir(os.Args[0]))); err != nil { + return err + } + + return http.Serve(listener, http.FileServer(http.Dir("public"))) +} + +func main() { + if err := mainWithError(); err != nil { + fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err) + os.Exit(1) + } +} |