Re:Writing web applications using only the Go Standard Library
by lobster_johnson on Friday December 23, 2016 @08:49PM
(#13248192)
The first thing people tend to do is to replace the default, very primitive "mux" with a router that more closely aligns with modern expectations, such as httprouter (https://github.com/julienschmidt/httprouter) or chi (https://github.com/pressly/chi).
These libraries also support middleware wrapping [1], a technique that the default mux supports but doesn't help you with. For example, adding CORS headers or logging the request.
Re:Writing web applications using only the Go Standard Library
by chrisper on Friday December 23, 2016 @07:49PM
(#13248056)
No, it has been around forever. It was the first page I used to see how to make a web app in Go.
Re:Writing web applications using only the Go Standard Library
by eternalban on Friday December 23, 2016 @10:54PM
(#13248470)
I think Go is being strictly correct here:
Re:Writing web applications using only the Go Standard Library
by codebeaker on Saturday December 24, 2016 @11:58AM
(#13250518)
Isn't being "technically" correct, but actually not doing what people expect kinda frowned upon?
> Be conservative in what you do, be liberal in what you accept from others
Re:Writing web applications using only the Go Standard Library
by jasonkostempski on Saturday December 24, 2016 @09:11PM
(#13252513)
I despise that quote. Regardless of what the intended message was, what it implies is a horrible recipe for life-long support of shitty client behavior.
I think the stdlib is awesome, but the biggest gripe I have with the standard net/http library would be the multiplexer (ServeMux). Out of the box if you provide it with a handle like /foo but the user making a request adds a trailing slash (e.g. GET /foo/), it returns a 404, compared to other libraries like julienschmidt/httprouter which will handle cases like this for you.
For example: https://play.golang.org/p/Q96EulBUfI
Other than that I think the stdlib is bang-on for simple http servers. Wouldn't recommend it if you're planning on writing a web server backed by a database, however. Compared to other web frameworks like django, the stdlib is a great library for working at a lower level in the stack, whereas Django is more of a content-oriented framework built around higher level concepts like basic CRUD applications.