6 ms·
Go comes with a built in web server that can serve static web pages easily. What's the point of this?
by gopowerranger 11y ago
Go comes with a built in web server that can serve static web pages easily. What's the point of this?
- ojanik 11y agoI was wandering the same thing. It takes only few lines to set this one up: https://golang.org/pkg/net/http/#FileServer https://golang.org/pkg/net/http/#FileServer
- beefsack 11y agoSpecifically: https://golang.org/pkg/net/http/#FileServer https://golang.org/pkg/net/http/#FileServer
- ashark 11y agoIt's handy to have a program, easily compiled for multiple platforms, that can be told to simply serve a given directory, with optional HTTPS support, and no config files or dependencies—just cross-compile to the target arch/OS, scp it over, and run. Without, you know, having to write it, even if Go's libraries make it fairly easy to do so. My go-to (haha) for this is Goserve[1]. I'm not sure why I'd switch to this, except that it may now have more eyes on it after today's publicity (it's already got more stars than Goserve—a little advertising goes a long way) [1] https://github.com/johnsto/goserve https://github.com/johnsto/goserve
- gopowerranger 11y agoSo 20 or so lines of code is too tough? How much work is involved integrating this server into an app?
- skywhopper 11y agoNot sure why you think this server was written to integrate into apps. If you can't think of a use for it, that's fine. But lots of other people do have uses for simple static web servers. Including people who don't have the knowledge, time, or patience to hand code a 20 line Go program every time they want to use one.
- gopowerranger 11y agoBy integrate I meant interacting with your program, whatever that may be. With the go server, you get everything this program has without the concern of the code going stale or dying should the author abandon it.
- biomcgary 11y agoStatic file serving is a great tutorial project in Go. I wrote mine (https://github.com/biorisk/httpfolder https://github.com/biorisk/httpfolder) to include a file upload option too, but did not add some of the nicer features, e.g., https, in your project.
- skywhopper 11y agoMaybe because you don't have to write it yourself? $ go get github.com/m3ng9i/ran && ran
- gopowerranger 11y agoHow much work is involved integrating this server into your application versus writing 20 lines of Go code? Or less. Maybe more.
- conradk 11y agoNot necessarily. In addition, this kind of program can be really useful for development. I use "python3 -m http.server" a lot when I'm just testing a bit of HTML/JS and don't want to setup a whole virtual host within Nginx/Apache. It just starts a static file server, on any platform.
- gopowerranger 11y agoSo just like go except with benefits.
- neurohax 11y agoAs I understand, the point is: a simple and practical bash command to http-serve the current directory (implemented in Go).
- gopowerranger 11y agoSo everything Go already does but in bash.