What is the difference between pure golang and web framework like beego for server side in Web?

I am try to learning golang these days, and as you know there is alots of web frameworks for web backends, so I want to develop services for my web apps, and I do not know I am choose pure golang or golang web frameworks? I want to just work with rest API to integrate my react .js front end.

1 Like

If you want magic, more overhead and a sometimes a complete different language - go for framework. It may save you a lot of time.

If you want less overhead and using plain Go - go for pure Go. I have made a simple API without any framework that maybe gives you a hint.

tnx for ur answer, with pure go, can I create services for apps which have high traffics

In my opinion - yes. Concurrency is the strength of Go. But you may pay more attention to sessions limits and sessions length regarding the database. In this case a framework may - or may not - have built in functions for that.

if I decide to work with framework, which web framework best for REST API in Golang

As always, there is no “best” framework. It is personal preferences and what is best suited for the task. But Gin appears many time as one of the most popular. Google your question or maybe anybody else want to jump in…

1 Like

I get it tnx, I will.

When you say “pure golang” do you mean stdlib? Because to my knowledge most of the available frameworks are “pure golang”. Is your worry that you don’t want to add a bunch of bloat/dependencies to your project?

gorilla/mux and the gorilla toolkit are used by many projects. I have a few web APIs in production right now built with gorilla/mux and enjoy it quite a bit. That said, the main thing that is lacking in the stdlib is routing/param matching capabilities. If you want something more lightweight that provides just these capabilities, check out julienschmidt/httprouter. For a first project, though, I don’t think you can go wrong with gorilla.

All this having been said, go is almost purpose-built for web APIs and is going to be a great fit for what you’re trying to do. Good luck and have fun!

1 Like

tn sfor ur reply, yes sure I mean without framework, like python or django. python is general purpose language, but django is web framework. that is why I confused about golang, becasue there is not popular web framework in golang.

Ah - there are many popular web frameworks in golang. But I think the confusion is: with Python, for example, django is like the clear winner. Whereas, in the go ecosystem, there are more options. Most adhere to stdlib for the most part so they’re (for the MOST PART) pretty interchangeable. And you can get pretty far with stdlib + a few helper functions since most of what you want from a web framework is routing and serialization/deserialization, the latter of which is part of the stdlib. See this comment I made about routing via convention using only stdlib. If you wanted to be completely barebones you could use something like that as a starting point.

but many python developers say, golang can beat python in every where via its performance. I am curious about that, how many companies integrate golang to theirs web apps. some companies using django in theirs web apps, but after years, they are using golang also in this app. why they decide to use it? if so why they are not migrate to golang totaly.

Does the possible performance improvement warrant the opportunity cost of rewriting code when that time could be spent adding new features that customers will pay for?

2 Likes

is there popular apps which totaly developed with golang?

1 Like

Not end-user applications, but development apps kubernetes and hashicorp tools including consul, normad, terraform, vault are written in Go.

Right - if you have an app that you’ve spent millions developing, it stands to reason it would probably cost millions to port it to Go. You can throw a lot of server power at something for millions of dollars before it becomes problematic enough to do a rewrite in a more performant language/stack. That’s why people aren’t just rewriting every app whenever something new/better comes along. It’s expensive.

Not exactly the situation posed here, but here’s the classic advice against rewriting: Things You Should Never Do, Part I – Joel on Software

Go’s vanilla HTTP library is just very nice, which is not the case with many other languages.
For many use cases, the http package in the standard library is just the optimal perfect choice.

I had the experience of writing an advanced reverse proxy with some complicated logic and I used gin and it worked just perfectly well. But I’m just transitioning that to the standard library’s http package, just because there’s no extra benefit in using Gin, for my use case.
I used Gin exactly ouf of this perception that the standard http library can’t be really that good.
But after all, that may not be the case for your project.

Anyway, if you wanna use a framework, I certainly recommend Gin.

1 Like

tnx for ur answer, which framework best for any kind of project in golang?