Getting Started with Go: Essential Tips and First Hello World
This article shares practical Golang notes, covering compilation, package structure, basic syntax, common pitfalls like GOPATH issues, and step‑by‑step screenshots of setting up a Hello World program in Eclipse.
The author shares initial Golang notes and a hands‑on tutorial.
Learning Go: some scattered notes from the early attempts.
Compilation and Execution
Compile and run: go run source.go Build and run:
go build source.goPackage and Imports
package maindefines an executable module.
Import required packages: import packagename Semicolons are unnecessary unless multiple statements appear on one line.
Functions
Define a function:
function functionname(){ //code }Command‑Line Arguments
Access arguments via os.Args or os.Args[0], where the first element is the program name.
First Hello World in Eclipse
Install the Goclipse plugin and create a simple program:
import ( "fmt" ) func main(){ fmt.println("Hello World!") }The initial run produces an error (shown below):
Resolving GOPATH Issues
After moving the source to /src/main, a GOPATH‑related error appears:
Configure the project properties to add the project location to the required GOPATH:
Finally, the first program runs successfully:
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
