From 11c0e0ca37ce58d74f3cd5831265b9912f6bc8ea Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Fri, 8 Jan 2021 22:25:55 -0500 Subject: Make the application a bit more user friendly Make a split between being accessed over loopback and remotely. Attempt to show the IP of the server on the internal page to make it easy to hand out. Remove the ability to change any of the runtime configuration or quit the program unless you're local. --- cmd/web/serve-self.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 cmd/web/serve-self.go (limited to 'cmd/web/serve-self.go') diff --git a/cmd/web/serve-self.go b/cmd/web/serve-self.go new file mode 100644 index 0000000..103fbf1 --- /dev/null +++ b/cmd/web/serve-self.go @@ -0,0 +1,27 @@ +package main + +import ( + "io" + "os" + "net/http" +) + +func serveSelf(w http.ResponseWriter, r *http.Request) { + s, err := os.Executable() + if err != nil { + Logger.Println("While trying to get my executable path: ", err) + http.Error(w, "Internal server error", http.StatusInternalServerError) + return + } + + fh, err := os.Open(s) + if err != nil { + Logger.Println("While opening my own executable for reading: ", err) + http.Error(w, "Internal server error", http.StatusInternalServerError) + return + } + + _, err = io.Copy(w, fh) + fh.Close() + return +} -- cgit v1.2.3