Skip to main content

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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
157 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, ...
surfmuggle's user avatar
1 vote
1 answer
208 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 ...
LeaBit's user avatar
  • 151
0 votes
0 answers
42 views

How to handle integration tests for different stages

A test program should post a json object to a rest service OrderRequest and receives an OrderResponse. The test program should tests against the quality assurance stage (qa) and against the production ...
surfmuggle's user avatar
-1 votes
1 answer
135 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 ...
Anatoly's user avatar
  • 264
1 vote
0 answers
67 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 ...
Albert Balbastre-Morte's user avatar
0 votes
4 answers
1k 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 ...
Al_M42KM's user avatar
1 vote
1 answer
166 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 ...
dragons's user avatar
  • 121
0 votes
0 answers
56 views

GoLang for-loop variable scope change and Table driven testing

As I was reading this blog post: https://go.dev/blog/loopvar-preview about scope of loop variables and as I’m trying to learn #GoLang, I asked myself the question: “okay, but is really so common ...
tarilabs's user avatar
  • 101
0 votes
0 answers
76 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 ...
markfw's user avatar
  • 101
1 vote
2 answers
768 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 ...
cylon86's user avatar
  • 111
0 votes
1 answer
392 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 ...
Big_Boulard's user avatar
3 votes
1 answer
300 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? ...
SRNissen's user avatar
  • 161
1 vote
1 answer
306 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 ...
Daniel's user avatar
  • 119
0 votes
1 answer
421 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 (...
AndreaL's user avatar
  • 119
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. ...
vancan1ty's user avatar
  • 119
-3 votes
1 answer
135 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 ...
HackXIt's user avatar
  • 97
0 votes
0 answers
360 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 ...
joshmeranda's user avatar
2 votes
4 answers
849 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 ...
DaCool1's user avatar
  • 37
3 votes
5 answers
1k 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 ...
drkvogel's user avatar
  • 147
1 vote
0 answers
138 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. ...
Zack Shainsky's user avatar
4 votes
2 answers
309 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 { ...
onepiece's user avatar
  • 169
0 votes
0 answers
241 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 ...
beardeadclown's user avatar
0 votes
1 answer
337 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 ...
Chien's user avatar
  • 129
0 votes
0 answers
108 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" ...
oare234's user avatar
1 vote
1 answer
220 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 ...
hullunist's user avatar
  • 137
-2 votes
1 answer
356 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 ...
Tim's user avatar
  • 5,485
67 votes
9 answers
8k 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 = ...
Heinzi's user avatar
  • 9,798
1 vote
1 answer
228 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 ...
Coupcoup's user avatar
  • 200
2 votes
1 answer
149 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 ...
Coupcoup's user avatar
  • 200
0 votes
1 answer
512 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 ...
Gabe's user avatar
  • 127
0 votes
1 answer
80 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....
overexchange's user avatar
  • 2,285
62 votes
10 answers
25k 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 ...
TheEnvironmentalist's user avatar
1 vote
0 answers
74 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 ...
Eddie Hatfield's user avatar
2 votes
2 answers
216 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": ...
Filipe Gorges Reuwsaat's user avatar
0 votes
1 answer
775 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 ...
Tim's user avatar
  • 111
1 vote
2 answers
120 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 ...
alex's user avatar
  • 21
0 votes
1 answer
504 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, ...
BinaryVeil's user avatar
1 vote
1 answer
1k views

exit and error handling in golang

I am new to Golang and I've seen it is very common to check for errors all the time. I am trying to find a way to not have my code polluted with "if error { log... }" or "if error { exit }". What do ...
user3468164's user avatar
3 votes
1 answer
4k views

Golang Interface Design for Multiple Parameter and Return Types

General question how can I design an interface that can support both // v1beta1.Deployment type Deployment struct { metav1.TypeMeta metav1.ObjectMeta Spec v1beta1.DeploymentSpec ...
dotslashlu's user avatar
0 votes
1 answer
144 views

Preferred return type, pointer or value, when the method/function can also return an error

In Go we can choose to make something a pointer or not. We can also support multiple return types. A common signature on functions or methods is: type MyType struct{} // Value Return Type func (m ...
AJ Venturella's user avatar
-3 votes
1 answer
222 views

Receiver parameters in Go

I have no idea where to post this question since it isn't about the Go language specification itself but rather the justification. In the Go language, functions can have receiver parameters to ...
Niklas Vest's user avatar
2 votes
1 answer
1k views

Grouping related types in Go (approximating unions)

Suppose I have a set of related types that are returned by a function, treated as a group and have certain shared features. In a classical OOP I would achieve this by having a base class and then ...
curious's user avatar
  • 33
2 votes
0 answers
116 views

Convert singleton to single instance with concrete Go example

I have been using singletons in the past. However, reading articles like Singletons are Pathological Liars have led me to explore alternatives to singletons. There are a few posts discussion ...
peaxol's user avatar
  • 121
0 votes
1 answer
1k views

Best Way To Take multiple TCP Connections, Read the Incoming Data, and send that Data back into the Main Thread in Golang?

I want to take data from my goroutines and add them back to the main thread/goroutine. Problem is that I need the goroutines to stay open because data can come through the connection at any time in ...
Carter Weinberg's user avatar
1 vote
1 answer
172 views

Best way to deal with multiples projects when using go mod/vendors

I am pretty new with go mod and vendor... I have a project A and a project B out of the GOPATH. I import project A in project B. I own both projects and I modify them. As I use externals packages ...
julien2313's user avatar
2 votes
2 answers
121 views

How do I recover from failed writes?

I'm writing logic for a patchable game, and patching involves modifying multiple files. type UpdateInfo { file string data []byte at int64 } func AtomicUpdate(ui <-chan UpdateInfo) ...
Passer By's user avatar
  • 121
2 votes
1 answer
142 views

How to Avoid Copy Pasting Repetitive Log Calls

Currently working on a Go project of about 10k lines of code. Within the project, there's a logging library that requires a couple steps of initialization in order to actually write to the log ...
max's user avatar
  • 139
1 vote
2 answers
830 views

Domain Driven Design too many structs

I'm trying to apply DDD to a Golang service and sometimes I find that I have too many structs. For example, I need to satisfy the requirements (for simplicity, I reduce the number of required fields):...
Ruben Cervilla's user avatar
1 vote
1 answer
248 views

Is it bad practice to have a helper package in go for testing purposes. Or is this introducing dependence's

I find myself repeating the same code when writing unit tests, for example... When writing functions that work with files, In the setup for the test i often write some code to create a file (in a ...
user3755946's user avatar
0 votes
1 answer
422 views

Why do new language versions typically use an early compiler version for the bootstrap compiler?

Wikipedia describes a bootstrap compiler to have these properties: An initial core version of the compiler A minimal subset of the language to be used by successive compiler versions Everything I've ...
progner's user avatar