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
0answers
30 views

Can anyone explain what is happening in the following GO code? [closed]

The following code outputs false. The test function returns an interface that I believe should be nil. But in the print statement, the nil check returns false. Can anyone explain why is that? ...
1
vote
1answer
45 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 ...
0
votes
2answers
213 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
0answers
32 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
1answer
165 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
1answer
35 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
2answers
190 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
votes
1answer
126 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
1answer
70 views

Plan 9 freq(1) in go

I implemented the freq(1) program from Plan 9 in go. ...
3
votes
0answers
69 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? ...
0
votes
0answers
32 views

Calculate intersection point of 2 or 3 moving averages

I want to calculate the intersection point, in time, of 2 or 3 moving averages. To solve this problem I decided to transform the moving average(ma) data into geometrical lines and calculate the ...
1
vote
1answer
52 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 ...
4
votes
1answer
233 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
2answers
102 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
0answers
238 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 ...
0
votes
1answer
65 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
1answer
35 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. ...
1
vote
1answer
64 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
0answers
34 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 ...
1
vote
0answers
32 views

Integer Double Ended Queue GO

I'm currently learning Go and I have decided to implement a Circular Doubly Linked List (Deque) structure for the training. Go is not my first language. I program mainly in Python, therefore I would ...
2
votes
1answer
96 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
1answer
80 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 ...
0
votes
0answers
25 views

Filtering methods for 3 collections

I'll start by saying that I just started learning Go coming from Python (and some basic on Java), so I am trying to understand how to write Go code in more idiomatic way and not in a Python way. Any ...
2
votes
2answers
74 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
1answer
55 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: ...
1
vote
1answer
244 views

Merge Intervals(Golang)

Solving the merge intervals problem in golang(link: https://leetcode.com/problems/merge-intervals/). The Problem ...
4
votes
1answer
65 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
1answer
68 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. ...
0
votes
1answer
18 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
1answer
72 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 ...
1
vote
0answers
34 views

Parallelizing identical long-running tasks with Go channels

I have written a program in Go to compute the discrete logarithm mod primes (find \$x\$ such that \$h=g^x\mod p\$), and the algorithm I am using can be easily parallelized. Essentially, I am trying to ...
2
votes
1answer
39 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
0answers
65 views

Swagger API with Gorm DB connection

I have an API Swagger generated, I'm not satisfied with how I'm handling my part of the contract e.g. how I have constructed my db and ...
0
votes
2answers
101 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
vote
0answers
33 views

Read value from config and return function

I’ve the following function which should be run in production I read some config If valid add the runner otherwise just return, the function is working! Is there a cleaner/better way to do it in go? ...
-1
votes
1answer
117 views

Find string enclosed in brackets [closed]

I have this find function. Is it concise, efficient and readable with good logic flow? ...
0
votes
1answer
113 views

Increment struct value using reflection

The main idea is, I have a struct and I will get a struct field as a string from another function, which I shall increment its value by 1. Below is the code I used and I think it is memory consuming. ...
1
vote
0answers
26 views

Breadth first search of a binary-tree with channels

As an exercise in using channels in Go I implemented a breadth-first traversal of a binary tree, using a channel as a queue to store the order of the nodes to traverse. After ironing out a bunch of ...
1
vote
0answers
81 views

Command line utility for user data migration from MUBI.com to letterboxd.com

Please make code review for command line utility for user data migration from MUBI.com to letterboxd.com. Utility makes Get HTTP request downloads json-data, parses it and saves as CSV-file. Can be ...
0
votes
0answers
61 views

2 Weeks into Go: Golang Tour WebCrawler Exercise

I'm on week 2 of learning go. I just completed the golang.org exercise on creating web crawler (https://tour.golang.org/concurrency/10) and I would please like feedback on my code. It feels overly ...
0
votes
0answers
48 views

Golang - Abstract Factory

Here I'm trying to learn the Abstract factory pattern. Have referred some examples and trying to mimic the same with some dummy server examples. Please help me to review this. ...
2
votes
2answers
243 views

Golang unbuffered channel - Correct Usage

Here is an example where I'm trying to understand the concepts of buffered channels> I have three functions and create a buffered channel of length 3. And also passed a waitgroup to nofiy when all ...
3
votes
1answer
95 views

Golang Rest API

I want to ask if there is a better way to arrange this. Main concern is whether the store is set up in a good way and if passing Pointer to ProductRepository is a good idea or there are better ways ...
0
votes
0answers
75 views

Golang parser for code generation and http request binding

After making some changes to an API realized I had to manually rewrite too many sections of code. That started me looking at different code generation techniques. I did a bit with Swagger/OpenAPI but ...
1
vote
1answer
266 views

Parallelized web crawler using goroutines and channels

As part of the "a tour of Go" section on golang.org, I was trying to make a (formerly singlethreaded) web crawler parallelized using goroutines. I got it working but it doesn't seem to "...
0
votes
0answers
47 views

Go: Optimize Inclusion/exclusion check

This function works as such: Use_Inclusions and Use_Exclusions are either true or false File_Type_Exclusions is a slice of ...
0
votes
1answer
77 views

Is there a better "Go" way to implement LC Add Two Numbers solution

Problem Statement: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the ...
1
vote
1answer
114 views

Reverse Root Solution

Solved one of the easiest problems from acm.timus.ru. 1001. Reverse Root The input stream contains a set of integer numbers Aᵢ (0 ≤ Aᵢ ≤ 10¹⁸). The numbers are separated by any number of spaces and ...
1
vote
1answer
45 views

Simple http helper in Go

Can you please share your thoughts on the following simple httphelper in Go? Thanks in advance. I mainly would like to know whether returning a channel of a custom type seems like a good idea and if ...
1
vote
1answer
41 views

Creating SQL Table from a Go Struct

I have been building an API in Go, which I want to link to a Postgres SQL table. I have always used NoSQL previously but thought ...

1
2 3 4 5
12