Questions tagged [golang]
The term sometimes used for the Go Programming Language, since searching for just Go is usually too broad.
40
questions
-3
votes
0
answers
26
views
How do you set up a Go repo to use a private repo in the most convenient way? [closed]
We wish to decrease the amount of duplicate code in our organization, and part of that is to move functionality into separate private repos on github.
We onboard new people, and use a number of ...
1
vote
2
answers
125
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
159
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 ...
2
votes
1
answer
207
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
174
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 ...
0
votes
1
answer
257
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
0
answers
121
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 ...
-1
votes
1
answer
132
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
967
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, ...
3
votes
4
answers
682
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 ...
2
votes
1
answer
156
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 ...
0
votes
2
answers
1k
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
0
answers
78
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" ...
11
votes
1
answer
2k
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'...
61
votes
10
answers
24k
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
476
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
899
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
40
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 ...
0
votes
1
answer
95
views
How should I distribute my app with my own OAuth2 client ID, without letting anyone find it out?
I've written an app using golang which uses OAuth2(Authorization code flow with PKCE) to interact with the Gmail API.
If I build the app using my own client ID then my client ID can easily be found ...
-1
votes
1
answer
139
views
Is there existing technology write code to be executed in response to an email being sent for a certain email? [closed]
Similarly to a rest api, I want a server to listen for an email to an address I have created, and in response to mail being received, run code that I have created. Is this possible already? I ...
1
vote
0
answers
195
views
Can I add new function for protobuf generated struct
I am using protobuf definitions to define message types.
Structure looks like
message1 {
}
message2 {
bytes msg1 = 1
}
So message2 has a field which is a byte array representation of message1. I ...
0
votes
1
answer
198
views
REST API with 1000 query templates?
How do I manage maybe 1000 SQL-queries in a Golang REST API?
My SQL experience is at the upper basic level using Postgresql. I am today using a tool that you can use plain SQL as well as sort of ORM ...
2
votes
1
answer
104
views
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 ...
1
vote
1
answer
663
views
How can a factory method stay true to "Accept interfaces, and return structs" in Golang?
Let's us say I have a package which contains different types of TV structs. Now, based on the parameters passed I would like to return a specific TV type.
How is it possible to return the specific ...
6
votes
1
answer
2k
views
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, ...
9
votes
1
answer
6k
views
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 ...
-1
votes
1
answer
337
views
How to deal with licensing when importing remote packages in golang?
In golang, one can import packages with urls such as import "github.com/foo/bar". Do I still have to include the license of the remote package, as I'm not including library source code directly? How ...
1
vote
0
answers
159
views
Concurrently parsing records in a binary file in Go
I have a binary file that I want to parse. The file is broken up into records that are 1024 bytes each. The high level steps needed are:
Read 1024 bytes at a time from the file.
Parse each 1024-byte "...
1
vote
2
answers
214
views
How can I include common strings (regexes) in several projects written in different languages?
I have a simple Go library (~300 lines, mostly type declarations and nice methods and compatibility methods for gomobile etc., also pretty-printing scripts). The heart of the whole project are two ...
1
vote
1
answer
188
views
How perform automated tests over code that changes a DBMS (throught DML or DDL)?
I'm written a software as an exercise to improve my skills and I ask my self about how to test code that changes a database.
Let the code in my github:
https://github.com/daniloanp/Ensaios/blob/...
0
votes
2
answers
102
views
How can I effectively design password authentication for encryption in my project?
I'm working on a small personal project that involves a user entering a password that would then allow them to view a text file that would otherwise be encrypted.
I'm having trouble wrapping my head ...
5
votes
6
answers
5k
views
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 ...
1
vote
1
answer
629
views
Exposing blocking API in golang?
I have a golang library that abstracts a network service (think IRC-alike). The network server produces events which users of my library should consume. I'm using blocking network calls internally. I ...
-1
votes
1
answer
8k
views
Sorting an array based on another array's order, quickly [closed]
There are two arrays of maps. The first array contains maps of ID values in a specific order (but not necessarily either pure ASC or DESC ordering):
// pseudo code
first := [
{"id": 1},
{"...
2
votes
1
answer
803
views
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....
0
votes
3
answers
252
views
Identical Databases for Multiple Users Reading Efficiency
Our project utilizes a static database (no writes). With many users we don't actually have a problem per se reading it. If a database "locks" per read request by any user, then would it not be more ...
2
votes
1
answer
226
views
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 ...
-8
votes
1
answer
363
views
Golang Testing Process [closed]
I am new to golang and RunC and now doing some research on it as a part of my intership. What kind of contents do the ' _test.go ' functions check during testing a program or a container with Golang (...
15
votes
5
answers
21k
views
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 ...
35
votes
4
answers
6k
views
How much is Google investing in the Go language? [closed]
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 ...