Go is a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.

learn more… | top users | synonyms

3
votes
0answers
35 views

Equivalent binary trees (A Tour of Go)

Any suggestions on how to improve the code shown below for the Go-tour exercise? Exercise description: There can be many different binary trees with the same sequence of values stored at the ...
0
votes
0answers
32 views

HTTP handlers exercise (tour of go)

Any suggestions on how to improve the code shown below for the go-tour exercise http://tour.golang.org/methods/14? Exercise description: Implement the following types and define ServeHTTP methods on ...
-3
votes
0answers
45 views

A Tour of Go: rot13reader

Any suggestions on how to improve the code shown below for the Go-tour exercise? Exercise description: A common pattern is an io.Reader that wraps another io.Reader, modifying the stream in ...
1
vote
1answer
23 views

Injecting an object in each function in Go

My current project uses a database represented as object. Furthermore I want to implement methods like CreateUser(), ...
2
votes
0answers
27 views

Restful API for parsing records

I'm trying to implement my own API. This code excerpt should show the basic working routines. The storage is temporary an in-memory-array and the only HTTP method for now is POST. I outsourced the ...
8
votes
2answers
783 views

Checking for any character common to two strings — Go is 50× slower than Python

I decided to learn Go, knowing Python. My approach is by solving easy problems like this one: You are given two strings, A and B. Find if there is a substring that appears in both A and B. ...
12
votes
2answers
127 views

A closer look at the chat's mumblings

The Go Playground was boring so I decided to make a small application that throws me into the language. It basically queries the chatroom every second for new messages and displays them in the output ...
1
vote
1answer
50 views

Natural mergesort

This is a problem from Robert Sedgwick's Algorithms book: Write a version of bottom-up mergesort that takes advantage of order in the array by proceeding as follows each time it needs to find two ...
2
votes
0answers
69 views

Nuts and bolts algorithm

I am trying to learn golang. This is a problem from Robert Sedgewick's Algorithm's book: You have a mixed pile of N nuts and N bolts and need to quickly find the corresponding pairs of nuts ...
0
votes
2answers
28 views

Binary tree isSame()

Please help me review this code. I want to make it both accurate and more Go-styled. Go Playground code ...
3
votes
0answers
38 views

Utility that decodes and logs UDP packets

I have written the following utility, as my first non-tutorial program in Go. The purpose of the utility is to connect to a torque/force sensor (aka load-cell) via UDP; to send an initialization ...
3
votes
1answer
31 views

Reverse Polish Calculator in Go

I'm very new to Go (this is my first real program), and I was hoping to see if there was anything I was missing about the language or any ways to make it more idiomatic. calculator.go ...
5
votes
2answers
77 views

Getting rid of goto without duplication in Go

Consider the following function: ...
2
votes
3answers
55 views

Pythagorean Triple Generator

I'm just playing about with Go, and am trying to solve some project euler problems to get used to it. I've created a generator function for Pythagorean triples, using a channel which returns a set of ...
3
votes
0answers
31 views

Reading from and writing to a file without passing around filename

I was looking for a way to write to and then read from a file in different parts of my code, without passing the filename around and without consumers needing to know it was coming from a file. I ...
2
votes
0answers
25 views

Most efficient way to remove specific items from a slice

Given a slice of unknown length (potentially very small or very large), and another slice containing (unique) integers indicating indices to be removed from that slice, the most straight forward way ...
1
vote
0answers
93 views

Binary heap implementation in Golang

I have implemented a binary heap in Go to get familiar with the language. GitHub ...
3
votes
1answer
151 views

Golang async but sequential enqueue with buffered channel

The objective of this program is to call enqueue sequentially with multiple URLs, and never block, fetching the URLs asynchronously, but on the order they were entered. In other words: keep calling ...
4
votes
1answer
215 views

Remove element slice of struct pointers

I have an application with a recent addition that requires the removal of a struct pointer from a slice that is itself an element of another struct. A summary of the usage. I am wondering if this is ...
1
vote
0answers
43 views

Implementation of the closest pair algorithm [closed]

I just started learning Go. To start playing with it, I've implemented the fast power algorithm: Here is the pseudo-code I used (source): ...
4
votes
2answers
72 views

Return results from goroutines

I have two goroutines that each need to return their results to the main function. These results are of different types. I have implemented a solution that uses a structure that holds these results. ...
0
votes
0answers
34 views

ttyname() implemented in Go

I'm rewriting GNU's coreutils in Go in order to learn Go better. I've implemented ttyname(3), and I'm looking for a general critique. I can't think of anything in particular I think I did poorly on. ...
3
votes
1answer
39 views

Walking and comparing contents of binary trees

I've written a solution for http://tour.golang.org/concurrency/8, which asks for a Walk() function to traverse a randomly generated binary tree, and a ...
1
vote
0answers
405 views

Golang concurrent HTTP request

I wanted to test the performance of concurrent http request in Go against node.js: ...
3
votes
1answer
49 views

Fast power in Go

I just started learning Go. To start playing with it, I've implemented the fast power algorithm: Any suggestions or criticisms regarding the coding style? ...
2
votes
0answers
33 views

Basic Binary Tree in Go

As an exercise I have written a basic binary tree implementation in Go. Tree struct: ...
3
votes
0answers
86 views

Is this minimal Go cookie authentication system safe?

I'm working on a login system in Go (Golang). Previously, I was using Gorilla Sessions for this, but I wanted to see if I could reinvent the wheel and make it simpler. Also, I don't need to store ...
1
vote
0answers
21 views

Filesystem-dependant unit-testing in go

I recently rewrote a piece of software to practice unit-testing. I decided to constrain myself and do dependency-free code, so I can do better and easier tests. I came to the following solution while ...
3
votes
1answer
72 views

Convert int64 to custom base64 number string

I want to convert int64 to custom base 64 number string, with this specification: ...
5
votes
1answer
70 views

Number database using binary trees

I recently got interested in Go and wrote a database server which uses a binary tree for data storage for fun. As I have no prior experience in Go, I'd like to gather a bit feedback on my code and ...
2
votes
0answers
33 views

Parsing CSVs for bulk database insertions

I'm writing this as (eventually) part of a larger program. This will serve as the bulk data insertion from .csv files we parse. I'm primarily looking for parts that are breaking Go's formatting, ...
12
votes
1answer
227 views

Go Go Gadget Web Crawler

In A Tour of Go, you are given the following problem: In this exercise you'll use Go's concurrency features to parallelize a web crawler. Modify the ...
2
votes
0answers
47 views

Is this web service synchronized correctly?

I'm new to both concurrency programming and Go. I've written a small server side script that gets the title and ratings of a book for a given ISBN. I've to optimise performance by using a cache and ...
4
votes
1answer
459 views

Unmarshaling dynamic JSON

I have JSON object response returned from the server which is similar to this one: ...
3
votes
1answer
50 views

Command line flags & sorting algorithms

I've made my first-ever program in Go, which sorts a given input of integers. There are 2 options: The list of unsorted integers and the algorithm to use. Since it's my first go project I'm a bit ...
4
votes
1answer
243 views

Merge sort in Golang

I am just starting out with golang. I implemented the merge sort algorithm just to practice. Any suggestions or criticisms regarding the coding style? ...
7
votes
2answers
174 views

Subnetting calculator in Go

Whenever I try to learn a new language, I write a subnetting calculator. Here's my attempt with Go. In particular, I think I'm not writing idiomatic Go, as well as abusing ...
1
vote
0answers
34 views

Daisychain channels

I watch the presentation about concurrent programming presented by Rob Pike and I saw the daisychain example. I tried to rewrite this code to make it more readable. Everything went well, but I am ...
7
votes
1answer
755 views

Golang HTTP status checker

I'm writing my first somewhat production ready (or not) Go program and could do with some feedback from someone more experienced with go. The code reads a list of URLs from a JSON file and then makes ...
4
votes
1answer
597 views

Graph (adjacency list) for BFS and DFS in Golang

I am trying to implement a Graph data structure in Golang and choose to use adjacency list representation. When starting to implement adjacency list, I have an idea ...
4
votes
1answer
94 views

Channels vs. “for loop” prime number generator

I've found a question on SO (here), which is a prime number generator that uses channels. First of all, I had some trouble to find out how this code works, but later on, I saw the fun of it. Then, all ...
4
votes
0answers
47 views

Reading OS X file tags

I'm investigating Go for use in our internal network / office project management system, and need a way to check and edit the color tags that you can set in Finder on files or folders (extended ...
4
votes
0answers
100 views

Equivalent binary trees (structure & values)

I am following the Golang tour and I have been asked to build a couple of functions to manipulate binary trees. My code runs as expected, but I would like to know if I could further improve my code. ...
3
votes
2answers
67 views

Go string formatting

I'm very new to Go, and am trying to get some experience by re-writing some of my Python code in Go. Below is a function that takes an IP address (ipv4) in integer form and returns the string ...
5
votes
1answer
99 views

Is my spin-lock implementation correct?

I'm working on a project where a spinlock is more appropriate than a mutex, and after few tries I came up with: ...
3
votes
2answers
230 views

in_array() in Go

This function's objective is very simple. It takes array and checks if val is a value inside of this array. It returns whether ...
2
votes
1answer
90 views

Deferred log file close

My code works in that it compiles, and when executed writes out a log file using a buffered writer. But I wonder whether: I am correct in assuming that this actually winds up deferring a ...
1
vote
1answer
67 views

Securely shuffling an array with 75 numbers in Go

I have a SHA512 hex string consisting of my random input and that of the user. Since rand.Seed only accepts a int64 I can never ...
7
votes
2answers
111 views

Is this a good way of managing parallel go routines when I care about ordering of results?

I have a process with a number of stages that need to be completed in sequence. Each stage is largely parallelisable, involving looping over a large data structure and processing each item ...
3
votes
1answer
39 views

File-based Equation Evaluation in Go

My program 'Monkey', written in Go, can take a file like this: + 9 13 / 10 2 And prints the output (in the case for the 'file' above, '22' and '5'.) Variables ...