Learn Data Structures and Algorithms with Golang
上QQ阅读APP看书,第一时间看更新

Variadic functions

A function in which we pass an infinite number of arguments, instead of passing them one at a time, is called a variadic function. The type of the final parameter is preceded by an ellipsis (...), while declaring a variadic function; this shows us that the function might be called with any number of arguments of this type.

Variadic functions can be invoked with a variable number of parameters. fmt.Println is a common variadic function, as follows:

//main method
func main() {
var customers []Customer
customers = GetCustomers()
fmt.Println("Before Insert",customers)
var customer Customer
customer.CustomerName = "Arnie Smith"
customer.SSN = "2386343"
InsertCustomer(customer)
customers = GetCustomers()
fmt.Println("After Insert",customers)
}

Run the following commands:

go run database_operations.go

The following screenshot displays the output:

Let's start the update operation in the next section.