Thursday, April 16, 2015

Day 3 - The famous Hello

Today I want to test if all my previous preperations where correct and create my first runnable Go programm.


Create a new directory for the hello world test code inside your workspace:

$GOPATH\src\github.com\<yourgithubusername>\hello
In my case this is:
D:\goworkspace\src\github.com\kimxilxyong\hello

Inside the hello directory create a file named hello.go and copy the following code into it:

package main

import "fmt"

func main() {
    fmt.Printf("Hello, world. Heureka!\n")
}

One important point here is that the opening curly brace MUST be on the same line as func main! (Thats some Go specific syntax, see: Curly brace in Go)

You can edit the code with any editor you like, i am using LiteIDE which is a "simple, open source, cross-platform Go IDE".
http://sourceforge.net/projects/liteide

Next open a cmd prompt and cd into 
$GOPATH\src\github.com\<yourgithubusername>\hello

Run "go install" to compile, this will put the runable hello binary into  $GOPATH\bin
(no output is good, means no error occured)

Run "hello" and hope ...






Aaaand ... it worked, Heureka !!





No comments:

Post a Comment