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
305 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
180 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
386 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
43 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
52 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
35 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. ...
5
votes
1answer
114 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
73 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
147 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
733 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
101 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 ...
7
votes
1answer
122 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
72 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
72 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 ...
3
votes
2answers
170 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
243 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
86 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
273 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
48 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
158 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
232 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
387 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
266 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
118 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
32 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
29 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
695 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
2answers
220 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
36 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
38 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 ...
4
votes
1answer
1k 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 ...
1
vote
0answers
527 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
52 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
33 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
97 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
329 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
27 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
55 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 ...
6
votes
0answers
1k 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
191 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
754 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
139 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
2answers
309 views

Golang matrix package

I developed a small package to do matrix math. I just learned Go so I may have done it wrong. ...
4
votes
3answers
495 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: ...
3
votes
3answers
1k 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. ...
2
votes
0answers
730 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
73 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
114 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
47 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 2
3
4 5
11