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
1k views

Property file into configuration in Go

My first ever attempt at Go. Writing a small app. It takes a property file and uses it to populate a Config object. After adding the first property of the Config object (dateformat) I realised that ...
2
votes
0answers
47 views

Extract script body or script src for internal and external JS scripts respectively

I have written a function func getScriptsFromUrl that accepts a URL and creates two files with script body and script src for internal and external JS scripts ...
2
votes
0answers
167 views

Hello, World BDD in Golang

I've tried to do some BDD in Golang using Godog. File Hello.feature: ...
1
vote
2answers
97 views

Extract unique words from given text and group by letter count

The task is for training go-lang. The idea is to extract unique words sorted and grouped by length. Might be useful in learning new words. The program uses command line argument assuming it's a file ...
3
votes
0answers
243 views

Getting all unique permutations from a slice of integers slices in golang,

For a project I'm working on I have a set of number sets, and I need all unique permutations of them. I want to return only one copy of each unique number set, and I'm struggling to figure out how ...
2
votes
0answers
13 views

Dealing with API routes in form of interfaces

Today I had an interesting idea. I have been copy/pasting the following line for each kind of request method for every route. ...
4
votes
0answers
170 views

A task scheduler with persistence

I wrote a task scheduler package with data persistence in Go. However, the logic seems super messy... even it seems passed all tests. Is there any better way to structure the code and finish few ...
1
vote
1answer
373 views

Reading lines from a file and processing them concurrently

I'd like to read lines from a file and process them concurrently. I came up with the following code to do this: ...
3
votes
2answers
1k views

int to Roman numerals in Go / Golang

For a new project, I've started learning Golang. This is one of my very first steps in Go. The objective that I've given myself is to convert int to a String representing the roman numeral of that ...
2
votes
0answers
380 views

Concurrent hash map implementation with Go's channels

I've implemented a concurrent hash map in Go. I'm fairly new to this language as I have mostly Python background so I'm looking for suggestions how to improve my code. I've ran the tests with ...
3
votes
1answer
181 views

Interview Take Home Challenge: Chat server

Recent take-home challenge I was assigned from a recruiter prior to technical interviews with the team. The team wanted it written in GOlang (I had no experience in the language) but told the ...
3
votes
0answers
59 views

Exporting tables from 30 databases

What my code do: Connecting to 30 DB (consistently) Copying DB file to temp.dat Reading temp.dat Writing read data to file So, it connects 30 times with different databases. This take 6-7 second (...
5
votes
2answers
576 views

Show all primes in go

I'm trying to go through Adrian simple programming tasks; Elementary task 8 It's basically asking for an infinite loop to print every prime number as it finds it. Are there too many ...
4
votes
1answer
349 views

HTTP Load test with Golang

I am a golang novice... I am trying to write an application that takes in many requests - up to a sustained 10000 HTTP posts/sec and post the payload to two back-ends in parallel (5 second timeout). ...
6
votes
1answer
4k views

golang rabbitmq message consumer

I need to process rabbitmq messages with golang with worker style, is this correct way to process rabbitmq messages with golang? ...
1
vote
1answer
348 views

XML file parsing in Go

Below is a piece of code that is responsible for serializing files. ZL_LIST and PERS_LIST are XML file structs, I have not shown ...
5
votes
1answer
451 views

Inefficient binary search? Hackerrank - Climbing the Leaderboard

I'm learning Golang and have been trying to get 100% on the following Hackerrank practice challenge: Climbing the Leaderboard The code passes ~8 of 11 tests. The Hackerrank tests are time-bound and ...
3
votes
1answer
51 views

Utility to cache Google Maps

I wrote a little wrapper for Google Static Maps API so that I do not pull down from Google Maps if I have already retrieved the address. The below code works, but I wrote it in a quick fashion - not ...
4
votes
1answer
44 views

Length-Based Frame Stream En-/Decoding in Go

I'm relatively new to Go, which is why I decided to post some code here. My goal is to en-/decode a TCP stream. The individual data packets length-based. The first two bytes are the unsigned size in ...
4
votes
1answer
370 views

API client, using an injectable helper to aid testing

description write a api client that fetch items from remote service I have separated Service{} class's helper methods into another class ...
4
votes
1answer
283 views

Detecting over-/underflow for uint64+int64

I am trying to write a function in Go which adds an uint64 value and an int64 value and which detects whether the result can be ...
1
vote
1answer
151 views

Go task scheduler

This is the same problem as the Python task scheduler, but in Go. I chose not to use a sync.Cond (I couldn't seem to get that right), but instead use channels. <...
4
votes
2answers
571 views

Representing multiple errors in Go

The MediaWiki API may return multiple errors. Is this a idiomatic way of representing them? ...
2
votes
1answer
49 views

Skeleton for a command-line tool to scan domains for vulnerabilities

I'm working on a new command line application in GO and was hoping I could get feedback on my design pattern, or suggestions on a better one to use. I'm still new to GO, only having used it for a ...
2
votes
0answers
59 views

Testable filesystem Writer for logging, with log rotation

I want to implement a custom Writer that allows the native go logger to do log rotation, and I also wanted to be able to write tests for it. The general idea was ...
6
votes
1answer
155 views

Google Translate CLI

A Translator in the Terminal using Golang. It uses Google's API. Currently, it only translates en (English) to es (Spanish). ...
4
votes
3answers
2k views

Weighted Probability in Go

I was recently tasked a programming assignment with a prospective company, unfortunately I didn't pass the assignment and didn't receive any feedback on what I could have done better. I would ...
5
votes
1answer
163 views

Flashcard CLI app in Golang

This is a simple flashcard app. With flags to control the sides of the flashcards and the number of flashcards in the session. All the flashcards without any input at the prompt, are deleted from the ...
6
votes
2answers
2k views

Customizing errors based on HTTP status code in golang

I want to collect errors and its causes by defining custom errors (HTTP status 40x & 50x). For example, if user's request was bad, I want more specific reasons for the error. A customized error ...
1
vote
1answer
544 views

Strategy design pattern for writing to a file or to the console

I have this interface for all strategies: type PrintStrategy interface { Print() error } of two types: ...
2
votes
0answers
128 views

Determine the country by an IP

EDIT: I have updated the code, if you have comments about the previous version of the code, please do post them anyway. The task is to determine the country by an IP. Provided programme queries two ...
4
votes
0answers
604 views

Scraping website and print them via routers

I've been working on a personal project for a while which simply extracts some information from a website and save them as JSON files. Then I've decided to move those scraping functionalities to the ...
2
votes
2answers
4k views

Return Unique items in a Go slice

I'm trying to return unique items in a Go slice. I've landed on the following, but it seems rather sub-optimal. I'm new to golang (first project in it) and wondering if there's a better way to ...
5
votes
1answer
263 views

Trie based string indexing with edit distance / Levenshtein in Go

This is my first Go program that I've ever written. The code can also be found here. It allows you to create a search index and add words to it. The twist is that when searching for a word within the ...
1
vote
0answers
651 views

Dependency Injection and Service Locator/DI Container

I have implemented clean architecture for my app, and I have a few questions. Typically, pure DI is argued for over a Service Locator pattern, because it is very explicit and more testable. However, ...
2
votes
1answer
111 views

Use of concurrency to generate combinations

I have the following package to generate combinations from a slice of bytes: ...
4
votes
1answer
481 views

Worker, Pool and Jobs

I created a snippet of code that allows me to create a worker pool, and from that worker pool I can run a bunch of jobs. I can configure each job to have a retry limit, and set a callback that will ...
2
votes
1answer
128 views

Counting different kinds of line terminator characters in files

Can someone take a look if this code piece is ok. I'm most interested whether the goroutines are used correctly, but also general Go best practices. ...
3
votes
1answer
105 views

Creating a presigned URL

I've created software in Go to create a presigned URL: ...
2
votes
0answers
66 views

Pub/Sub Broker Subscriber Interface

I'm working to build out a Subscriber interface for handling at-least-once messaging semantics, so I can produce different brokers. Here's my interface thus far: <...
1
vote
0answers
272 views

Go program to generate S3 presigned PUT URL

I'm have a made a simple Go program to generate a s3 presigned put url: ...
2
votes
1answer
637 views

Go program to find duplicated files in a directory (recursively)

This is my first Go program. I'm learning the language but it's a bit difficult to understand all the concepts so in order to practice I wrote this. It's a simple program which recursively check for ...
2
votes
1answer
1k views

Query Select and Insert if not exists

Are there any good ways to make this createIndexBlock() method shorter? It looks wastefully long. I have many tables. I don't like to make these kinds of methods. ...
5
votes
0answers
846 views

Tool to calculate the average time that takes for a GitHub pull request to get merged

I'm learning Go, and this is my first attempt at a command-line tool that uses the GitHub API to calculate the average time that takes for a pull request to get merged for a particular organisation or ...
5
votes
1answer
528 views

Go web application with a mock user repository

I'm new to go and struggling to create structure of web application. I read about clean architecture and Ben Johnsons blog post about package layout. Now i want to put it all together. This is just ...
4
votes
1answer
1k views

Callback pattern for handling socket response

I am in the process of learning go and am coming from a PHP, JS, and Nodejs background. I created a package that is a client which connects to a socket server and processes the data received from ...
5
votes
3answers
308 views

Beginner solution to basic quiz exercise, a la Gophercises

I just started golang development about two weeks ago and recently finished the recommended introduction book. I'm now working my way through Gophercises - a sort of collection of exercises to ...
5
votes
1answer
2k views

DFS implementation

I implemented DFS using recursion in Go. When I dfs the graph, I am able to get the path of traversal. But I'm unsure what else could I add to this DFS in order to make the search better. Also, Is ...
2
votes
0answers
180 views

Multi Site Concurrent web crawler using gRPC

This is the server portion of a gRPC implementation of a multi site concurrent web crawler. ...
1
vote
1answer
474 views

Simple bitset in Go

I was playing with an implemention of sieve of Eratosthenes in Go and realised a memory-efficient solution would benefit from a memory-efficient data structure for storing boolean values at the given ...

1
3 4
5
6 7
11