[Go] Package
Create a new folder utils
with a new file math.go
package utils
import (
"fmt"
)
func printNum(num int) {
fmt.Println("Current number is: ", num)
}
// Add multi int number together return total int
func Add(nums ...int) int {
total := 0
for _, num := range nums {
printNum(num)
total += num
}
return total
}
In Go package, any func
with captlized name will be auto exported. And you must add comments for that function.
Any func
with lower case name will be private to that file.
Import the local package:
package main
import (
"fmt"
math "<path_to_folder>/utils"
)
So, we import the file, and named it as math
. You can also use default package name utils