The term sometimes used for the Go Programming Language, since searching for just Go is usually too broad.
Questions tagged [golang]
38 questions
61
votes
10 answers
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
for _, c := range s {
if c == '\n' {
…

TheEnvironmentalist
- 1,159
- 1
- 8
- 14
35
votes
4 answers
How much is Google investing in the Go language?
I have read quite a bit about the Go language, and it seems promising. The last important bit of information I am missing before I decide on spending more effort on the language is: How much money/man power does Google or other companies invest in…

David
- 4,449
- 6
- 35
- 48
15
votes
5 answers
Use of "this" in Golang
On the closest thing Golang has to a style guide found here, under Receiver Names this is written:
The name of a method's receiver should be a reflection of its identity; often a one or two letter abbreviation of its type suffices (such as "c" or…

Adam
- 1,367
- 3
- 12
- 15
11
votes
1 answer
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't use any mocking library at all. For example,…

cytsunny
- 627
- 6
- 19
9
votes
1 answer
How to structure a Go application, architected according to the clean architecture
I'm trying to build a project using the clean architecture, as described here. I found a great article on how to do this in Go.
The example is a very simple one, and the author puts their code into packages named based on the layer they are in. I…

bigblind
- 1,415
- 1
- 13
- 17
6
votes
1 answer
How to test interactors in clean architecture?
After reading the last book from Robert C. Martin, I've tried a to develop some big Go applications following clean architecture.
While writing interactors, I end up with a lot of complex unit tests, because the interactor has a lot of external…

luistm
- 163
- 5
5
votes
6 answers
Flow control in Go without a for loop
I've been set a challenge that I'm trying to get my head around, but am struggling with the best (or 'correct') way to implement it. The challenge is to create a simple console app written in Go that calculates the sum of squares of n numbers.…

Hexodus
- 77
- 1
- 3
3
votes
4 answers
(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 the limitations of OOP. I am from a C++ and…

drkvogel
- 147
- 3
3
votes
1 answer
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 getSomeNums(ch chan<- int) {
// Imagination goes here
}
//…

Tal
- 141
- 3
2
votes
1 answer
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?
Pure guesswork on my part:
It cannot be a…

SRNissen
- 151
- 5
2
votes
1 answer
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 identified by a booking code.
We use DynamoDB to…

JamesBoyZ
- 245
- 1
- 7
2
votes
1 answer
Building object with arbitrary functionalities
I am trying to look for the right design pattern for the below scenario.
I am trying to create an object/binary with different modules, a module is a functionality that I want to provide to that object. Examples of a module are like reading a file,…

Timothy Leung
- 131
- 4
2
votes
1 answer
Best Possible Way To Write Unit Tests For HTTP Middleware
I am using this go library(https://github.com/abourget/goproxy) to create a custom proxy server app. The app is utilizing several middleware of the following form:
MyMiddlewarFunc(ctx *goproxy.ProxyCtx) goproxy.Next {
if…

Rana
- 141
- 4
2
votes
1 answer
TDD Duplicate Testing on Related Classes
In following the principle of testing only the exported functions on a package (using Go - or for others languages, the public functions on a class), I'm running into a scenario where related packages are causing the code base to be tested multiple…

Andy Brewer
- 23
- 2
1
vote
2 answers
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 that do a mutex.Lock() inside a function that…

cylon86
- 111
- 3