Questions tagged [go]
Go, also called golang, is an open source programming language initially developed at Google. It is a statically-typed language with syntax loosely derived from that of C, adding automatic memory management, type safety, some dynamic-typing capabilities, additional built-in types such as variable-length arrays and key-value maps, and a large standard library.
175 questions
5
votes
2
answers
1k
views
Repository and Service Interfaces in an Accounting Software in Go with Uncle Bob's Clean Architecture
I'm trying to get hands-on experience with Uncle Bob's Clean Architecture in Go, but I'm running into some issues. Also, I'm not yet familiar with all of Go's idioms.
For testing purposes, I'm ...
4
votes
2
answers
694
views
why would one use the "Functional Options" pattern in go?
I just learned about the Functional Options pattern in golang.
what are the benefits of using it over just allowing to pass a config struct and just overriding the default values provided in the ...
1
vote
1
answer
113
views
Go, Error Handling, and Big Text Files - express error semantics in types
The title Go, Error Handling, and Big Text Files is a blog post from Wesley Aptekar-Cassels from 2021. In this blog post he reports about a problem he faced parsing long text files. He tried
scanner :=...
1
vote
1
answer
506
views
How to handle different json response for the same api rest endpoint and different http status
I have an endpoint similar to GET ../produtcs/123 where 123 stands for an ID. The REST service response
with either status 200 and a json object A {"deliveryData": {"status": 200, ...
1
vote
1
answer
258
views
Is there any logical reason to "store" just one object file (.o) into archival file (.a)?
As far as I understand (not much), the archival .a file is just, roughly speaking, the collection/batch of object .o files. It's like a library of compiled code that can be cached and which can be ...
0
votes
2
answers
242
views
Seeking a Third Opinion on Kafka Consumer Implementation and Architectural Disagreements
I've been at my current job for about 4-5 months, mainly working with Go, and I have no prior experience with Kafka. Before this, my background was in JavaScript, Node.js, React, etc. I recently got a ...
1
vote
1
answer
132
views
Return function after kicking off background process
I have a process in golang that I want to kickoff through a RPC call but then have the function return early whilst the process continues in the background. Specifically it’s just a basic db transfer ...
-2
votes
1
answer
540
views
Go’s answer to c10k problem
I have few questions on the go's answer to c10K problem. How is an event loop different from the network poller described in this blog?
I see a striking similarity between waiting threads and waiting ...
1
vote
0
answers
134
views
golang: pattern for handling message queues? Are named functions anti-idiomatic somehow?
Had a discussion today in how to implement services that work with messages coming in from event queues. We call these services processors. One of us argues for using several functions, while the ...
0
votes
4
answers
3k
views
Should Golang 'private' methods need unit tests?
I'm relatively new to Go but I come from a C#/OOP background where unit testing private methods isn't something that's generally done. I currently have a senior developer telling me it's "bad ...
1
vote
1
answer
214
views
High Throughput Concurrent Map Access and Periodic Updates Causing Contention and Latency Spikes
I am working on a Go application where two concurrent maps, products and productCatalog, are accessed by numerous threads in live traffic to retrieve data at high throughput. These maps are populated ...
0
votes
0
answers
105
views
Domain-Driven Design: Storage layer and MySQL client
I'm very new in DDD and I was following one of the videos of GohperCon to structure of my Golang App using DDD with Hexagonal Architecture. At the lowest (deepest) layer is the storage that can be ...
1
vote
2
answers
1k
views
design pattern to avoid deadlock with mutex in golang
What would the appropriate design pattern to avoid deadlock when several functions use the same mutex ?
It is quite easy to forget what method uses the lock and so it happens that you call a function ...
0
votes
1
answer
600
views
Cheap But Effective Solution for Logging in a private rest microservices backend api
I've created a backend following a microservices architecture and now I need to implement logging.
my understanding
After reading some articles about this topic, I've listed below some "pretty ...
3
votes
1
answer
395
views
How are interfaces implemented behind the scenes in the Go language?
I have read this article which indicates a double tuple structure, but it is unfortunately light on implementation details, which is what I am looking for.
So... how are interfaces implemented in Go?
...
0
votes
1
answer
408
views
Cron job to read multiple "entities" from the database
I have one microservice (in GO) that needs to read a whole table every hour, filter out some data and send it to another application.
So as an example, imagine I have the following model:
type User ...
1
vote
1
answer
362
views
Creating a new type as slice of strings in Rust?
I have a little bit of experience with Go, that I have been trying to use as a reference point to wrap my mind around Rust via a cards game I wrote in Go that I would like to now write in Rust.
I know ...
0
votes
1
answer
601
views
Making side effects explicit even in non-pure functions
I try to have as many pure functions as possible, but if I can't, I at least try to make the side effects as explicit as possible.
Here is an example (in Go)
type State struct {
count int
}
func (...
1
vote
1
answer
435
views
How to solve duplicate request with Distributed Lock Management in Golang
I’m trying to test concurrently request (brute force test), with 1000 request/sec (same request id). I’m using Rest API.
The service running on distributed system, I’m using 3 pods.
The problem is I ...
0
votes
1
answer
2k
views
Why is Java AOT compilation (using graalvm native-image) so much slower than golang compilation?
I followed the guide here https://quarkus.io/guides/building-native-image to set up a minimal quarkus webservice graalvm native image. Ran command 'time quarkus build --native' to compile the example. ...
-3
votes
1
answer
169
views
Using two different languages where one would suffice for the task (microservices)
I previously asked this on StackOverflow, but doesn't fit there and I was suggested to move it here.
I was thinking about using two seperate backend languages for seperating concerns in a project of ...
-1
votes
1
answer
234
views
Writing a API for a hardware device for mutliple platforms
We want to create an API to communicate witha device we currently sell.
The API should be available for several platforms like C / C++ / .NET / Python and available for Windows and Linux.
The idea is ...
0
votes
2
answers
1k
views
Golang interface-implementation circular dependency
In trying to separate interface from implementation, I ran into a circular dependency problem.
There is a best practice in the world of Java: consume interfaces instead of concrete classes. That is, ...
0
votes
0
answers
431
views
Why doesn't golang have a version number built into go.mod
I've recently been learning go and the versioning system seems rather odd to me. Most languages / dependency management systems that I'm familiar with (like rust and cargo) have an explicit way to ...
2
votes
4
answers
1k
views
Is it ok to test an external function?
I have a utility function called connectToMongoDB() which connects to MongoDB. Basically, it creates a client for MongoDB and returns that.
I'm making a library and I'm thinking of unit testing the ...
4
votes
5
answers
2k
views
(How) can the circle-ellipse problem be solved by using composition rather than inheritance?
I was reading about composition over inheritance and came across a question about solving the Circle-Ellipse Problem in Object-Oriented Programming. This kind of problem is often used as an example of ...
1
vote
0
answers
182
views
Managing user session state with Google Sign In
I need some help with my authentication design. Happy to share any code as needed...
Overview
I have implemented the Google Sign-in (new web implementation here) button in my client web application. ...
2
votes
1
answer
190
views
How do we maintain consistent-read promise to clients + handling ID collision when using a fallback queue?
In my company, we are using Event Sourcing pattern to implement a storage for all changes to the price of a booking. Across the company, different services might try to append events to a booking ...
4
votes
2
answers
363
views
How to structure many complex conditionals on a class
I have a class (as a protobuf) OrderChange, that represents when an order (imagine Amazon.com) changes:
message OrderChange {
Order old_order = 1;
Order new_order = 2;
}
message Order {
...
1
vote
0
answers
332
views
Managing concurrent TCP connections with Go, Docker and Kubernetes
I need to consume several APIs concurrently. In order to do that I decided to containerize each API client code and manage them using Kubernetes. Some of those APIs need to be "walked". They ...
0
votes
2
answers
2k
views
Golang Design Pattern for Generating View Objects in a REST API?
I have moderate Golang experience and lots of experience in other programming languages such as Java, Python, Rust, Scala, and others. I'm comfortable with building REST services and most of the other ...
0
votes
1
answer
504
views
How to properly notify a client from the server side in Golang (broadcasting)?
I'm working on a project which focuses on simple HTTP-related actions (to get my feet wet really). I'm using the net/http package, which I thought was very convenient for almost all requirements ...
0
votes
0
answers
215
views
What is considered as best practice for defining common types in golang?
We have set of common types (mostly structs, scalars, string IDs) that are used across different packages in a project written in Golang. Currently we define them in a package named "models" ...
1
vote
1
answer
236
views
Should I cover code that should not be able to fail with tests?
I'm asking myself above question since I implemented an API that accesses a third-party API and currently write tests to increase my code coverage in the class that communicates with the third-party ...
-3
votes
1
answer
426
views
Is Go's concurrency model suitable for distributed systems and for microservices?
In Programming Distributed Computing Systems:
7.3.4 Distribution
Distributed computing is inherently concurrent. However, distribution
aspects go far beyond concurrency. Of particular importance from ...
11
votes
1
answer
3k
views
Why Golang projects seldom use mocking library in testing?
New to golang and is now researching on how to do test in golang. I see that there are popular mocking library like gomock. However, at the same time, I see that large golang open source projects don'...
67
votes
9
answers
9k
views
Why do "checked exceptions", i.e., "value-or-error return values", work well in Rust and Go but not in Java?
Java has "checked exceptions", which force the caller of the method to either handle an exception or to rethrow it, e.g.
// requires ParseException to be handled or rethrown
int i = ...
1
vote
1
answer
345
views
SPA browser-based routing: external routing table for both frontend (React) and backend (Go) use
I have a Single Page Application that uses React-Router and is served via Go backend. The pre-built static app is accessible at app.com which then uses app.com/api to load dynamic data.
If a user goes ...
2
votes
1
answer
158
views
Golang / React Webapp Architecture
A project is structured as so:
A build server listens to changes in two repositories: a frontend and backend repo. When it picks up a change it builds, tests, and deploys the updates to a production ...
0
votes
1
answer
695
views
Correct Architecture for Monolith with Go
I'm designing a monolith RESTful API that potentially sometime in the future may turn into microservices. I'm also trying following Uncle Bob's clean code as well. My question lies in structuring the ...
0
votes
1
answer
92
views
Pubsub model - publisher broadcast to remote subscribers
With a single publisher(go-routine) and multiple subscribers(go-routine) on same machine, below message hub help create pubsub model:
type PublisherHub struct {
subscribers map[*subscribmediator....
63
votes
10
answers
26k
views
Does it ever make sense to use more concurrent processes than processor cores?
I've got some process in Go. Here's an example counting lines in text, though the question is meant to be far more general than this particular example:
func lineCount(s string) int {
count := 0
...
0
votes
1
answer
639
views
Race conditions in API calls within Golang microservices
I have a microservice architecture running on Heroku. I am having some problems handling race conditions.
The problem is, that service A:
Needs to fetch the user's balance through an API call to ...
3
votes
1
answer
1k
views
How to test channel pipelines in Go
I use the "channel pipeline" pattern quite a lot in Go, which looks something like this:
// getSomeNums spits out ints onto a channel. Temperatures, pressures, doesn't matter
func ...
1
vote
0
answers
80
views
Issues Regarding Data Model Abstraction in Golang
I am currently writing a quiz web-app with a React front-end and a Golang backend, with a PostgreSQL database to keep track of the quizzes, the questions on the quizzes, and the choices in the ...
2
votes
2
answers
236
views
Ease testing with complex setup scenarios
Within our codebase we have integration tests like these:
func TestActivateSuspendedFoo() {
// setup all dependencies
baz := jsonToStruct(
"baz": {
"a": ...
1
vote
0
answers
54
views
Offloading database joins to IOT devices
Solution as it is right now
I have this solution where I gather information from a proprietary product of a different company in various sites. The solution is based on a single go binary that ...
1
vote
1
answer
1k
views
Modbus over TCP concurrency pattern
I'm trying to learn about MODBUS as a free-time project. It is a long standing desire to write my own driver in Golang. That being said, I'm now trying to design the concurrency model for device ...
1
vote
2
answers
169
views
How to agree on message schema in a Publish–subscribe pattern
I'm working on a project that uses PubSub(GCP), my question is not specific to GCP, it's more regarding to the architectural pattern(I'm used to statically typed languages, and I have a hard time ...
0
votes
1
answer
552
views
Go (Golang) efficient logic processing in a chat system
In order to build a messaging app, I have followed this example : https://github.com/gorilla/websocket/tree/master/examples/chat
This consists of a Hub, running in a single goroutine in the program, ...