News for hackers. Stuff that matters.
Re:Show HN: A simple Go web server with logging, tracing, he... by twic on Sunday January 07, 2018 @12:21PM (#16091597)
Here's a quick attempt at the same thing in Java (although note that the command line format is different):

https://gist.github.com/tomwhoiscontrary/b4888b86057c74a636c...

The main takeaway is that the JDK's built-in web server is poor:

* There is no way to configure timeouts

* Filters have to be added to each handler separately, by mucking with its filter list

* Filters have to extend an abstract class with two methods (one totally pointless), so you can't use lambdas for them

* Handlers use a simple string prefix match, so a request for "/healthzone" will hit the health handler

* The stop method always blocks for the specified timeout, and never returns early as the docs promise (IME)

Other minor irritations:

* There is no method to parse an InetSocketAddress from a string

* Java's support for handling clean process shutdown is not great; i think there's some sort of race between the shutdown hook and the logging system getting shut down, so you never see the "Server stopped" message

Re:Show HN: A simple Go web server with logging, tracing, he... by SEJeff on Sunday January 07, 2018 @02:45PM (#16092271)
If you're using java, just use finagle's http server and be done with it. It is really good and runs most all of twitter.com's production web services. The very definition of "web scale":

https://twitter.github.io/finagle/guide/Quickstart.html

Re:Show HN: A simple Go web server with logging, tracing, he... by twic on Monday January 08, 2018 @05:39AM (#16095872)
"zero dependencies" was an essential feature of this. Finagle would be a dependency. And, according to a quick 'gradle distZip', it drags in a further 49 transitive dependencies.
Re:Show HN: A simple Go web server with logging, tracing, he... by SEJeff on Tuesday January 09, 2018 @06:54PM (#16111321)
That seems sensible. Really cool project (and I didn't mean to piss on it), just wanted to point out that generally speaking, finagle is serious business and can be used already.
Re:Show HN: A simple Go web server with logging, tracing, he... by michaelmcmillan on Sunday January 07, 2018 @04:22PM (#16092813)
Not sure if I would use Twitter as a success story for handling scale. Not exactly the poster boy of reliable software.
Re:Show HN: A simple Go web server with logging, tracing, he... by SEJeff on Sunday January 07, 2018 @04:55PM (#16092963)
You're kidding, right? After they ditched ruby and wrote finagle, they've been super reliable. They've got one of the biggest Apache Mesos clusters in the world (second only to Apple's Siri backend per Apple employees who presented at MesosCon) and run it all with Apache Aurora, a really nice mesos framework for long running jobs.

Twitter, Soundcloud, Salesforce, Pinterest, FitBit, Tumblr, Box, Foursquare... What do they all have in common? They all run finagle in production. For java, it is about as battletested and as good as you'll get unless you want to write your own. Personally, I'm more of a golang and python developer, but respect where it is due. Twitter is massively more scalable than the overwhelmingly majority of the sites on the internet and they've gotten their act together since abandoning Ruby and the fail whale.

Re:Show HN: A simple Go web server with logging, tracing, he... by xstartup on Sunday January 07, 2018 @09:51PM (#16094303)
Is it Java or Scala? I only see Scala on this page: https://twitter.github.io/finagle/guide/Quickstart.html#a-mi...
Re:Show HN: A simple Go web server with logging, tracing, he... by SEJeff on Sunday January 07, 2018 @10:45PM (#16094497)
Finagle proper is written in Scala, but you can use java as well for building services with it:

https://github.com/jghoman/finagle-java-example

Re:Show HN: A simple Go web server with logging, tracing, he... by ianamartin on Sunday January 07, 2018 @04:40PM (#16092901)
Really good; web scale; reliable.

Pick two.

Re:Show HN: A simple Go web server with logging, tracing, he... by meddlepal on Sunday January 07, 2018 @01:26PM (#16091908)
Yea, the built-in JDK HTTP server is pretty poor, but I don't think I've ever run across it in the wild thankfully.

> There is no way to configure timeouts

They're configured by properties if I recall.

> Filters have to be added to each handler separately, by mucking with its filter list

I personally prefer the explicitness of this.

As for the rest... I think a lot of these issues stem from the fact it's an old, not particularly well-known API in the JDK.

Re:Show HN: A simple Go web server with logging, tracing, he... by enricofoltran on Sunday January 07, 2018 @12:55PM (#16091765)
Hi twic, thanks for sharing this! I love to see implementation in other languages. I'm particularly interested in Rust, it would be awesome if anyone can make a attempt! :)
Re:Show HN: A simple Go web server with logging, tracing, he... by AsyncAwait on Sunday January 07, 2018 @01:21PM (#16091878)
That would be awesome, but note that Rust, due to it being a low-level language, doesn't really have a net/http equivalent in its standard library and therefore any implementation would be more of a representation of the 3rd party libraries used.
Re:Show HN: A simple Go web server with logging, tracing, he... by rb808 on Sunday January 07, 2018 @09:50PM (#16094301)
Jetty does everything, else Spring with tomcat. I don't see any reason to rely on JDK web server (which I've never seen anyone seriouosly use.
Re:Show HN: A simple Go web server with logging, tracing, he... by dboreham on Sunday January 07, 2018 @09:20PM (#16094172)
I've been developing in Java for around 20 years and I never knew the JDK included a web server. This must be the thing I learned today ;)
Re:Show HN: A simple Go web server with logging, tracing, he... by skanga on Sunday January 07, 2018 @01:41PM (#16091974)
Nice. Does anyone have a server like this but with the addition of

* serving of files and directories

* LetsEncrypt certificates and SSL

Re:Show HN: A simple Go web server with logging, tracing, he... by sd8dgf8ds8g8dsg on Sunday January 07, 2018 @08:11PM (#16093915)
static file server in go:

    package main

    import (
        "fmt"
        "net/http"
        "path/filepath"
    )

    var (
        host = "0.0.0.0"
        path = "/var/www/public"
        port = 8080
    )

    func main() {
        path, err := filepath.Abs(path)
        if err != nil {
            panic(err)
        }
        listenAt := fmt.Sprintf("%s:%v", host, port)
        fmt.Println("static-serve-dir serving", path, "over http at", listenAt)
        err = http.ListenAndServe(listenAt, http.FileServer(http.Dir(path)))
        if err != nil {
            panic(err)
        }
    }
Re:Show HN: A simple Go web server with logging, tracing, he... by wyattjoh on Sunday January 07, 2018 @03:31PM (#16092515)
The builtin golang.org/x/crypto/acme/autocert [0] package manages SSL for you easily through Lets Encrypt.

[0]: https://godoc.org/golang.org/x/crypto/acme/autocert

Re:Show HN: A simple Go web server with logging, tracing, he... by TheDong on Sunday January 07, 2018 @09:05PM (#16094108)
golang.org/x/ packages are not builtin. You still must download them and use them just as you do any other dependencies, they just share some contribution process and developers with golang's stdlib.
Re:Show HN: A simple Go web server with logging, tracing, he... by setheron on Sunday January 07, 2018 @01:30PM (#16091925)
Just wrap the handlers with middleware rather than using that filter abstraction.

Same thing!

Re:Show HN: A simple Go web server with logging, tracing, he... by twic on Monday January 08, 2018 @06:06AM (#16095973)
By 'middleware', do you mean another handler? That would work, but i'd still have to wrap each handler separately.