47 points · by Cwizard · 4y ago · 49 comments
It's been great. We don't use any frameworks, just the http package. It's blazing fast and highly reliable (low bug occurrence and easy refactors due to the safety provided by strong typing).
1. How do you handle DB interactions? A data mapper/repository pattern?
2. Do you have a service layer to coordinate between the different "inputs" (the REST API, event processing, and scheduled jobs)
3. Is this REST API used by a web front end or other services? Interested in how people handle token auth and/or using session tokens.
I've been reading about architecture patterns more and I've realized which patterns I've used without knowing it, so now I'm interested in how others handle similar situations in different languages and ecosystems.
- I didn't love the Java tooling at the time. Maven for example. - I don't love OOP. Go has just enough OOP patterns for me.
I tried Go as an experiment, but didn't know it would become my go-to language. What I found was super fast build times (big win), built in testing, and a simple language that almost anyone can understand (versus the relative sophistication of something like Scala).
Now that's out of the way, yes. We use Go for both API and web development, actually full stack WITHOUT any JavaScript. We have written a custom error handler that deals with runtime HTML template errors, if any, which improves the otherwise tedious work when a template makes the web service crash.
Go is superb at HTTP and all web related. We still have some PHP development, but would very much like to do Go all the way, we just haven't gotten there yet.
Last, but not least, we do not use any frameworks or libraries, only the Go standard library and we love it. No matter were we put it, it just always works and is very performant.
I see how under that definition an API can't be RESTful, but what service then can be? And how do clients interact with it?
Not OP, but there was an interesting article & discussion recently here: https://news.ycombinator.com/item?id=32141027
An example response could be
{
name: 'john',
nickName: 'johnny',
relatedEndpoints: ['/v2/friends', '/v2/jobs/', ...]
}
Or one could include a link to an Open API spec for the API in the response of every request that details all endpoints available and their parameters/bodies. {
name: 'john',
nickName: 'johnny',
apiSpec: '/v2/open-api-spec'
}Do you use internal libraries?
This also removes any problems with third party dependencies that suddenly gets abandoned yet still have serious issues, supply chain attack problems, etc.
We have also found that most third party libraries tries to be (more or less) general purpose, so they often contain lots of stuff we would never need, so we prefer to e.g. write our own specific code.
The way we work require a little extra effort because we write the things we need our selves, but of course we reuse our HTTP handler code, our custom runtime error handler code, etc., from project to project, but in general the benefits far outweigh the cost in our experience. The fewer dependencies, the fewer problems - and Go shines in this because of how much is covered in the standard library.
https://www.unixsheikh.com/articles/no-your-api-isnt-rest.ht...
The author got Roy T. Fielding, one of the principle authors of the HTTP specification and the originator of the Representational State Transfer (REST), to comment on this issue by email (was since removed when the author changed his blog).
However, if you ask people that switched away from Go, then you will see responses that also match that expectation.
So it really is down to your preference.
Today, I would go with Rust instead because of personal preferences. But if my code base has to be shared with not very experienced developers, perhaps Golang again.
Because of the stable nature of the base language and library, and the way libraries are imported, with multiple pinned versions allowed and without import loops, it gives better longevity to "set and forget" type back-end services.
I rarely have a problem when coming back to work on an old project, it still compiles and even updating dependencies is usually fine.
This helps with the problem of back-end services becoming "forgotten children" that don't receive attention for extended periods.
That said, being able to use pprof to debug and the single binary deployment makes life really easy.
Should be gofiber.io
Which generators do you use to transform the OpenAPI spec?
I have been using Java for a long time but will soon be using Go because of a job change and I am trying to get a better sense of the trade-offs and advantages.