Using golang as front end framework

Hi there,

i want to learn golang but i see no option to use it a fullstack language like javascript. i can build the backend but then again i have to go to react, vue etc to build the front end.

or

is there an actuall tool one can use to make fullstack frontend backend webapp with golang is there an example of a good webapp all built using golang?

thanks

1 Like

I have played with Go both frontend / backend. Still a newbie, but you can check my latest attempt here. No additional framework used. Just standard Go.

hi @Sibert

beautifull ui/ux on top of your golang apps. I am wondering if i can create a website with blog and comments fucntion for users to login and comment and manage the comments. using Facebook, google or custom signup to comment etc. what is your recoemendation for a beginner.

thanks

Hi @Dean_Davidson

the list of availabel frameworks is big, is there a specific tool you can recommend which better from your experience thanks

Thank you! Plain HTML, CSS and Javascript. The Go code is about 10 MB only. No framework. No dependencies. I have used both PHP, Drupal and WordPress earlier. But I do like Go templates and sub templates. The speed and simplicity is the best I have experienced so far.

Sure it is possible, but this will maybe take some time using Go. Using WordPress solutions from the shelf, you can be up and running in a few days.

1 Like

In general the reason you have not seen how to use Go as a full-stack language is generally because Go is not a full-stack language, it is a back-end and CLI language, and there is shines. much better than for example Node and Javascript, IMO.

As they say, “Use the right tools for the job and the job becomes much easier.” Go is great if you want to build an API, or even to serve a Single Page App that uses a front-end technologies such as React or Vue.js for the front-end.

That is not to say you can’t create a website using only Go as Sibert illustrated, but that will have you swimming upstream against a relentless current, assuming you actually want to get something accomplished. Of course if you are just doing the work for learning and exploration sake, more power to you!

And even so it’s not accurate to say that Silbert’s site is 100% Go because he still had to use CSS and JavaScript (https://task.go4webdev.org/js/nav.js) because browsers do not run Go code.

There are a lot of web frameworks for use with Go, but (pretty much) all(?) of them require you to handle the front-end with front-end technologies:

Now you could generate WebAssembly and implement a website completely in Go but you’ve have to reinvent the wheel that React and Vue.js have already invested probably tens of thousands of man-hours into.

That would be like trying to build a new car and building everything from scratch and not using any already readily available off-the-shelf parts. Unless of course you want to be the one to build the Go developer’s web toolkit that does everything that Vue.js and React do but all in Go-generated WebAssembly. If so, good luck and these links might help:

So, as Silbert said, an easy approach is to just use WordPress.

Alternately, if you want to stick with something written in Go you should take a look at the website generator Hugo, which is written in Go. Here’s an article explaining how to create a blog using it:

If you want to actually code in Go (to maybe get experience?) then you could fork Hugo and make your own modifications to it I guess.

But bottom line, unless you are going the route of everything in WebAssembly then you are going to end up having to use front-end tech in addition to Go to build a modern website.

Hope this helps.

-Mike

3 Likes

thanks @mikeschinkel

this was a really detailed response i discoverd new tools i didnt knew exist. i get intrested in golang as i was told it can cover both frontend and backend.

should i use tools like this

as my arguement is if i need to build frontend with react nextjs why not just build the backend with node instead of golang this way one have to manage single resources type js and much easier to manage and learn?

will golang become a full stack language anytime soon or i shoudl abandon golang if i want single frontend backend language.

thanks

It sounds to me that you have made up your mind :-). Node (or Nextjs) / React is a very popular combination. The web part of Go is not that mature, but despite that I think that Go will be my choice. Make a small test site (Hello World +) in both environments, and this will help you to choose. Nobody else can give you a correct answer. It is a personal preference.

Why I will choose Go is because of the capabilities beyond Web frontend.

Gin Framework

Gin is a fine web framework, but it does not handle the front-end (AFAIK, at least), so that’s up to you. Which means you’ll still have to handle the front-end in Javascript.

BTW, if you are looking for web frameworks that handle more of the front-end, look at Buffalo. But still, you’ll likely have to write Javascript.

Will Go become “full-stack?”

I cannot speak for the Go team.

However, I can read the tea leaves. In my estimation — based on the past 10+ years — I would say there is less than a 1% chance the Go team has any plans to optimize Go for front-end development, other than to support WebAssembly.

But hey, I could be wrong!

Why use Go vs. Node?

Why build backend and front-end in different languages? It lets you use the best tool for each job.

With Go you get compiled code in a single executable for ease of deployment, and in most cases faster execution. And you also get type safety, which you don’t get in Javascript (although you can get it with TypeScript.)

Avoid Dependency Hell

Further, you don’t have dependency hell in GoLang anywhere near the way you do with Node; no node_modules directory with an infinite number of files and directories (I exaggerate. Well, only a little):

node_modules suck!

This blog post from a member of the Go team explains in detail why Node dependency management is such as problem and why GoLang is so much better (Note: Read the whole post, not just these headline because reading only the headline might give you the wrong impression of what the problem is.)

Different folks, different strokes

But like Sibert said, it sounds like you’ve already know what you want and that is you want to go with some form of JavaScript. If using the same language is most important to you then have at it. At the end of the day both approaches will allow you to create websites; what works best for you is what works best for you.

But I can say that — having done web development for 20+ years — I really enjoy coding in Go whereas dealing with Javascript and especially Node was always painful to me. So much so that I decided to focus exclusively on backend development (and DevOps) in the past year, and so I no longer do front-end dev, pretty much at all.

For me, life is so much nicer now! And the pay is a lot better, too. :slight_smile:

So it’s up to you to choose what you want. Sibert and I tag-teamed to answer your questions and we’ve given you plenty to go on; now the choice is yours.

P.S. A 3rd Option

But before you go, you might consider a third option. Not as great as Go on the backend, IMO, but better than dealing with Javascript and Node:

#fwiw

Again, hope this helps.

-Mike

2 Likes

Go is great for backend, but is not really designed for frontend work.