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...
Join the DZone community and get the full member experience.
Join For FreeA 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!

Published at DZone with permission of Kevin Hooke, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
What Is React? A Complete Guide
-
Integration Architecture Guiding Principles, A Reference
-
Clear Details on Java Collection ‘Clear()’ API
-
Using OpenAI Embeddings Search With SingleStoreDB
Comments