Thursday, December 31, 2009

gvim - fatal error: can't find import: fmt?

I have setup go related environment variables in my ~/.bashrc as follows


GOROOT=$HOME/go
GOOS=linux
GOARCH=amd64
GOBIN=$HOME/bin
export GOROOT GOOS GOARCH GOBIN PATH


When I compile from vi (:make) in terminal, everything is fine. However, when I do the same from gvim (window), I was getting

fatal error: can't find import: fmt


A quick google search pointed me to this

So, gvim is not seeing those environment variables. I confirm in gvim with

:echo $GOROOT


Reports an empty string. So I edit $MYVIMRC (:e $MYVIMRC) and add the following

:let $GOROOT='/home/amitava/go'
:let $GOARCH='amd64'
:let $GOOS='linux'


Worked like a charm!

Wednesday, December 30, 2009

My exploration of Google "go" programing language

1. return
Named return variables are available within the scope of the function. Consider the following funciton


func SomeFunc() (foo int, bar int) {
// notice how foo and bar is already defined in the body and a return w/no arg returns those values
foo = 10
bar = 20
return // compiler knows it has to return foo & bar
)


2. Type Assertion (ala dynamic_cast)
Given an interface type, it can be coerced to another interface type (at runtime) provided the underlying type supports both the interfaces

Look for type assertion here (Go For C++ Programmers). You have to scroll down to the relevant section. Just use browser search - use type assertion

3. defer - a piece of code to run when the surrounding function returns. Cool feature! See Here

4. dot import

Import declaration Local name of Sin
import . "lib/math" Sin (as opposed to math.Sin)

See go-doc - import

Sunday, December 13, 2009

Xen block device

While reading "The Book of Xen", I ran into a snag with attaching a block device in dom0

# xm block-attach 0 duncan. img /dev/xvda1 w 0

I am expecting /dev/xvda1 to show up now, but it doesn't. As suggested in the book, I try

# /mknod /dev/xvda b 220 0

Doesn't work (btw, the book has a typo, it should be 202 not 220)

Turns out, the xenblk kernel module was not loaded. Do this
# modprobe xenblk
# lsmod | grep xenblk

Now xm block-attach works like a charm