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
0
votes
1answer
55 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 ...
0
votes
1answer
48 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
45 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. ...
0
votes
1answer
754 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
724 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
110 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
70 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
62 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
60 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
268 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
vote
0answers
36 views

Shares struct's to multiple packages

This is my first real attempt and playing with GoLang In my project, I will be contacting multiple carriers to get their "estimate". I have carriera at the moment, but there will be carrierb etc too. ...
3
votes
0answers
42 views

Reduce cluttering in a VPN initialization dance implementation (html, xml extraction and api calls) in Go

I'm still rather new to Go and I wanted to convert a part of a Python script I wrote a while ago to perform the VPN initialization dance (basically a set of API calls + parsing to fetch an auth cookie ...
3
votes
0answers
28 views

Code to send print jobs through Jetdirect port

I have a program made in Go that lets me send files directly to printers through the Jetdirect port. The program works without issue and I can print in any printer with the port 9100 enabled. ...
4
votes
1answer
58 views

Golang checks for equilateral, isosceles, or scalene triangle

For me, learning the basics of a new programming language is best done through some easy to intermediate challenges. Here's one that's rather well known and relatively simple - determine if a triangle ...
2
votes
0answers
57 views

Lock-free state machine

I've written a lock-free state machine in go and I would love to receive some feedback on it. Writing this library my main concerns are keeping it lock-free and very light-weight (no bells and ...
2
votes
2answers
50 views

Recursive Mergesort using goroutines

When learning a new language, one of my first tasks I like to go through is writing a few different sorting algorithms in that language to help familiarize myself with the syntax and see if there are ...
7
votes
3answers
230 views

Unit testing a REST API in Go

I am learning Go by writing a simple CRUD REST API using gotilla/mux and Gorm. I would like to get some feedback on the application code and on unit tests in particular. Please suggest me what to ...
5
votes
1answer
88 views

Compiling Go with python

I've made a small script to compile Go code with Python. The result is not something I'm happy with, because: It seems overly complicated I'm worried the nested if-else with f string are unreadable ...
8
votes
1answer
118 views

Writing a test to validate that the repo is formatted

I have a short test to validate that all committed files in the repo are formatted. I'm new to go so not sure what the best wat to do it is. The error handling, in particular, is rather gruesome as ...
2
votes
1answer
64 views

Concurrency-safe task scheduler

I'm trying to do some task scheduler and worker. Tasks are added to the queue from which worker retrieves and processes them. Tasks from one queue must be executed sequentially. Tasks from different ...
1
vote
1answer
69 views

Keep reading Command-line until you get the word END

I have to write a code which takes (integers) numbers from Command-line and keeps reading the terminal until it gets a word END So I wrote the following; I feel ...
0
votes
0answers
19 views

Reuse of a gRPC server connection object in Go

Friends, I'm attempting to use a single grpc.ClientConn variable with multiple HTTP handlers in a main go package. Is it okay to have a package scoped connection variable? I'm not mutating the value ...
3
votes
2answers
124 views

Simple BubbleSort in GoLang

I'm just starting in Go. Please review the below code, and let me know what I can improve in this code. ...
1
vote
0answers
114 views

Observer Design Pattern in Golang

I am trying to practice the Observer design pattern in Golang, here is my code. I would be pleased to receive your comments, improvements, etc. ...
4
votes
1answer
52 views

Simplest lexer for c in go

I started learning compilers development and as pet project decided to implement c compiler. The first step is implementing simplest lexer. Also, I decided to try new programming language and chose go....
4
votes
2answers
95 views

Graceful shutdown of applications/servers

I am trying to find out if there is any difference between two implementations that currently do the same thing - gracefully shutdown applications/servers, for example, when Ctrl+C is hit. Both work ...
3
votes
1answer
43 views

File Utilities in Go

I'm beginning to learn Go. I've decided to write some file utilities to help me with some bigger projects I intend to write. Coming from mainly a Python background, I'm sure there are plenty of ...
7
votes
1answer
103 views

Boyer Moore Horspool Search Algorithm in Go

I am practicing Go and try to implement Boyer Moore Horspool Algorithm in Go, It returns all ocurrance of a "phrase" in a given text. This code is working, but I would be pleased to have any feedback ...
4
votes
1answer
84 views

Passing around context.Context in Golang

I am currently "gracefully" handling HTTP server net/http shutdown which works perfectly fine (I am not asking you to review server shutdown). As seen in the code ...
6
votes
2answers
218 views

Implementing a REST API in Go using gorilla/mux and Gorm

While learning Go I decided to implement a simple REST API to get to know the language and since I am inexperienced in Go I would appreciate any feedback on the code. Please post any thoughts you ...
2
votes
0answers
74 views

Tests for redis wrapper

I've written a wrapper package for redis. The idea is to be able to provide better error reporting with the package, as well as integrating stats and logging at a later stage. For now it's just better ...
0
votes
1answer
79 views

Traversing a JSON-like data structure in Go

In my code I need a function to traverse an arbitrary JSON-like data structure with a path definition. E.g., given the structure ...
0
votes
0answers
30 views

Error handling in Go

I have a function which returns an error. I would like to handle this error on the caller function, so I need to know the reason of the error in the caller function. Below there is my solution, but I ...
2
votes
0answers
28 views

Refactoring the Go HTTP API code/flow/structure

This app loads application specific global configs and starts http server so that it is ready to serve API requests. While structuring and coding, I've followed some "best" practises either from the ...
3
votes
1answer
74 views

Setting a request header with or without Context in Golang

I have two ways (middleware) of setting a specific header (if not set) to request but want to know if one is better/beneficial than the other and the reasons why. Note: At some point I will need to ...
4
votes
1answer
63 views

Go function to generate permutations of a given integer array

I'm writing a function to generate a permutation of given []int: ...
1
vote
0answers
35 views

Checking for a values existence: slice iteration vs map lookups in Go [closed]

Assuming I have the following slice: mySlice := []string{"one", "two", "three"} and I want to know whether or not it contains a given string, say ...
1
vote
1answer
36 views

Dependency injecting or manually instantiating structs in others with go

I am coming from PHP OOP background so just want to find out if what I do with Go is common/acceptable practise or not (I am newbie in Go). It is to do with Dependency Injection. In OOP it is ideal ...
3
votes
1answer
343 views

Google pubsub client in golang

I've been working on a Google Pub/Sub client library for golang. Fairly new to golang and my intention is to learn the language. Not really sure what are the best practices, aiming to learn them over ...
0
votes
0answers
239 views

Prometheus exporter for custom scripts (Golang)

This is my first project using Go to study, I've built a simple utility to export output of commands or other scripts in the Prometheus metrics format. The utility basically get's the output of a ...
2
votes
1answer
51 views

Simple Go REST API that returns dummy messages

I am a learner in Go and wrote example below in a day so I would like to get some suggestions to improve it. It is a simple rest api that currently just accepts request and returns a dummy message. My ...
0
votes
0answers
29 views

Analytic Tableaux Implementation in Go

As an exercise I wrote a very simple implementation of an analytic tableaux proof checker thing. The method of analytic tableaux is decribed here on Wikipedia. It's a simple graphical method for ...
3
votes
1answer
80 views

Apply a sepia filter to an image

I'm writing a simple function that applies a Sepia filter to an image. My function works, but I'm a beginner gopher. So I would like to know if there is a way to improve the code. I usually code in ...
2
votes
1answer
82 views

Go functions to create a directory if it doesn't exist

Which of the 2 solutions is written better? Personally I prefer the one line method but it does make it slightly more difficult to debug. Is perhaps doing it the long way first then refactoring to ...
1
vote
0answers
18 views

Precompiled templates with initializators (factory pattern) or single interface and method or what else?

PROBLEM I'm trying to use authboss (https://github.com/volatiletech/authboss) with quicktemplate (https://github.com/valyala/quicktemplate). The authboss rendering system is defined by one interface:...
4
votes
1answer
48 views

Find the total number of emails in a folder (with all of the subfolders)

The Folder struct definition below is given: type Folder struct { ID int emailCount int childFolderIDs []int } Description of the fields are: ...
1
vote
1answer
50 views

HTTP status monitoring

I am fairly new to programming. I am writing a script which gets URLs and parameters through a config and makes http requests to check status, finally push a json string to Open-falcon server. I am ...
4
votes
0answers
147 views

Implementing a TCP client in Golang

I am very new to concurrent programming in general and want to know if my implementation is thread-safe. I'm currently working on implementing a TCP client in golang. The service listens on a port ...
4
votes
2answers
124 views

Displaying IP addresses in Go using Stringer interface

I am trying out some Go code examples (while coding a private project) to get more "in-depth" knowledge about the language. I have come across an exercise from the Go Tour website about displaying ...
1
vote
0answers
356 views

Golang and Gin framework: best practices to connect to Postgresql

I come from this question. Project A very simple project with Gin framework with an endpoint to return a list of users based on their score. Structure ...

1 2 3 4 5 9