Learning Golang (part 1)

A few random notes from my initial attempts learning Golang.

Compile and run:

go run source.go

Build executable:

go build source.go


//defines a module
package packagename

Package main defines a standalone executable:

package main

Import required packages:

import packagename

Semicolons are not required unless there’s more than one statement on a line


func functionName() {

Arguments passed to an app are accessible via the array os.Args. os.Args[0] contains the name of the app itself.

Ok, let’s try my first hello world in Eclipse with the Goclipse plugin installed:

import (
func main(){   fmt.Println("hello!")

I get this error:

Ok, first lesson, a package is required, so added:

package main

Creating a Run As… config in Eclipse for my project and then attempting to Run again gave me this useful message:

Ok, so I moved my source into an app folder (/src/main) but this gave me additional errors. At this point I’ve errors about $GOPATH:

Looking through the Project properties, this dialog with this option adds the Project location into the required GOPATH:

Now my first app runs successfully!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.