Difference between revisions of "Golang/Basics"

From Ever changing code
Jump to navigation Jump to search
(Created page with "= Main function = <source lang=golang> package main import ( "fmt" "time" ) func main() { fmt.Println("Welcome", time.Now()) } </source>")
 
Line 11: Line 11:
}
}
</source>
</source>
= Go modules =
A Go Module is nothing but a collection of Go packages. Why do we need Go modules to create a custom package? The answer is the import path for the custom package we create is derived from the name of the go module. In addition to this, all the other third-party packages(such as source code from github) which our application uses will be present in the <code>go.mod</code> file along with the version. This go.mod file is created when we create a new module.

Revision as of 15:40, 29 August 2021

Main function

package main
import (
	"fmt"
	"time"
)

func main()         {
	fmt.Println("Welcome", time.Now())
}

Go modules

A Go Module is nothing but a collection of Go packages. Why do we need Go modules to create a custom package? The answer is the import path for the custom package we create is derived from the name of the go module. In addition to this, all the other third-party packages(such as source code from github) which our application uses will be present in the go.mod file along with the version. This go.mod file is created when we create a new module.