Packages and Modules
Import Groups
Go import blocks list the packages a file uses.
Import Groups
import_groups.go
package main
import (
"fmt"
"sort"
"strings"
)
func main() {
var phrase =
words := strings.Fields(phrase)
sort.Strings(words)
first := words[0]
fmt.Println("phrase=", phrase)
fmt.Println("count=", len(words))
fmt.Println("first=", first)
}
package main
import (
"fmt"
"sort"
"strings"
)
func main() {
var phrase =
words := strings.Fields(phrase)
sort.Strings(words)
first := words[0]
fmt.Println("phrase=", phrase)
fmt.Println("count=", len(words))
fmt.Println("first=", first)
}
package main
import (
"fmt"
"sort"
"strings"
)
func main() {
var phrase =
words := strings.Fields(phrase)
sort.Strings(words)
first := words[0]
fmt.Println("phrase=", phrase)
fmt.Println("count=", len(words))
fmt.Println("first=", first)
}
import group
An import block keeps related imports together and makes package dependencies visible.