go imports
To demonstrate Go imports, let's consider an example where we have a main package that imports a package called "fmt."
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}
In this example:
- The package main
statement declares that this file is part of the main package.
- The import "fmt"
statement imports the "fmt" package, which provides formatting and printing functions.
- The func main()
function is the entry point of the program.
- Inside the main()
function, fmt.Println("Hello, world!")
uses the Println
function from the "fmt" package to print "Hello, world!" to the console.