diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-21 17:43:52 -0400 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-21 17:43:52 -0400 |
commit | 4a2aa14e68b5b6b1b3c09e0b923178c7c98a671c (patch) | |
tree | 5e79e561563205356e0c53be1001703b962d918b /bin-src/httpd.go | |
parent | 34c71d5c91fe98276496ded1cb14362aa8028712 (diff) |
Add a simple httpd
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) + } +} |