Net/http vs Gin: when should I prefer one over the other?

I often see production Go services using the standard net/http package even though frameworks like Gin provide faster setup and more features.

For those with production experience:

  • What limitations or downsides have you encountered with Gin?

  • Does net/http scale better for large codebases?

  • How do you handle routing and middleware cleanly without a framework?

Please leave your thoughts and experiences regarding this thought.

My experience with net/http is that there is a difference between MPA (<a href> for simpler sites) and SPA (Both Go and Javascript routing for apps).

MPA routing can be quite simple with one single dynamic endpoint.

func router(w http.ResponseWriter, r *http.Request) {
	path := strings.Trim(r.URL.Path, "/")
	if path == "" {
		path = "mpa"
	}

	if strings.HasPrefix(path, ".") {
		return
	}

	setheader(w) // CPS and other headers
	meta := geturl(path) // some canonical stuff
	err := tpl.ExecuteTemplate(w, path+".html", meta)
	if err != nil {
		fmt.Println("Something is wrong ", err.Error())
		http.Redirect(w, r, "/mpa", http.StatusSeeOther)
		return
	}
}

SPA on the other hand I have a rather simple router, but routing to several handlers as the sub templates may be different. No framework needed IMO.

I have no experience with Gin as I think net/http is powerful and simple enough…

1 Like

Hi, I am a senior golang developer. If you want me, I can answer your questions. I want become friend with u. I wish you are doing well.

1 Like

Yeah - I think prior to version 1.22, routing frameworks were a must. But in the post-1.22 world, that isn’t necessarily the case:

I have shipped plenty of RESTful APIs using nothing but the stdlib. If you find value in Gin, use it though. I can’t think of a single project that I’ve been involved with that did or didn’t succeed due to the routing framework we chose.

2 Likes