In this Getting Started with Golang, we will learn how to use the Golang Functions with or without parameters, functions that have multiple returned types, and exportable or non-exportable functions in the Golang programming language with step by step guide.
#MaharlikansCode
#GolangFunction
#Golang
#LifeAsSoftwareDeveloper
#Maharlikans
#FilipinoSoftwareDeveloper
#ExportableFunctionInGo
#NonExportableFunctionInGo
If you go with extra mile for buying me a cup of coffee, I appreciate it guys: https://ko-fi.com/maharlikanscode
Source Codes:
package main
import (
"errors"
"fmt"
)
// GetAveNum ...
func GetAveNum(num1, num2 float64) (float64, string, int, []string, error) {
if num1 == 0 {
err := errors.New("num1 must not be a zero value")
return 0, "", 0, []string{""}, err
}
ave := (num1 / num2) * 100
return ave, "", 0, []string{""}, nil
}
func main() {
result, _, _, _, err := GetAveNum(0, 8)
if err != nil {
fmt.Println("Oops!, got some errors: ", err)
return
}
fmt.Println("result: ", result)
}