go version
If you use gvm to install Go, you can change Go versions easily.
-
Check the available versions
gvm list
-
Swtich version
gvm use go1.18
-
Install new version
gvm install go1.17
-
Uninstall a version
gvm uninstall go1.17
package main
import "fmt"
func main() {
fmt.Println("Hello, World")
}
-
Run with
go run
go run main.go Hello, World
-
Run with compiled file:
go build main.go
./main Hello, World
func greet(language, name string) (string, error) {
if language == "Spanish" {
return fmt.Sprintf("Ola, %s", name), nil
}
return fmt.Sprintf("Hello, %s", name), nil
}
func main() {
fmt.Println("Hello, World")
greetText := greet("Spanish", "Naka")
fmt.Println(greetText)
}
- Format:
go fmt main.go
- Validate: report likely mistakes in packages
go vet main.go
- Install
go install <package>
- Import necessary libraries and remove unnecessary libraries.
go mod tidy
For more details, https://pkg.go.dev/cmd/go