Questions tagged [golang]

The term sometimes used for the Go Programming Language, since searching for just Go is usually too broad.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
101 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 ...
user avatar
  • 99
0 votes
2 answers
99 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, ...
user avatar
  • 109
3 votes
4 answers
355 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 ...
user avatar
  • 147
2 votes
1 answer
137 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 ...
user avatar
  • 245
0 votes
2 answers
476 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 ...
user avatar
  • 1,561
0 votes
0 answers
66 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" ...
user avatar
9 votes
1 answer
1k 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'...
user avatar
  • 607
59 votes
10 answers
23k 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 ...
user avatar
0 votes
1 answer
308 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 ...
user avatar
3 votes
1 answer
261 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 ...
user avatar
  • 141
1 vote
0 answers
36 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 ...
user avatar
  • 225
0 votes
1 answer
68 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 ...
user avatar
-1 votes
1 answer
130 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 ...
user avatar
1 vote
0 answers
121 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 ...
user avatar
  • 111
0 votes
1 answer
173 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 ...
user avatar
  • 113
2 votes
1 answer
88 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 ...
user avatar
1 vote
1 answer
558 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 ...
user avatar
5 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, ...
user avatar
  • 153
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 ...
user avatar
  • 1,415
-1 votes
1 answer
280 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 ...
user avatar
  • 129
1 vote
0 answers
148 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 "...
user avatar
  • 127
1 vote
2 answers
212 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 ...
user avatar
1 vote
1 answer
170 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/...
user avatar
  • 11
0 votes
2 answers
99 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 ...
user avatar
5 votes
5 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 ...
user avatar
  • 77
1 vote
1 answer
558 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 ...
user avatar
  • 21
-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}, {"...
user avatar
2 votes
1 answer
647 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....
user avatar
  • 141
0 votes
3 answers
249 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 ...
user avatar
  • 103
2 votes
1 answer
206 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 ...
user avatar
-8 votes
1 answer
353 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 (...
user avatar
  • 1
15 votes
5 answers
19k 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 ...
user avatar
  • 1,357