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.

Filter by
Sorted by
Tagged with
1 vote
0 answers
30 views

Go log file swapper

Please review my code. I left some comments where I think something might be wrong, but any comment is appreciated. I am writing a package for a project I am currently building. Its purpose is simply ...
Daniel Burgos's user avatar
1 vote
1 answer
54 views

Gracefully shutdown http.Server{}

Good day, everyone! I want to learn the proper way to gracefully shutdown a http.Server{}. Some answers I found would not handle ...
mahtues's user avatar
  • 11
0 votes
1 answer
64 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 ...
ETLJ's user avatar
  • 1
0 votes
0 answers
56 views

Tiny portion of Git wire protocol implemented in Go

I wanted to upgrade a remote reference in a remote git repository (without a local checkout) much like ssh git update-ref but gitlab doesn't allow me running that. So I wrote this little Go utility ...
chx's user avatar
  • 356
0 votes
1 answer
43 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 ...
bit's user avatar
  • 143
0 votes
1 answer
50 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, ...
Nisal Edu's user avatar
  • 103
2 votes
3 answers
112 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 ...
stefanobaghino's user avatar
0 votes
0 answers
24 views

Gorilla/mux request DTO builder

I got tired of having to extract the provided input from the requests manually so I made a library with which I can extract the values from the request a build a given DTO. The idea is to create ...
Enthys's user avatar
  • 101
0 votes
0 answers
105 views

For loop vs If statement using conditional variable

I'm extending the sync.Pool type by limiting the amount of objects that can reside outside the pool. To achieve this I'm using ...
Bernardo1r's user avatar
0 votes
0 answers
15 views

Golang code that gets data from Kubernetes API and Writes to Spanner

Code for writing a Writer that is used to dump data in a Spanner table. Specifically concerned about the function: ...
Aviral Srivastava's user avatar
3 votes
0 answers
71 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 ...
user219820's user avatar
0 votes
1 answer
39 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: ...
ceving's user avatar
  • 413
0 votes
0 answers
54 views

Testing Receiver Methods in Golang

I'm trying to test and implement an exercise on receiver method from here. This basically states the following: Cars start with full (100%) batteries Each time you drive a car, it covers the it's ...
Saurabh's user avatar
  • 435
1 vote
0 answers
51 views

Write a library for Mutex protected variables in Go

Problem description I'm trying to write a library for protecting variables from concurrent access using sync.RWMutex. The goal is to prevent accidental misuse and promote best practices and I didn't ...
Falco's user avatar
  • 418
1 vote
1 answer
101 views

Implementation of a lock free queue using CompareAndSwap in Go

Here is my implementation of a lock free queue using CompareAndSwap operation. ...
Tauseef Ahmad's user avatar
3 votes
1 answer
198 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, ...
korolev's user avatar
  • 33
0 votes
1 answer
146 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 ...
JavaDeveloper's user avatar
2 votes
1 answer
171 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 ...
b.b3rn4rd's user avatar
  • 121
2 votes
1 answer
117 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 ...
Zach Young's user avatar
0 votes
1 answer
72 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? ...
ericraio's user avatar
  • 151
2 votes
2 answers
1k 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 ...
ojdo's user avatar
  • 420
0 votes
1 answer
118 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 ...
smac89's user avatar
  • 1,467
2 votes
1 answer
168 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 ...
Pawan Kumar's user avatar
0 votes
0 answers
30 views

Component-wise double precision multiplication in Go

I'm working on porting the bullet3 physics engine to Go to learn more about physics simulations. I'm working through some of the convex hull computing code, and I've reached a component-wise, double ...
Sienna's user avatar
  • 453
1 vote
0 answers
191 views

Golang HTTPS certificate expiry checking CLI tool (UPDATED)

I previously submitted this CLI tool to this site for review and have made changes based on comments by the reviewer. I have refactored the code, fixed a bug (the tool will no longer output ...
preetpalS's user avatar
0 votes
1 answer
46 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 ...
JonB's user avatar
  • 431
4 votes
1 answer
386 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 ...
preetpalS's user avatar
0 votes
0 answers
252 views

Integer hash function for concurrent map implementation golang

I am using concurrent map from this repo which only uses string as the key and it doesn't have any implementation for key as integer (int64) so I tried implementing it by just replacing all ...
david's user avatar
  • 1,647
1 vote
0 answers
80 views

Dining Philosophers in golang

I'd appreciate any feedback on this code. The assignment was to have each philosopher eat three times. I introduced time into the problem where eating takes 20 minutes and then the philosopher ...
Robert Lugg's user avatar
1 vote
0 answers
878 views

Timeout middleware in Gin -Golang

This is an implementation of a custom timeout middleware. I am creating a context with a deadline in my middleware and using it in the rest handlers for timeouts (to wrap the query to DB eventually) ...
Manish Kumar's user avatar
0 votes
1 answer
596 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 ...
J86's user avatar
  • 424
1 vote
0 answers
434 views

Golang Program to convert RGB and Hex to DMC colors

I wrote a small console app for converting RGB or Hex values (by specfying on top of the input file) to the nearest colour of DMC thread. I'm curious to know how I could improve my code organisation ...
Adam Parker's user avatar
4 votes
1 answer
420 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 ...
Andrey's user avatar
  • 141
3 votes
1 answer
63 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 ...
rihekopo's user avatar
  • 131
2 votes
2 answers
585 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. ...
Vincent Wen's user avatar
2 votes
2 answers
100 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? ...
woxihuanxiayua's user avatar
1 vote
0 answers
77 views

Set up pub/sub service as part of web app in Go

I have a web application that I'm writing in Go, using the Iris package. This app needs to listen to Azure Service Bus for messages, and take action when they come in. This is my first time writing ...
Kevin Whitaker's user avatar
6 votes
2 answers
452 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. ...
s4vage's user avatar
  • 63
0 votes
0 answers
64 views

A fast food ordering cli program

i am a student learning go as my first programming language as a hobby. I have tested this program on linux+kitty terminal. Program needs unicode supported terminal. ...
spicySugar's user avatar
2 votes
2 answers
120 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 ...
Boro8ey's user avatar
  • 23
1 vote
1 answer
48 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. ...
norman's user avatar
  • 21
0 votes
1 answer
92 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 ...
sensorario's user avatar
0 votes
2 answers
65 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 ...
Andrew Savinykh's user avatar
2 votes
0 answers
314 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 ...
Geo's user avatar
  • 21
1 vote
1 answer
1k 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 ...
Srikanth's user avatar
  • 135
3 votes
1 answer
273 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 ...
AndyP's user avatar
  • 229
1 vote
0 answers
36 views

Managing TimeMachinesCorp POE clock via UDP

I've got a working implementation of a go program to talk UDP to TimeMachinesCorp POE clocks. This code is also in a github repo which notes things I know aren't implemented yet. I feel like there's ...
chicks's user avatar
  • 2,855
2 votes
1 answer
802 views

MongoDB abstraction in Go with generics

I'm working on a new project with go. So I figured I would give this new feature a run (it's fun!). Although, I'm not sure I'm implementing this the way it's suposed to be. I've read the following ...
Russo's user avatar
  • 123
2 votes
1 answer
134 views

Golang solution to CTCI 1.2: Check whether two strings are permutations of each other

Just started learning Go recently. Did some questions from Cracking the Coding Interview book. Wrote the solutions in Go. Let me know what you think. https://github.com/samjingwen/ctci Below is ...
Sam Jing Wen's user avatar
1 vote
1 answer
276 views

Suggestions for improvement for generic array and map functions in Go 1.18

Yesterday I build some generic functions for the new official Golang 1.18 release. What do you think about it and what could be added and improved? ...
Erik Bent's user avatar

1
2 3 4 5
13