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
3
votes
1answer
19 views

An example of transferring the C ++ class hierarchy to Golang. Is it done correctly?

I am trying to transfer my c ++ experience to the Go area. I'm new to Go, so not sure if the implementation is correct. In any case, it looks very ugly compared to C ++ code. Is there a nicer solution?...
3
votes
0answers
25 views

n executions of a periodic goroutine

I'm new to Go and have a use-case for periodically executing an async work-function. I want the interval between work-function executions to be constant (not the time between one finishing and the ...
0
votes
0answers
43 views

Golang Error handling by a generic interface

I was wondering why we people don't use a generic interface instead of error type. You can see this pattern a lot in the Golang community: ...
7
votes
1answer
73 views

Mutual recursion - Naming the opponent serve - pingpong

Problem statement Ping-pong The ping-pong sequence counts up starting from 1 and is always either counting up or counting down. At element k, the direction switches if k is a multiple of 7 or ...
4
votes
1answer
55 views

Decode FEN string into separate variables for the 6 categories

FEN strings are compact representations of chess board positions which allows you to derive the necessary information to start playing a chess game from that position. This includes things like the ...
3
votes
0answers
50 views

Running DNS lookup over million IP addresses

I need to run over all the IP addresses on the CIDR 10.96.0.0/12 network. There are 1,048,574 IP addresses. I created a multi ...
3
votes
1answer
79 views

Project Euler 67 | Maximum sum path II reading from file

I tried to solve the Problem Euler 67 with golang, because I started to study Go recently. This is my solution: ...
3
votes
0answers
29 views

Email sender worker-pool skeleton in go

How to refactor this go code to make it more easy to understand and to maintain? It is email sender worker-pool skeleton. To understand the working-pool logic I coded it without real email client and ...
4
votes
1answer
69 views

Find “secure file erase” commands on the system

This code finds which "secure file erase" command exists on the system. It used to simply test for "shred" and pick "rm" as a default. Now it is a bit more complex ...
1
vote
2answers
85 views

How to make Print() method memory & CPU efficient?

Problem Statement You are receiving n objects in a random order, and you need to print them to stdout correctly ordered by sequence number. The sequence numbers start from 0 (zero) and you have to ...
1
vote
0answers
18 views

Using two handlers for a GraphQL project; handle query with the second one if the first one is not capable of

I'm trying to use both SuperGraph as-a-library and GqlGen. So I have two handlers: the first one is SuperGraph; this checks that it can carry out the operation the second one is GqlGen; this checks ...
3
votes
1answer
60 views

Word Wrap in Go

I'm building a dead simple CLI app that parses a RSS feed and prints it to stdout. I needed a simple word wrapping function to, well, wrap lines to an arbitrary ...
1
vote
0answers
18 views

Avoid code duplication if what changes is one argument type only

As you can see these functions differ only in keys []int and keys []*int (and in name). ...
2
votes
0answers
17 views

Refactoring Golang to avoid manual fields updating between similar structs and other redundant code

I'm using GraphQL and go-pg. I have many entities like these: ...
2
votes
0answers
20 views

Is there a better way to handle errors in these functions?

I'm creating a GOLang Linux distribution installer. The architecture is straight forward. I have N parameters and uses them in N installation steps. Summarizing: Every step implements a interface ...
2
votes
0answers
41 views

Creating an API in Go to work with Github

I am fairly new to Golang and I was creating an API to fetch commits from any Github repository using their API. I was then creating a frequency count, based on the date and then sending it to the ...
2
votes
1answer
51 views

Blocking send and receive algorithm in Go

I'm sending and receiving data over an interface (serial in this case) with the following behaviour: The receiver sends back an Ack message if a message is delivered successfully. If an Ack is not ...
2
votes
0answers
21 views

Basic functional programming understanding in GO

I'm new GO coder (stared this Sunday) coming from different backgrounds, I wrote the below code based on my understanding of Go within these couple of days, and impacted of my experience in other ...
2
votes
0answers
54 views

Implementing A Simple Singly Linked List

Implementing A Simple Singly Linked List I'm trying to learn Go and wanted to implement various data structures and algorithms from scratch. I wanted to try and implement a singly linked list ...
1
vote
0answers
46 views

Why is my Python thread pool faster than my Go worker pool?

I have recently been digging into understanding Golang concurrency, in particular the use of channels and worker pools. I wanted to compare performance between Go and Python (as many have done) ...
4
votes
1answer
71 views

CLRS implementation (opportunity to sort subarray) of merge sort in golang

I'm reading "Introduction to Algorithms" by CLRS and I can't find an implementation of the pseudo code from the book in golang. By the original implementation I mean that we deal with extra parameters ...
1
vote
1answer
80 views

connection to mongodb in golang

I am building an API server in golang with mongodb. My main.go file looks something like this: ...
1
vote
1answer
48 views

Goroutine wait select operation on multiple channels

I'm trying to understand an SO answer for this question Golang select statement with channels and waitgroup. The author of the now accepted answer goes on to say that OP's code is almost similar to ...
1
vote
0answers
31 views

Decision making inside a for loop and taking certain path based on output from gathered results

I would love to simplify my code, with better utilisation of for loop indexes. The goal is to change out all UP once for new UP ...
1
vote
0answers
30 views

Simplifying decision tree when working with map which has two keys and value as a slice

Can this logic not be simplified more, the code works, but it has become too much of a spaghetti. The requirements are that there should always be one connection if possible in ...
1
vote
0answers
82 views

Recursion - Max of integers in slice

Logical processors available on my machine: CPU(s): 4 Thread(s) per core: 2 So, 2x4 = 8 logical processors. But am currently using only 4 go-...
3
votes
1answer
47 views

Command line dictionary tool, using webscraping

This is my first proper Go program, after completing Go by Example and https://tour.golang.org. I have a background in Python. This program scrapes definitions from Wordnik, then prints them nicely ...
5
votes
1answer
116 views

Roman numerals isomorphic conversion in Go

I always try to port the roman numeral conversion algorithm to learn new languages. Reading the Go manual as a beginner, this is the most idiomatic way I've been able to write it. I would love it if ...
2
votes
0answers
37 views

How to define UDP connection sessions more correctly?

Listening to messages from the udp socket, I would like to somehow determine where packets come from and scatter in sessions to get a more detailed report on the received data, I just did it forehead, ...
1
vote
0answers
97 views

SSH Port Forwarding - golang

I developed this small code to make my life easier when I work with remote machines over ssh tunnel crossing a bastion host. I would like to publich it so others could benefit/learn from it. So I ...
1
vote
0answers
40 views

infinite generator with eviction

I made a struct that will loop through a list, and return the next element on calls to the Get() method. It also allows to remove elements from the list by calling the Evict() method, and is safe for ...
1
vote
0answers
70 views

Brute force md5 checksum matching regex

The code starts with 128 bits of 0 (size of md5sum checksum) then brute forces to find checksum matching regex (all characters of checksum in hex are digits). I ...
5
votes
2answers
151 views

Run Length Encoding in Go(lang)

Run-length encoding (RLE) is a simple form of data compression, where runs (consecutive data elements) are replaced by just one data value and a count. For example: ...
2
votes
0answers
73 views

Flashcard app in Golang

Most of my development experience is in the .NET world. I started learning Golang again a few months ago, and decided to build a super simple flashcard app. This project was mainly to get used to ...
1
vote
2answers
62 views

Count the number of discrete values in a slice

I'm using this right now to count the number of discrete values in a given []string. Is there a faster way to do this? ...
2
votes
1answer
71 views

Go pig Latin translator

I've been recently fooling around with Go(lang) and ended up doing a (very) simple pig Latin parser. I'm pretty sure this is not the best solution out there (no punctuation and only lowercase letters) ...
-1
votes
1answer
74 views

http router written in Golang

in my jurney to learn Go, I decided to write a simple router which I called it Gouter, which I think it has most of the features in gorilla/mux but in my opinion it's easier to use. Anyway, it ...
3
votes
2answers
74 views

A not-so-simple time calculation

I'm struggling with some code that should be a very simple computation of a duration. The purpose of the code is to generate a random delay, constrained by an upper and lower limit. The reason I'm ...
1
vote
0answers
28 views

Executing two database queries concurrently in Go [closed]

I would like to execute two database queries concurrently for quicker response time. Since channels seemed to be too verbose, I came up with the solution below. However, I'm not very confident about ...
3
votes
0answers
46 views

implementing a mutex with capacity

Not sure this is the right place, but I'll have a try. I'm trying to implement a mutex with capacity, which can be achieved easily with buffered channel like this: ...
0
votes
1answer
74 views

Should Golang interface be shared among different packages of an application?

I'm developing a Go application that has lots of packages. Many of the packages use the same type from a 3rd party library. Should an interface be defined for the type in each package, and let the ...
1
vote
1answer
63 views

JSON-Parser written in Go

Below is a JSON parser written in Go. It's just a task I set myself in order to learn Go, which is also the rationale for reinventing this wheel. At the moment, it's not 100% complete but it can ...
3
votes
2answers
53 views

Simple multiple producer and single consumer concurrency pattern

Anyone please review and share your feedback for the following code. Multiple producers generate random integer numbers and a single consumer receives it to display only odd numbers out of it. ...
1
vote
1answer
853 views

Go homework interview challenge for Storj

Last December I interviewed with Storj and was unsuccessful after my code challenge. Storj were good enough to pay me for the time it took to complete the challenge, but have refused to give any kind ...
9
votes
2answers
959 views

Are there ways to speed up this string fuzzy matching in Golang?

I have a piece of python code doing fuzzy matching which works very well and is pretty fast. For reference, it uses the following files: https://raw.githubusercontent.com/datasets/s-and-p-500-...
3
votes
1answer
217 views

Matrix Transpose in Golang

I have write a normal programm "Transpose the matrix" in go. Suppose input are always correct. I also read the article An Efficient Matrix Transpose in CUDA C/C++. So I keen to know how I can use Go-...
2
votes
1answer
74 views

High Performance Calculation of Sums and Returns in Go

I am writing a finance library with the intention to have the best of Golang's performance. The function Re calculates the returns of a float list, and function Sum calculates the sum of float list. ...
3
votes
0answers
156 views

HTML -> PDF in Go

First time writing a Go script, just looking for feedback on language usage etc. Using chromedp to run a headless (I think) browser to load some html, generate a PDF and then save the PDF to the file ...
2
votes
1answer
90 views

Golang REST API that CRUDS in-memory object

Hey everyone I have a very simple go REST API that is running CRUD operations on an in-memory object. I would love some feedback on how I can refactor this code, and how/if I should break this up into ...
4
votes
2answers
320 views

Computing Scrabble score in Golang

I think we all know the game of Scrabble and how popular it is as a simple programming challenge. Here's my attempt at computing a Scrabble score for a given word done in Go. I must admit, I'm fairly ...

1
2 3 4 5
10