In libraries, the package need not be called main nor do you need the main
function. As libraries aren’t applications, you cannot build a binary file with them and you need the main
package that is going to use them.
package arithmetic
func Sum(args ...int) (res int) {
for _, v := range args {
res += v
}
return
}
package main
import (
"fmt"
"github.com/myName/libraries/arithmetic"
)
func main() {
sumRes := arithmetic.Sum(5, 6)
subRes := arithmetic.Subtract(10, 5)
multiplyRes := arithmetic.Multiply(8, 7)
divideRes, _ := arithmetic.Divide(10, 2)
fmt.Printf("5+6 is %d. 10-5 is %d, 8*7 is %d and 10/2 is %f\n", sumRes, subRes, multiplyRes, divideRes)
}