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:

In my case this is:

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".

Next open a cmd prompt and cd into 

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