Go concepts

The capital the first word, go run, environment, bin, src, go build, creating virtual env in go, why go (garbage collection), compilation, go offline documentation,

Packages: In go, everything is in package, your main code is named as package main ( see hello.go )and there can be only one main package inside the working directory.

hello.go
// Some code
package main

import(
    "fmt"
    )
    
func main(){
    fmt.Println("hello, Go")
}

The list of packages offered by Go can be found here.

Main package is starting point for a program and it import packages from import path fmt. The name of the package name is the last name of import path for example in case of math/rand, rand will be the name of the package.

Import: you either import built-in package or from third party. In anyway a package can be imported independently or as factored method.

package.go
// Some code
package main

import "fmt"

import(
    "math\rand"
    "github.com/gorilla/mux"
)

Last updated

Was this helpful?