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
20 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 ...
3
votes
0answers
34 views
+50

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 ...
1
vote
0answers
37 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
66 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
24 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 ...
-1
votes
0answers
32 views

Searching for items in different objects and printing their names

The program gets a map of different lists of objects (DeploymentList and DaemonSetList). It runs over each of the lists and pass ...
-1
votes
0answers
35 views

Finding matching secrets in different structs but with the same schema

I am using the go-client library to execute code on my Kubernetes cluster. My code works and running but I have duplicated code. I am searching for mounted secrets inside the workload. In my example ...
2
votes
0answers
26 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
40 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
53 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
34 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
35 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
90 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
69 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
46 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
28 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
74 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
76 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
16 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
47 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
49 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 ...
2
votes
0answers
54 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
110 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
105 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
vote
1answer
124 views

Two solutions to 2-sum

I have written a solution for two sum problem in variation. first is simple with two loops and another one is one loop and hash map. But I wonder why the simple solution is faster than the efficent ...
4
votes
1answer
67 views

Golang matrix package

I developed a small package to do matrix math. I just learned Go so I may have done it wrong. ...
2
votes
2answers
90 views

Check whether a string has all unique characters (time efficiency)

I don't find this algorithm in Go language here, so I just want to check that it is really most efficient algorithm in Go: ...
1
vote
0answers
109 views

Golang configuration management with viper package

I'm new to GO, I created 2 different configuration resources. Also I created a manager responsible for initializing and reading the configurations and creating default ones if needed. Is this a ...
3
votes
3answers
953 views

Go function to test whether a file exists [closed]

How could one write in a more elegant way that if error is null, the result is true? I really need a bool as returned value. ...
1
vote
0answers
72 views

Singleton pattern for Redis connection

Recently I have learned about singleton design pattern. I have tried to implement Redis connection following singleton design pattern. conn/redis.go ...
2
votes
1answer
72 views

Fetching configuration or default value

I have two code snippets, doing exactly the same thing and both get the job done: use defaults use from config Which is cleaner to use in golang and why? first option: ...
5
votes
1answer
105 views

Find the longest word in a string

I have written code in the language Go. I wonder if anyone can do it in a very simple and effective way, because every language has its own way to solve this problem. My experience is in JavaScript. ...
3
votes
0answers
42 views

Simple REST Base Web Server with Unit Tests

I am building out a simple web server in Go. My goal is to expand on this framework in a different application I am building. Here is my github repo https://github.com/jmacnc/gowebserver Is what I ...
1
vote
2answers
127 views

Remove adjacent duplicates in golang

This is an exercise in a book which ask me to implement Write an in-place function to eliminate adjacent duplicates in a []string slice. I am relatively new to golang and I am not sure if my ...
1
vote
1answer
76 views

Go command-line tool to do some simple byte manipulation

I have some files containing 16-bit words in big-endian order, and a tool to process them that assumes little-endian order. I therefore need to swap the order of each pair of bytes in my files. This ...
3
votes
1answer
99 views

Go implementation of dining philosophers

Follow-up of this question. Questions: is this code a correct implementation of the Dining Philosophers problem? what is there to improve regarding Go Best Practices? ...
2
votes
1answer
88 views

Gin framework project with an endpoint to return a list of users based on their score

My relevant work experience is with Java (mostly web development with Dropwizard/Spring) so I can not avoid using the same practices as I do in a Java project. The project is there but I am going to ...
1
vote
0answers
26 views

Go - avoid result reassignement in OOP [duplicate]

I'm learning Go and I wrote this for a programming challenge. It is working (building and running) but I feel the code is not what Go code should be: The code implements the steps a podracer takes to ...
1
vote
1answer
54 views

Simulating pod racing over a 2D map : am I implementing OOP in a GO-like fashion?

I'm learning Go and I wrote this for a programming challenge. It is working (building and running) but I feel the code is not what Go code should be. I used an OOP design. Is it correctly implemented ...
3
votes
0answers
41 views

N-Queens problem using other pieces using Go

I wrote a solution to a problem based on the N-Queens problem which should use more pieces than just queens. Problem is it's very slow, it probably has to do with how I modeled data and my lack of ...
1
vote
1answer
44 views

Decode Argon2 parameters and handling decode errors

I am writing a function to decode Argon2 hashed string to extract parameters. I need to handle many decode errors, and handle those errors lead to write many repeating ...
3
votes
0answers
42 views

Golang tool to check public repositories list in Github

Didn't post on the Codereview for a while but trying to learn Golang now and wrote my first utility a few days ago and will be glad to see what I did wrong here and what can be done better. This ...
1
vote
0answers
57 views

Extracting attribute value from multiple XML nodes in golang?

I'm attempting to parse an SVG file to get all of the colors that are present in the file. SVGs are XML based and their structure can vary a bit. For example: ...
1
vote
0answers
32 views

client handling of tcp server in go

I'm writing a service for a ORPG and I expect traffic of about 10kb of packets per second from multiple clients. I just want to know if my approach is correct? Are there areas I can improve? This is ...
1
vote
0answers
33 views

Transforming golden and input files in test table

I'm trying to find a way to create a test table from golden and input files. I have the following dir structure: ...
7
votes
1answer
106 views

Quiz game with timer

This is my first Go program. I would like to know what could be improved, what is done wrong, and anything else that I should know. The CSV contains 10 questions with the 10 answers separated by a ...
3
votes
0answers
85 views

Writing Go object code that respects Go guidelines

I'm learning Go and I wrote this for a programming challenge. It is working (building and running) but I feel the code is not what Go code should be: Am I using the ...
3
votes
1answer
170 views

Golang HTTP requests

I'm beginning to learn about Golang and I would like to have some advice about the following program. ...
3
votes
2answers
78 views

Download and save bulk URL concurrently

I am new to Go and wrote program to download and save bulk URLs concurrently. It is working correctly, but I would like to make it more efficient and follow best practices. ...
6
votes
2answers
154 views

Parse dblp XML and output sums of publications grouped by year and type

The following Go program parses a gzipped XML file (available here) which contains bibliographic information on computer science publications and has the following indicative structure: ...