Go is a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.
3
votes
1answer
35 views
Map strings to (const) ints
I'm imagining go generate would be a good tool for this. I want to convert strings to ints to save space.
...
8
votes
1answer
80 views
cat program in Go
In order to learn Go, I've implemented the cat program in Go. I want to know if the code is idiomatic and what could be improved.
...
5
votes
1answer
118 views
Classifying by age
Problem:
Classify the user (such as infant, child, teenager, adult) based on user's age.
Solution
Please run the solution here.
The code snippet written below works well as expected. I want to ...
10
votes
1answer
202 views
A minimal version control system
I just finished writing a simple version control. You register files using "add", and then "com" will save them inside a directory, with an ID attached to it, same ID for all files. With "rev" it will ...
3
votes
1answer
69 views
Bottom up mergesort - singly linked list
I have written the following program in Go to mergesort a singly linked list. It does bottom up merge sort and hence does not have to find the mid of the linked list. Please review the algorithm and ...
4
votes
0answers
40 views
Gin web framework middleware
As a beginner in Go, I'm seeking feedback on a web framework middleware I wrote up. I reckon that knowledge of the web framework is not needed for the code review.
The goal of this middleware is ...
2
votes
0answers
17 views
0
votes
0answers
13 views
Generic JWT Handler
I'm developing a Go REST service that uses JWT (JSON Web Tokens) for authentication.
I've written a JWTHandler which validates the token using a Validation Handler. If validation succeeds, the ...
9
votes
0answers
89 views
Concurrency interview
A little while back I had an interview where they posed a problem, in summary:
Watch a certain directory, and process incoming JSON files
These JSON files have various "Type" fields
Every second ...
4
votes
0answers
34 views
Bayesian spam filter interface
In essence, what I'm looking to do is split a string into one-word and two-word segments, and train classifiers against them. First it lowercasifies the string, then strips all non-alphanumeric ...
2
votes
1answer
38 views
Using goroutines to bruteforce a secret code
For a puzzle I had to brute force a password. I've never used goroutines before, and I don't have much experience in concurrency.
This is the cksum function, which takes an array of the ASCII code ...
3
votes
0answers
24 views
Project Euler #2 in Go
I just learned Go (yesterday in fact) and today I made this solution to Project Euler #2. The problem is to sum the even Fibonacci numbers. My program uses the matrix representation of the linear ...
3
votes
0answers
42 views
Golang A* Pathfinder
This is a generalized A* pathfinder in Go. I am new to the language and am eager for advice about best practices.
In particular, I am not sure if the type assertion I make in ...
2
votes
1answer
55 views
Calculate total width of a range of numbers
I'm mostly curious if there's a faster or more efficient algorithm I could use. I created this for a unique side project, as well as for an issue at work, so what the function does (e.g., return a ...
7
votes
0answers
67 views
Go Fish game written in Go
A couple months back I made a go fish game in Go, just for the sake of that pun. It was pretty poorly done and made experienced Go-ers cry when they looked at it. I rewrote some of it to be more ...
4
votes
0answers
67 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
72 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 ...
1
vote
1answer
34 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
46 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
861 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
135 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
89 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
...
3
votes
0answers
108 views
Nuts and bolts algorithm
I am trying to learn Golang.
This is a problem from Robert Sedgewick's Algorithms 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
29 views
Binary tree isSame()
Please help me review this code. I want to make it both accurate and more Go-styled.
Go Playground code
...
13
votes
0answers
113 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
38 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
83 views
2
votes
3answers
59 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
40 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 ...
3
votes
1answer
38 views
Removing 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
145 views
Binary heap implementation in Golang
I have implemented a binary heap in Go to get familiar with the language.
GitHub
...
3
votes
1answer
250 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
790 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 ...
5
votes
2answers
92 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
38 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
44 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
699 views
Golang concurrent HTTP request
I wanted to test the performance of concurrent http request in Go against node.js:
...
3
votes
1answer
53 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
39 views
Basic Binary Tree in Go
As an exercise I have written a basic binary tree implementation in Go.
Tree struct:
...
4
votes
0answers
133 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
104 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
40 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, ...
14
votes
1answer
346 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
51 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
762 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
298 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
177 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 ...