Questions tagged [go]
Go, commonly referred to as "golang", is a fast, statically typed, compiled language created by Google. The language was initially developed as an alternative to C++ for server infrastructure and has native support for concurrency.
581 questions
-2
votes
1
answer
138
views
Go response JSON unmarshalling [closed]
Pprof Profiling Snapshot
I have a critical user facing Go API in which I call an internal API. The API response time is <200ms but the response unmarshalling with goccy JSON is taking 500ms. The ...
-1
votes
1
answer
99
views
How to structure payment system code in golang? [closed]
sorry for my English. I create paysystem. I want to structure the project based on https://github.com/golang-standards/project-layout. I would also like to hear general comments on the code. Thank you ...
5
votes
2
answers
151
views
Command-line Tool That Reads a Text File and Calculates Basic Statistics
TLDR: First time dev in Go moving from Java and I need feedback on my simple CLI Tool.
I wanted to get competent in Go as a very junior developer, so this is my first basic project in go. I set a goal ...
7
votes
3
answers
1k
views
C++ implementation of Go inspired cancellable context
I am trying to create golang inspired cancellable context in C++ for use in worker threads and other tasks. I have tried to avoid using raw pointers, but ever since I started writing C++ code, I ...
5
votes
1
answer
146
views
Default methods for embedded structs
I am learning Go by working through programming puzzles.
There is shared boilerplate between puzzles that I want to factor out into into some kind of helper structure:
Read the input (always the same,...
1
vote
0
answers
91
views
Generic sync.Map in Go
In one of our projects it became rather painful to use the Go standard library's sync.Map as it lacks type safety, i.e. it became rather tedious to do and check ...
4
votes
1
answer
122
views
Golang application: TCP listener to receive in HL7 messages
I wrote a small (~350 lines) golang application mainly for fun to explore the language. I was wondering what the standard layout of a little testing tool like this would be from a seasoned golang dev. ...
4
votes
1
answer
113
views
Go Program for Concurrent FHIR Resource Uploads – Does it Achieve True Concurrent Requests?
I’ve developed a Go program to benchmark a FHIR server by uploading a dataset of FHIR resources concurrently.
The goal is to stress-test the server by sending a specified number (...
1
vote
1
answer
297
views
golang - Kth largest element in an array using quick select - time limit exceeded issue
I am trying to solve the following problem in leetcode.
https://leetcode.com/problems/kth-largest-element-in-an-array/description
Given an integer array \$nums\$ and an integer \$k\$, return the \$k^\...
3
votes
2
answers
231
views
Data pipeline that handles errors and cancellations
I have code that concurrently reads data from a stream, processes elements, and writes the data to another stream. Each of these individual operations may fail, in which case I want processing to halt ...
2
votes
2
answers
175
views
Handling lock release in a goroutine with timeout
I have a scenario where I need to acquire lock on a resource inside a goroutine and release the lock (only once) after a timeout or when the goroutine is done with it's job.
I came up with a way to ...
1
vote
1
answer
70
views
Distributed locking with fencing token implementation in Golang
I was reading about the implementation of distributed locks where we need to verify the lease using a fencing token as per this article - https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-...
1
vote
1
answer
161
views
Bird struct and other type of birds
I am learning Go and trying to write a Bird design in Go. Here is the code. How can I improve it?
bird/bird.go
...
4
votes
2
answers
224
views
Golang Optimize Unzipping FiIes
I have been working on optimizing some code I use for compressing images and linting content in epub files. I originally used cli utilities to help get the job done before moving to using Go code as ...
5
votes
1
answer
297
views
String character changes (case insensitive) - Go
I saw this question on one of the socials, presented as an Apple interview question. I have had to paraphrase as it was not given in text format. (Credit: Instagram @greghogg5)
Given a string (S) ...
2
votes
1
answer
88
views
Application that interacts with a remote GitHub repository with retries
I came up with the logic for an app that talks to a remote GitHub repository using below. I tried to stick to Go best practices and approaches, but would like to identify bottlenecks and adopt better ...
1
vote
1
answer
130
views
Linux terminal like parsing
I'm creating a program that will hopefully operate like linux terminal (basic commands) for learning purposes.
...
1
vote
1
answer
164
views
A very simple secrets cache
This package is a part of a web application which is an internal company tool. This web application may need access to a number of secretes stored in hashicorp vault. The secrets rarely change, ...
4
votes
1
answer
139
views
Parallelized merge sort implementation in Go
I'm currently learning Go. To enhance my understanding of Go goroutine, I write a parallelized version of classic merge sort where I try to split the workload into parallel goroutines.
Implementation
<...
1
vote
1
answer
399
views
Gracefully shutdown http.Server{}
I want to learn the proper way to gracefully shutdown a http.Server{}. Some answers I found would not handle ctrl-c signals. ...
1
vote
1
answer
279
views
golang HTTP client that follows pagination header
I'm new to Go from another language and I'm most interested to know if this implementation has anything that's not idiomatic Go, but any feedback is welcome and you're not going to hurt my feelings by ...
0
votes
1
answer
70
views
Aggregate transactions in slips
I wrote code to aggregate transactions in slips. I'm concerned with the performance of my code because it uses 3 loops that are nested so the time complexity will be cubic. This code won't scale well ...
0
votes
1
answer
104
views
I have use this approch in my golang mongo REST APIs' DAO layer, need to clarify this is a good way or not
I have used this approach in my Golang MongoDB REST APIs' DAO layer, I need to clarify whether this is a good way or not, code is as follows,
...
2
votes
3
answers
480
views
Idiomatic retry loop in Go
I recently started taking on the Gossip Glomers distributed systems challanges as a way for me to practice writing Go and learn something new. In order to solve one of the challenges, I had a request ...
3
votes
0
answers
96
views
CLI app to spin up a Docker cluster
This is my first Go project. I've written a CLI app to provision a database cluster on docker containers. Since it's a distributed database, you can configure per-node services. For example: to ...
0
votes
1
answer
80
views
Golang: package setup to orchestrate initialization
The following code implements a package, which can be used to execute functions in the correct order based on dependencies.
Example:
...
1
vote
1
answer
191
views
Implementation of a lock free queue using CompareAndSwap in Go
Here is my implementation of a lock free queue using CompareAndSwap operation.
...
3
votes
1
answer
368
views
Determining if a file is UTF-8 text by looking at its first n bytes
I'm trying to find out whether a particular file is UTF-8 encoded readable text, by which I mean printable symbols, whitespaces, \n, ...
1
vote
1
answer
201
views
A producer (mapper) and consumer (reducer) problem with concurrency in go with race conditions
Link to go playground https://go.dev/play/p/ctQDpDW6pui
This code has been based on suggestions and conversations in this thread here
Architecture:
A read method creates a channel shared with ...
2
votes
1
answer
271
views
Golang waiter implementation pattern
I'm working on a simple waiter implementation, waiter - is a code that polls an external API until a desired response is received within a given period of time. I would like to keep it simple, but at ...
2
votes
1
answer
202
views
Remove unwanted chars from CSV header as it's being read
In trying to answer this question on StackOverflow about using the gocarina/gocsv package to read a CSV with a header column name that has a comma, I got to thinking about how to preprocess the first ...
0
votes
1
answer
108
views
Parsing shortcodes out of a string
I wrote this shortcode parsing and it runs in \$O(N^2)\$. Is there a way to better optimize this?
...
2
votes
2
answers
2k
views
Capture stdout output of a function call
Are there any major flaws to implement this test helper function?
I know that the preferred way (refactoring) would simply make the function to be tested return its value and delegate printing to ...
1
vote
1
answer
170
views
Readlines abstraction for Golang
I've just started learning Golang and was solving some problems which required me to read lines of text from a file. I decided to abstract away the reading part so that I can use Go's ...
2
votes
1
answer
229
views
Distributed lock service implementation in Golang
I have multiple E2E tests (written in Java) which share login details, each test during runtime will query the locker API for login details which is running on its own dedicated server.
Below is my ...
1
vote
1
answer
77
views
Count occurrence of elements in map during creation
This code works, but it's so ugly, so I was hesitant to put it on display.
There must be a nicer/easier way to achieve this.
The main issue is to count each unique occurrence during runtime when the ...
4
votes
1
answer
615
views
Golang HTTPS certificate expiry checking CLI tool
I am a beginner at using Golang, I would like advice about the following program. It is a CLI tool that can check the expiration dates of HTTPS certificates concurrently. I have only used the standard ...
0
votes
1
answer
1k
views
A Go endpoint to get all items from DynamoDB and return them as a JSON response
Let me start by stating that I am currently in the process of learning Go and AWS CDK. What better way to learn than building a Serverless Todo API!? Using the Go AWS CDK (v2) I have built my ...
4
votes
1
answer
808
views
Launching two goroutines in parallel and returning result of the first finished
Real case: I need to retrieve data from a web service (main process), but in case that web service is taking too long, I retrieve the data from the cache (that data might be older) in a parallel ...
3
votes
1
answer
143
views
Simple goroutines to make multiple http calls
I have a program which calls a lot of URLs with the help of a goroutine and assigns the result to a mapping. As a beginner in go I chose the simplest implementation as possible. I have ended up ...
2
votes
2
answers
793
views
Golang implementation of dining philosophers variant
I would like to implement a variant of the classical dining philosophers problem which has the definition as:
Implement the dining philosopher’s problem with the following constraints/modifications.
...
2
votes
2
answers
146
views
Finding files using multiple coroutines
I'm trying to write a simple program to find a certain file name within a directory tree. I use up to 30 coroutines.
Is there anything wrong with this code or what needs to be improved?
...
7
votes
2
answers
546
views
caesar cipher decoder and encoder - go
I implemented my first algorithm in golang - the caesar cipher. Is there something i could do more efficiently? I am quite new to go and any improvement suggestions are welcome.
...
2
votes
2
answers
159
views
Change interface depending on if statement
I'm using fiber and mongodb. Field "field" is needed to obtain certain data to unload the load on the database. If field "field" is empty, then needs to output all the data from ...
1
vote
1
answer
82
views
How to avoid nested map allocations in below code?
I have a below struct where I have a nested map for CustomersIndex which allocates bunch of internal maps causing memory increase. I profiled it so I noticed this. ...
1
vote
1
answer
111
views
go mars rover kata go
A kata is an exercise. In martial art is form. In software development is a way to practicing. For example in TDD.
Mars rover kata aims to solve some problem in the context of the mars rover. Here you ...
0
votes
2
answers
94
views
The levers puzzle
I started playing Pathfinder: Kingmaker, and very soon ended up in a room with 6 levers, and a task to open a secret door by manipulating the levers. I assumed that the correct position for all the ...
2
votes
0
answers
375
views
Networking code for a Golang P2P library
I am working in a Noise-based P2P lib that has only basic TCP networking implemented so far. I am looking for anyone who get interested in this project that want to helps with reviews to the code and ...
1
vote
1
answer
2k
views
Go Routine: Multiple Consumers to RabbitMQ
Here I'm trying to create the multiple consumers of rabbitmq queue using the goroutines. Also, I'm trying to achieve a graceful shutdown. Is the following approach create any memory leaks? or is it ...
4
votes
1
answer
366
views
Golang function that reads S3 files and populates maps with strings as keys
I have a below read function which is called by multiple go routines to read s3 files and it populates two concurrent map as ...