Live data from Hacker News

Build Your Own Web Framework in Go

nicolasmerouze.com

21–30 of 37 posts

Re: Build Your Own Web Framework in Go

#21
post #3

Yes, do make your own framework. And don't leave any documentation either. Hell, invent your own language while you're at it. It'll make the "should we throw this code out" discussion WAAAAY easier in five years.

As I mentioned in my comment above, there's a lot of value in doing this (and in writing your own language) if only for an understanding of how to do such things.

There is of course a huge leap between implementing and formalizing parts of a pre-built net/http package in Go and writing a well-designed language with a quality lexer/parser, but the idea is the same. Assuming you're not doing it to be your standard live environment language/framework of choice, it's a valuable process for learning.

If everyone took the :scoff: "don't write a framework, we already have them" approach it's true we'd have a lot fewer shitty frameworks. But we'd also have a lot fewer good ones.

Re: Build Your Own Web Framework in Go

#22
post #4

I kind of disagree with this article. With go its so easy to get started with http that most of the time you dont even need a framework. If you do, most good frameworks use the following function as a common basis: func(http.ResponseWriter, *http.Request) I started with barebones http, then used gorilla, and later started using negrioni. Any new library with uses this function helps me. So in the end: you dont need a…

I created a small starter Go Web Server from a website that I'm building:

GitHub: https://github.com/melling/GoWebServer

I'm not sure that I like embedding html in fmt.Print() methods, along with templates. A lot of my page handlers look something like this:

https://github.com/melling/GoWebServer/blob/master/src/webse...

My site is about 4000-5000 lines of Go, with a bit of "repeating myself". I'd like to hear from devs who've built larger sites.

Btw, here's my site:

http://thespanishsite.com

And the usually "hidden" admin pages where I've done most of my work:

http://thespanishsite.com/admin/summary?language=chinese&pic...

Re: Build Your Own Web Framework in Go

#23

And as expected there's no mention of interacting with a database. The lack of a decent orm is the only thing keeping me from using Go for some side projects.

I'm the author of the post. I will be addressing this topic soon, but it's a very vast subject, it takes time to write good articles about database interactions and best practices.

Re: Build Your Own Web Framework in Go

#24
post #4

I kind of disagree with this article. With go its so easy to get started with http that most of the time you dont even need a framework. If you do, most good frameworks use the following function as a common basis: func(http.ResponseWriter, *http.Request) I started with barebones http, then used gorilla, and later started using negrioni. Any new library with uses this function helps me. So in the end: you dont need a…

That's what this series of articles is doing. It starts with http.Handler and assemble libraries with minimal glue code to make things work without a lot of overhead.

Re: Build Your Own Web Framework in Go

#25
post #10

The question is: Should you build a web framework in Go?

In my opinion, Go is great to make REST APIs, but for full-fledged frameworks (with server-generated HTML views) Rails will always be light years ahead for the developer productivity and happiness. That's why the article focus on a web framework to make REST APIs.

Re: Build Your Own Web Framework in Go

#26
post #22
post #4

I kind of disagree with this article. With go its so easy to get started with http that most of the time you dont even need a framework. If you do, most good frameworks use the following function as a common basis: func(http.ResponseWriter, *http.Request) I started with barebones http, then used gorilla, and later started using negrioni. Any new library with uses this function helps me. So in the end: you dont need a…

I created a small starter Go Web Server from a website that I'm building: GitHub: https://github.com/melling/GoWebServer I'm not sure that I like embedding html in fmt.Print() methods, along with templates. A lot of my page handlers look something like this: https://github.com/melling/GoWebServer/blob/master/src/webse... My site is about 4000-5000 lines of Go, with a bit of "repeating myself". I'd like to hear from d…

Just looking at your fmt.Print link, you could be wrapping everything requiring a template in functions handling the html/template stuff, i.e. have code specifically interfacing templating for you that you can just pass a command "render this template". I had a lot of problems with working through templating and ended up with my own wrappers around html/template in Djinn(https://github.com/thrisp/djinn).

Re: Build Your Own Web Framework in Go

#27
One of the values in a framework, particularly in Go's case at the moment, is a curated set of libraries and middleware. Since this doesn't exist the cost/effort is high for people looking to enter. It is likely too high for many.

Put it another way, Django and Rails would never have gotten as popular were it not for their 'batteries included' approach. Sure, Sinatra and Flask came, but they came after.

IMV, Go needs a Django/Rails if it is going to be a webframework. If not, if Go is destined for the API layer, it is probably fine with what it has now.

Re: Build Your Own Web Framework in Go

#28
post #18
post #16

Earlier quoted context omitted.

My work is mostly spent in JVM and .NET world and I am not a big fan of Go's design, so I am already biased. However I am the first voice against ORMs in any project I work on. If you care about performance, nothing beats tuned prepared stated going through the wire and stored procedures for heavy duty work. In a few projects we improved batch processing times by a few hours just by throwing the ORM into the garbage…

> If you care about performance, nothing beats tuned prepared stated going through the wire and stored procedures for heavy duty work. for "heavy duty work",sure.Now write your own hydrators,again,again and again,and let's see how maintainable your code is. Now the fact is ,it's impossible to write an ORM in Go,without throwing all type safety,just like Java pre-generics,you'd cast and down-cast to Ojbect.

I don't even know what an hydrator is!

Re: Build Your Own Web Framework in Go

#29
post #20
post #16

Earlier quoted context omitted.

My work is mostly spent in JVM and .NET world and I am not a big fan of Go's design, so I am already biased. However I am the first voice against ORMs in any project I work on. If you care about performance, nothing beats tuned prepared stated going through the wire and stored procedures for heavy duty work. In a few projects we improved batch processing times by a few hours just by throwing the ORM into the garbage…

ORM works great for basic CRUD stuff like typical web applications. You don't have to use it in every part of your application.

Until you have the whole world banging into your site.

Re: Build Your Own Web Framework in Go

#30
post #6

A framework calls your code, a library is called by your code. In the long run, when you start a web application using packages like "net/http" and the gorilla toolkit, sooner or later it becomes framework-like, because you start to group your code together, you refactor it and make it easiliy extendable _for the app you are writing_. So, every app becomes a framework on it's own. And what I like about Go is the fact…

>A framework calls your code, a library is called by your code.

Exactly. Very subjective, but I lean towards library with golang, because it seems more natural, and the bigger a framework gets, the more you have to do work for it to get it to do work for you.

Post reply on HN