Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Learning Golang (Part 1)

DZone's Guide to

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 Structure: //defines a mo...

· Web Dev Zone ·
Free Resource

Jumpstart your Angular applications with Indigo.Design, a unified platform for visual design, UX prototyping, code generation, and app development.

A few random notes from my initial attempts learning Golang.

Compile and run:

go run source.go

Build executable:

go build source.go

Package main defines a standalone executable:

//defines a module
package main

Import required packages:

import packagename

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

Functions:

func functionName() {
  //code
{

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 (
    "fmt"
)

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

I get this error:

Ok, first lesson, a package is required, so let's add it:

package main

Creating a Run As... config in Eclipse for my project and then attempting to run it 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 got 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!

Take a look at an Indigo.Design sample application to learn more about how apps are created with design to code software.

Topics:
web dev ,tutorial ,golang ,go

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}