May 2010
4 posts
The Changelog Podcast - Interview with Rob Pike →
Why Google's Go is a Bore →
Asynchronous Go API idioms →
April 2010
1 post
Hacker News: An Introduction to Google's Go... →
March 2010
14 posts
release.2010-03-30 →
Maps now return a default value! Not really sure of the other features yet or what they mean, need to look into panic and recover more though.
Broken abstractions in Go →
Rendering distance fields using the Go-language →
Proposal for an exception-like mechanism →
autodetect go.vim highlighting
Instead of constantly having to hit :setf go when editing your Go files in vim, just drop this into ~/.vim/ftdetect/go.vim:
autocmd BufNewFile,BufReadPost *.go set filetype=go
go.vim : Syntax file for the Go programming... →
Installing Go on Ubuntu →
regexp.MatchString
Everyone loves Regular Expressions, right? Instead of writing an annoying parser for our first assignment, expr, it was definitely easier to just use Go’s built in regexp package.
The easiest way is just to use regexp.MatchString:
matched, error := regexp.MatchString("[0-9]+", "1337")
This returns a boolean, matched, and an os.Error in the second variable. This whole multiple return thing...
git precommit hook for gofmt
It’s no surprise I like Ruby, and gofmt is a great idea I wish Ruby could enforce. Instead of forgetting to run it constantly, let’s have git run it. In your .git/hooks/pre-commit:
#!/usr/bin/env ruby
Dir["**/*.go"].each do |go|
if File.basename(go) !~ /^_/
puts "gofmt #{go}"
system("gofmt -w=true #{go} && git add #{go}")
end
end
Make sure you run chmod a+x on...
flag
Checking out the flag package, Go’s built in command line argument parser. Here’s a simple example:
// flag.go
package main
import (
"flag"
"fmt"
)
var code *int = flag.Int("areacode", 716, "give me your codes")
func main() {
fmt.Printf("Testing out flags!\n");
flag.Parse();
fmt.Println("areacode has value ", *code);
}
# Makefile
include $(GOROOT)/src/Make.$(GOARCH)
...
gofmt
From the FAQ:
…the program gofmt is a pretty-printer whose purpose is to enforce layout rules; it replaces the usual compendium of do’s and don’ts that allows interpretation. All the Go code in the repository has been run through gofmt.
usage: gofmt [flags] [path ...]
-tabwidth=8: tab width
-trace=false: print parse trace
-r="": rewrite rule (e.g., 'α[β:len(α)] ->...
go-repl →
Took some hacking to get working since recently in go the way to convert a String into a series of Bytes changed:
There is one language change: the ability to convert a string to
[]byte or []int. This deprecates the strings.Bytes and strings.Runes
functions. You can convert your existing sources using these gofmt
commands:
gofmt -r 'strings.Bytes(x) -> []byte(x)' -w...
hg log -r 0:4
changeset: 0:f6182e5abf5e
user: Brian Kernighan <bwk>
date: Tue Jul 18 19:05:45 1972 -0500
summary: hello, world
changeset: 1:b66d0bf8da3e
user: Brian Kernighan <bwk>
date: Sun Jan 20 01:02:03 1974 -0400
summary: convert to C
changeset: 2:ac3363d7e788
user: Brian Kernighan <research!bwk>
date: Fri Apr 01 02:02:04 1988...
Installing Go on OSX 10.5
Heavily inspired by this blog post. With MacPorts installed:
sudo port install python easy_install
sudo easy_install -U mercurial
In your .zshrc:
export GOROOT=[path to where you want the language installed]
export GOOS=darwin
export GOARCH=386
export GOBIN=[path to where you store personal bin files]
Run:
source .zshrc
hg clone -r release https://go.googlecode.com/hg/ $GOROOT
cd...