HACKER Q&A
📣 iio7

Are you using Go for web development?


If so what is your workflow and what do you use? What do you find most difficult, if anything?


  👤 zserge Accepted Answer ✓
I start small: vim, makefile, bare Go with no dependencies. I add things only if they improve the end product from the consumer perspective (either FRs or NFRs). I even used to deploy things as systemd services, unless containers make things easier to more scalable. For the frontend I couldn't be happier since I discovered "esbuild", which is written in Go and has unbelievable performance.

I tried to describe my humble workflow here with a few code snippets: https://zserge.com/posts/go-web-services/


👤 boyter
Yes. Nothing fancy from workflow. I pay for and use Goland because I find it so good for refactoring... worth the expense over VSCode.

Generally I use standard library, with the exception being github.com/gorilla/mux Gorilla Mux for routing because it removes so much boilerplate.

I do however use Python for all HTTP integration tests. With requests + voluptuous its so much more productive than doing them in Go, which I had previously done.


👤 davidbanham
Yep. I write code in vim, run tests and orchestrate things with Make and I deploy to Google Cloud Run. I used to use k8s.

I write monoliths and render mostly HTML back to the client. I have a few json endpoints around for m2m APIs or to power search boxes here and there.

The main thing I’m hacking on at the moment is https://clubman.app other things are listed at https://notbad.software

A relatively up to date skeleton of my apps is at https://github.com/davidbanham/doubleboiler


👤 arcatech
Yup.

My personal website was built using Go and Postgres. I did a lot of it from scratch using the standard library and very few dependencies.

I have my own deployment process using a makefile, git tags, and rsync. Migrations are just a set of sql files checked into the project.

This works pretty well for me since I'm the only developer on the project.

Here's my "tech" page with some information on the website: https://dwayne.xyz/tech

And the portfolio page for the website (on the website): https://dwayne.xyz/project/dwayne.xyz


👤 jrumbut
I've created or inherited a few small web services (small, self-contained pieces shared by multiple apps or broken off for load management reasons). I would say Go is pretty good for this, some very nice performance wins were had easily.

I have very little temptation to use it for a whole application though. Unless you are already a Go shop I would advise anyone to just get better at making Ruby, Python, PHP, or JavaScript back ends that are more performant.


👤 potta_coffee
I enjoy Go for web development. I pretty much use the standard libary + Gorilla. I have few complaints, it's a little more verbose than Python but it feels more robust, easier to deploy and I like the performance. The code is easy to read.

👤 zhb
Working on a new project and part of it is web development, we're moving forward with some pain.

We use Fiber (https://gofiber.io) as web framework and Pongo2 (https://github.com/flosch/pongo2) as template engine. The Go/Fiber parts are ok, the pain is template engine.

- Pongo2 syntax is like Django/Jinja2, but not as easy as Jinja2. I use Python+Jinja2 for years in production, it's so easy to use and troubleshoot.

- No builtin i18n support. You can find some blog posts or articles introduce pongo2, but no one mentions i18n support/implementation like no one need it. We implemented our own i18n support, but still need a tool to extract strings from template files for translation.

- The macro syntax doesn't support specifying argument names while calling. e.g. `{{ my_macro("a", "b", "c") }}` is ok, but not `{{ my_macro(name1="a", name2="b", name3="c") }}`. It's hard to organize reusable HTML/CSS code snippets.

- Sometimes the custom macro is correct (syntax part), but it renders nothing in output html, but if i add the same pongo2 code in its own unittests files, it works. Didn't find a way to troubleshoot, no clue at all what the problem is.

Anyway, Go itself and the web framework are very good for web development now, just miss a Jinja2 for Go.


👤 mariusor
I work on a personal project split into multiple packages totaling about 60k lines.

The end result are two web applications that work as a backend and frontend for an ActivityPub link aggregator (similar to HN and old redddit).

I mostly develop in Goland as I use the debugger extensively, and I didn't want to spend the time to learn to use delve in the command line.

I tried to keep as much as possible a handmade approach, so I'm making use of the standard library over more fancy packages or frameworks.

In my specific case the biggest issue I had was with the protocol itself (ActivityPub) which allows for a large degree of flexibility in the structure of the JSON objects it passes around, a lot more than the default encoder in go allows for. I had to implement my own functionality for encoding/decoding JSON objects, and I'm currently working on adding similar functionality for binary encoding.

Links to the projects you can find in my bio.


👤 hactually
Got a small starter template I use but it doesn't do much more than basic format/structure for db patterns etc.

Tools wise we use VSCode, have a good local Dev story and we migrated from sqlx to sqlc recently to speed things up.

We use gorilla mux and build API first with Vue for frontend. Really clean and simple stack with few moving parts.


👤 majodev
Yes, monolithic Go RESTful JSON API services - we currently depend on go-swagger, SQLBoiler (PostgreSQL) and echo.

Workflow: we use VSCode with devContainers (docker-compose local dev env), our tasks are simply defined in a Makefile. Our high-lvl dev workflow is documented here: https://github.com/allaboutapps/go-starter/wiki/FAQ#how-does...

Difficulties: Nothing special actually. We switched from Node.js to Go in the beginning of 2020 and it's been a pleasure for our new projects (software agency). I thought it was going to be hard to onboard our staff / new hires to Go and our stack, but this really turned out to be a non issue.


👤 fileeditview
I used Go to create different web apps. One example would be https://namesmith.io (shameless plug), which I created with the Revel framework.

Revel is often seen as anti-idiomatic because it's a whole framework but it is nice to get a web app going pretty fast (with Go). These days I have a lot more experience and I probably would choose echo or something similar. Not because I think that Revel is bad but because I have a lot more freedom with those.

For editing I mostly use Vim.

Generally I would say if you create web apps maybe choose something different from Go. It certainly can be easier/more comfortable. For APIs it's still great and one of the best choices IMO.


👤 closeparen
Go is a little low-level/obtuse for business logic and UI stuff. We use it for many of the gRPC services that our web apps consume. The more systems-y the service, the better the fit.

👤 maxekman
Consultant using Go in a few client projects. Both use build-in-Docker for stability and less CI surprises. One uses GRPC with Profobuf, another is using an event sourcing toolkit I have authored [0]. Personally I use VSCode with gopls which has been working great for quiet some time now. Ordinary make files for combined documentation and usage of common operations.

[0] https://github.com/looplab/eventhorizon


👤 floren
We use it. Gorilla mux (https://github.com/gorilla/mux) to route requests plus some in-house handler chains that log, check JWT tokens, etc. We have a Go client library which accesses the web API, so we can do testing without having to involve the frontend team; a combination of tests in the client library and some judicious curl commands is usually enough.

👤 santamarias
Yes, chose Go over Rust for a prototype API backend because Google Cloud docs offers code examples in Go :p Satisfied with Go performance, strongly prefer Goland over VS Code for better debugging. Considering switching to Java or .Net for the remaining logic development, I would (perhaps naively) like to explore functional programming patterns and the potential benefits of a "larger" ecosystem (Spring Data JDBC for example).

👤 misframer
Yes, both for personal projects and at work. I write APIs in Go (and there's React on the UI side that talks to it). I use VS Code to develop and build as a Docker image.

At work the images are deployed on DC/OS, and for my personal projects I use Docker Compose.

The most difficult part (which isn't really that difficult) would probably be the actual deployment part, and that's not specific to Go.


👤 taklimakan
Yes, we use go-gin for HTTP servers and middleware (really fast and easy to use) and gRPC+Protobuf for backend services with database access. For the frontend, we have one project that renders HTML just with Go templates, but that’s kinda clumsy and awkward to maintain. Our main webapp is built with Vue.js, and the gin server only checks auth and serves the index.html

👤 RSHEPP
Pretty much write my services following this

https://pace.dev/blog/2018/05/09/how-I-write-http-services-a...

Use sqlx to extend the std lib.

Have dropped using an orm.


👤 weitzj
IntelliJ Ultimate with the Go Plugin. Sometimes vim-go.

The api is defined with gRPC.io and offered as a gRPC api as well as a Rest api with JSON using grpc-gateway. Database is PostgreSQL using pgx. Caching via Resis or memcached. Building testing via a Makefile with junit and cobertura reports


👤 Zealotux
I'm a Node guy and don't know anything about Go, what's the recommended route to get started on Go for the web? Any specific framework in mind? I need WebSockets and I'm guessing Go can provide some good performance improvement over Node there.

👤 srinikoganti
www.stackazam.com is a cloud application built with Go

I have started falling in love with coding/CS again with Go.

Our philosophy is to keep things close to the metal and not use layers as much as possible. Go enables you to follow with approach with the standard libraries that come with the language.

Problem with layers/frameworks is that while they seem to solve immediate problem quickly, layers will rear their ugly head down the road , making you feel helpless during debugging

We use standard libraries

database/sql for database html/template for UI

Only external package used so far is gin-gonic/gin for middleware&routing


👤 unixsheikh
We keep things as close to the bare metal as possible and avoid complex layers as the plague.

We have only negative experiences with frameworks and big layers. They solve problems quickly in the beginning, but they always end up causing problems. Years later, debugging strange errors, security issues, etc. The more layers you add the less useful and good the application becomes.

we use the standard library and a couple of slim and well written external libraries, such as sqlx and go-sql-driver.

I have written my own HTML form validator and custom error handler - once you get that done, web development in Go becomes MUCH easier.

We don't use ANY JavaScript on the front-end unless it is a minor custom enhancement to the UI (it must be able to run without). Everything is pure HTML and CSS.

However, I personally do find the HTML templating tedious, but I have always found templating stupid and annoying, this is not specific to Go. I prefer to write HTML inline in PHP (when I do PHP) i.e. the old fashion way. I hate templating in any language!

It's easy to make mistakes in Go HTML templates, make sure you test that part of your code well!

Writing big web applications from scratch is great though, and it's really fast in Go, faster than PHP, as long as you do it right! Documentation, documentation, documentation. Anyone who inherits your code, whether you're alone or on a team, needs to know and understand your thinking and rationale.

The main reason why projects fail when they build tailor made software is because of laziness regarding documentation.

The correct way is to regard missing documentation as a bug! Write the documentation WHEN you write the code. If you change the code, change the documentation right away, when you can still remember what you're doing and why - this is the most important part and why so many code bases are horrible to inherit. Missing or poor documentation.

Never use "clever" code, make code that is easy to read and understand. Don't worry too much about design patterns and philosophy, they mostly belong in the books and in theoretical discussions!

Web development in Go is not for everyone, it requires experience and thoroughness. The build fast, deploy and forget strategy - that most people use these days - doesn't belong in Go.

Go will reward you in the end with really good performance and very easy future maintenance. Nothing suddenly breaks because a third of the standard library has suddenly been changed in the next version upgrade, such as with PHP.

EDIT: Typo.


👤 quickthrower2
Nah my go to is node, although recently I used a PHP script and the simplicity for a quick job is pretty nice. At work it’s C#

👤 stefanmichael
yes! Jetbrains GoLand helps quite a bit with the more annoying parts of the language (GOPATH, remembering commands for tools, managing go modules, etc)

There are some small things about the language that can feel a little cumbersome (lack of generics for example) but largely happy with the language and the trade offs so far seem worth it.


👤 drakonka
We write most of our backend web services in Go, not really the frontend parts though.

👤 newusertoday
emacs with lsp plugin for development. echo framework for server and standard library for other things.