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
1k
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 ...
2
votes
1
answer
166
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 ...
1
vote
1
answer
344
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?
...
2
votes
1
answer
469
views
Read bunch of files in parallel and populate concurrent map
I am trying to read bunch of S3 parquet files in parallel from a S3 bucket. After reading all these files, I am populating my products and ...
3
votes
1
answer
109
views
Parse data into struct efficiently by reducing memory footprint
I have a simple program where I am deserializing my bytes byteSlice into a ClientProduct array struct. And then I iterate over ...
1
vote
1
answer
125
views
Re-usable worker pool classes
I am trying to read multiple files in parallel in such a way so that each go routine that is reading a file write its data to that channel, then have a single go-routine that listens to that channel ...
2
votes
1
answer
356
views
DelayQueue in Go
I tried to use Go to write a DelayQueue. I referred to the implementation in Java. So the general logic is to have a minimum heap, then try to fetch the top element ...
1
vote
1
answer
139
views
Chunk output into files, based on number of entries and total size
Below is my client code which stream all the customer URLs from a golang grpc server. It takes Request input parameter and streams customer URLs based on matching a ...
7
votes
1
answer
188
views
Download artifacts using HTTP
The public code is SaveAsFile(). It takes a URL, checksum and authentication info, and downloads the artifact and its hash using HTTP. It saves the content as a ...
1
vote
2
answers
142
views
Using classes for X number of config files which needs to be read individually in memory
I am working with lot of config files. I need to read all those individual config file in their own struct and then make one giant Config struct which holds all ...
1
vote
0
answers
110
views
Go REST API feedback [closed]
My intention is to create an API as generic and DRY as possible using Go. To achieve this, I have made some more or less common decisions:
To use AJAX call to avoid reloading page when updating the ...
0
votes
1
answer
490
views
Go logging wrapper that adds log levels
The package is essentially a small wrapper around the stdlib logger that provides a very simple, easy to use logger that can toggle between different log levels (DEBUG, INFO, WARNING, ERROR). Log ...
2
votes
0
answers
217
views
Parallelized Web Crawler
Exercise is here:
https://go.dev/tour/concurrency/10
Prompt:
In this exercise you'll use Go's concurrency features to parallelize a web crawler.
Modify the Crawl function to fetch URLs in parallel ...
1
vote
2
answers
101
views
Pagination configuration via query parameters (head, last, page, limit and offset)
i have logic module for head, last, page, limit and offset filter.
such as :
../example/param if no query, return all value
../example/param?limit=10 return the first 10 value
..example/param?offset=...
7
votes
1
answer
3k
views
Decompress tar.gz file in Go
I want to extract tar.gz file and store the contents in the same directory. I got below method which does the job but I wanted to see if there is any way to improve ...
1
vote
1
answer
87
views
Factory to create default or cyphered and encoded output marshalers
The following code bellow is a factory which creates two different objects for marshalling cyphered and ...
0
votes
1
answer
1k
views
Mongodb connection retry
Created a MongoDB client which is handling the retry in case of server connection failure. Please review and how I can improve further.
...
2
votes
1
answer
269
views
FizzBuzz JSON via Unix socket (Go)
At heart, this program is just the basic "FizzBuzz" program. However, the program was pushed further, by making it a client-server via Unix Socket:
Server run, and listening on a socket.
...
4
votes
2
answers
499
views
first Go program: Tic Tac Toe
If I formatted my question wrong, feel free to notify me or update, this is my first question on this subforum
This is literally my first ever Go project, decided to make a Tic Tac Toe (ironically I ...
2
votes
1
answer
910
views
golang http.Client wrapper with rate and concurrency limiting
My goal is to safely consume an API without getting 429 Too Many Requests error, activating DDoS protection or going over system limit of maximum open file ...
2
votes
0
answers
264
views
Simple implementation of various cache replacement policies
I am new to golang and I tried to implement various cache replacement algorithms (FIFO, FILO, LRU, MRU, LFU) in a generic or flexible fashion. I added some tests as well. My implementation uses the ...
1
vote
1
answer
90
views
Example of handling chained errors in Go with help of CustomError object
My code snippet represents a way of handling chained errors. I need a code-review to understand whether my way is idiomatic and relevant for the 2021?
My personal requirements:
I want each package of ...
1
vote
2
answers
1k
views
move duplicate items at the end of the array
I have array [1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4] so I
want to move all duplicates at the end of the array [1, 2, 3, 4,1, 2,
2, 3, 3, 4, 4, 4]. is there is another best way to do the same Go
Time O(n)...
1
vote
0
answers
58
views
Kademlia identifier package written in go
I'm very new with Go (started to learn it two weeks ago) and I would like to get your comments on the code below. The code is implementation of identifier used by DHT (Kademlia)
The code works as ...
1
vote
1
answer
2k
views
Concurrent processing of a slice
I am trying to learn Go concurrency patterns and best practices on my own.
I have invented a simple task for myself.
I want to process a slice of integers in a parallel manner by dividing it into sub-...
2
votes
1
answer
58
views
Loading configuration options from environment or default values
I have this method that I feel has code repetition that can be improved but since I am new to Go, I am not quite sure how to improve it. I would appreciate if anyone can give me their opinion.
...
3
votes
2
answers
526
views
Parsing custom text file using haskell
I am working on writing code for find difference between two text files that should be ideally same.
the format of file is
...
1
vote
1
answer
173
views
How to make this code's design better?
Github repo
I've attempted a backend assignment in Go from geektrust Assignment Link.
I'm not sure the code that I have written is idiomatic in the go way. I need some feedback on this code based on ...
4
votes
1
answer
109
views
Plan 9 freq(1) in go
I implemented the freq(1) program from Plan 9 in go.
...
3
votes
0
answers
308
views
I recently wrote sort of structs in golang
I am a bit concerned about style (functions, variable names, spacings, etc.). I am also not sure about whether I should return error or panic.
What do you think?
...
1
vote
1
answer
103
views
Go Brainf*ck Interpreter
Recently wrote a brainfuck interpreter in Go.
Here's the Github Repo Brainfuck
Areas that need work
The parsing for brackets [] is still buggy and is known to fail ...
5
votes
1
answer
292
views
Golang keep installation status for multiple installations process
Im fairly new to Golang and I appreciate any feedback about how to make the code cleaner.
The code is called by go-routine and should update status (fail/success ...
1
vote
2
answers
198
views
Improving my solution to the Quiz project from Gophercises in Golang
I'm new to Go and I completed the first challenge from Gophercises. Any feedback would be highly appreciated.
There are some things that I am unsure of if they are made in an optimal way.
Github repo
...
4
votes
0
answers
559
views
Simple RESTful counting API in Golang
Description
This is a simple (and hopefully) RESTful API in Golang that uses Redis. I have next to no prior experience in Golang and absolutely no prior experience with Redis. The API is a simple ...
1
vote
1
answer
769
views
Perform sum of squared numbers without using for loop
I have to find the sum of number after performing square operation in the given input the negative numbers need to be ignored. The input Format is, first line is number of test cases followed by N as ...
1
vote
1
answer
217
views
BoltDB Lookup and Add methods and advice on unit testing
I am writing a Go package that handles communication with BoltDB as a part of some larger project. I have 2 methods for interacting with DB.
...
2
votes
1
answer
150
views
Go Lang custom convert array into string with two separators
This is my custom function to join strings from an array into one string.
We can provide normal separator and the last one. ...
2
votes
0
answers
108
views
A terminal based atom feed reader written in golang
I'm a beginner trying to get a better understanding of golang so I decided to write an atom feeder that runs from the terminal.
I am using the gofeed library to parse the atom feeds and the tview ...
2
votes
1
answer
410
views
Installing charts in parallel using go routines
I use the following code which works and install helm chart (in the loop) in parallel,
it get a kubeconfig file (to access to k8s) create a helm client and install ...
4
votes
1
answer
121
views
Intersect channels in Go
I have a simple golang app in which I have two background tasks that produce data,each of them use it's own channel to signal it produced another unit of data.
I have a single consumer that needs the ...
2
votes
2
answers
2k
views
Mocking Interfaces Golang
I thought of doing the following to mock/test functions in Go and wanted some advice. Let's say you have an interface for a repository:
...
1
vote
2
answers
1k
views
Golang - Splitting a string by a separator not prefixed by an escape string
I need to split a string by a separator but don't want to split if the separator is prefixed by the escape string.
For example:
...
2
votes
1
answer
881
views
Merge Intervals(Golang)
Solving the merge intervals problem in golang(link: https://leetcode.com/problems/merge-intervals/).
The Problem
...
4
votes
1
answer
270
views
Idiomatic Go Lexer
I have written some Go code that produces the output I would like, but I am unsure if the code itself "smells" good. I would like to know if it contains any anti-patterns, exemplifies bad ...
2
votes
1
answer
123
views
Install helm chart automatically
I use the following code which works ok!
The code is installing helm charts in loop in k8s cluster, and I want to verify that I'm writing it ok.
...
1
vote
1
answer
145
views
Go Web API for Sending Emails via Contact Form
I've been playing around with Go and finally found a use case for a little web service I could build.
It takes JSON data via an HTTP POST request and sends me an email via Mailgun's API (it's used for ...
3
votes
1
answer
110
views
Proper way to map the object
I have a simple task.
Array of people object comes in, up to a thousand.
Need to iterate over it, and create a custom payload for external service.
I have created a working solution, but I would ...
2
votes
1
answer
82
views
Multiple input checks, repeat if conditions are not met
I've used this code to make some inputs checks. On any failed check, I need to ask again for proper input. I used labels and goto...
0
votes
2
answers
149
views
filter and map functions
I am a JavaScript programmer beginning with Go. I tried to replicate filter and map functions like JavaScript's, as an exercise....
-1
votes
1
answer
211
views
Find string enclosed in brackets [closed]
I have this find function. Is it concise, efficient and readable with good logic flow?
...