TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Easy-to-configure Web Server in Go

106 pointsby oakazalmost 12 years ago

9 comments

laumarsalmost 12 years ago
A word of warning guys, I&#x27;ve had a look through the code and unless I&#x27;ve missed the obvious, there&#x27;s nothing in there to change user ID; which means this would either need to be run as root, or would need to listen on a port &gt; 1024.<p>In the case of the former, that&#x27;s a huge step backwards in terms of security.<p>In the case of the latter, that would mean you&#x27;d need another reverse proxy hooked up - which would negate the need for this web server to begin with.<p>This can easily be fixed within Go though:<p><pre><code> import ( &quot;log&quot; &quot;syscall&quot; ) const ( user_id int = 1000 group_id int = 1000 ) func secureDaemon() { &#x2F;&#x2F; set group id first as you need to be root to change group err := syscall.Setgid(group_id) if err != nil { log.Fatalln(err) } err = syscall.Setuid(user_id) if err != nil { log.Fatalln(err) } } </code></pre> You can also add chroot to your code if you want to be ultra paranoid:<p><pre><code> import ( &quot;os&quot; ) const ( chroot_dir string = &quot;&#x2F;opt&#x2F;go-webserver&quot; ) func chrootDaemon() { err := os.Chdir(chroot_dir) if err != nil { log.Fatalln(err) } err = syscall.Chroot(chroot_dir) if err != nil { log.Fatalln(err) } } </code></pre> This will need to be done before you change your user ID (as you need root permissions to chroot) and you may need to compile the Go without CGO because some of the standard Go libraries will have SO dependencies (I found this to be the case with domain name lookups).<p>(the above code is adapted from my own Go web framework that I&#x27;m in the processes of building)
评论 #6114052 未加载
评论 #6114431 未加载
评论 #6112744 未加载
评论 #6115363 未加载
评论 #6112774 未加载
评论 #6113318 未加载
评论 #6113324 未加载
justinsbalmost 12 years ago
I remain not-entirely-convinced (1) by Go, but things like this are turning the tide. If it is indeed slower than nginx, it is not dramatically so. Considering the amount of time that went in to writing each, the Go version clearly &quot;wins&quot; from the point of view of anyone thinking of writing new code.<p>(1) I find error handling just too tedious to get right (Edit: &quot;I find error handling _in Go_ just too tedious...&quot;)
评论 #6113108 未加载
评论 #6112956 未加载
stevekempalmost 12 years ago
So it&#x27;s a reverse HTTP proxy, which can also serve files locally? That&#x27;s an interesting thing, no doubt, but it doesn&#x27;t feel like a web-server.<p>I wrote a flexible reverse proxy[0] using node.js, a year or so ago, and haven&#x27;t missed the ability to serve static files directly - so I&#x27;m wondering what the use-case for that is? I guess proxying to rails, or similar?<p>0- <a href="http://steve.org.uk/Software/node-reverse-proxy/" rel="nofollow">http:&#x2F;&#x2F;steve.org.uk&#x2F;Software&#x2F;node-reverse-proxy&#x2F;</a>
评论 #6113375 未加载
Uchikomaalmost 12 years ago
I always wonder with this kind of posts, is it minimalistic or is it an alternative?
评论 #6112731 未加载
评论 #6112435 未加载
JoeAcchinoalmost 12 years ago
I&#x27;m very interested in this because this is the kind of web server I was planning to write for my work, but from a quick glance I didn&#x27;t find HTTPS support.<p>Is HTTPS supported or planned?
评论 #6113704 未加载
pandeiroalmost 12 years ago
Code organization question: is this a common convention in Go, to nest the main package in a subdirectory and put all of the &#x27;modules&#x27; in different files but with the same package name?<p>(I&#x27;m more used to the Clojure namespace&#x2F;filesystem symmetry, so this is somewhat new to me. I like the more shallow project tree but it&#x27;s not immediately apparent where things are defined.)
评论 #6112918 未加载
评论 #6114518 未加载
alexchamberlainalmost 12 years ago
Nice to see an alternative on the cards. Of course, we need some independent security reviews before this can be used seriously.
tszmingalmost 12 years ago
json format is too limited for a web server configuration if you want to be the nginx alternative. Think about how you would represent conditional statements, how to include and reuse external configurations and how to have comments in json.
simonwalmost 12 years ago
The custom 404 page example in the readme looked incomplete - how do you ensure those pages are served with the correct HTTP status code?