Getting Started With Go: Beginner Tutorial
- Last Updated On: July 3, 2019
- By: Scriptcrunch Editorial
Create a file named main.go
in your project directory.
package main import "fmt" func main() { fmt.Println("Hellow World Scripties") }
From the above code, you should be having the following questions.
- How do I run this code?
- What does package main mean?
- What does import fmt mean?
- What does func mean?
- How is the main.go file organized?
How do I run this code
Open the terminal and browse to your project folder containing main.go file
Execute your main.go program using the following command.
go run main.go
Following are the available commands in Go. In that, we have used run command to execute our hello world program.
build compile packages and dependencies clean remove object files doc show documentation for package or symbol env print Go environment information bug start a bug report fix run go tool fix on packages fmt run gofmt on package sources generate generate Go files by processing source get download and install packages and dependencies install compile and install packages and dependencies list list packages run compile and run Go program test test packages tool run specified go tool version print Go version vet run go tool vet on packages
What does package main mean:
Every go program must start with a package declaration. It is for code organization and reusability.
There are two types of packages
- Executable: Can be executed directly through a command line or a click. This is normally used for creating small utilities. Each executable package is meant for some functionality. Once such example is creating a database backup.
- Reusable: Reusable packages are helper functions or reusable codes or a library that can be called within other program files.
How do you know you are creating an executable package or reusable package?
If your package declaration starts with main, it means you are creating an executable package. Any name other than main will be a reusable package.
What does import fmt mean?
It imports a package named fmt. This package helps in printing text to the standard output. It is a standard library. You can view the list of standard libraries available from here
func main()
func represent function. The go program execution starts from the main function. This main function will always reside in the main package file.
fmt.Println(“Hellow World Scripties”) prints the text mentioned inside the quotes to the standard output.
Scriptcrunch Editorial
Other Interesting Blogs
[50% OFF] Kubernetes Certification Coupons (CKA, CKAD, CKS, KCNA and KCSA)
Looking for CKA coupon and other Kubernetes certification coupon codes? You have come to the right place. Following are the list of
[80% OFF] Linux Foundation Coupon for December 2024
Looking for CKA Coupon and other Linux Foundation certifications coupons? We got you covered. With the latest Linux Foundation Coupon, you can
[65% OFF] Linux Foundation LFCA, LFCS & LFCT Exam Voucher Codes
Linux Foundation has announced up to a $284 discount on its Linux certification programs Linux Foundation Certified IT Associate (LFCA) and Linux