OneBite.Dev - Coding blog in a bite size

declare a function with multiple parameter in Go

Code snippet on how to declare a function with multiple parameter in Go

func DoSomething(param1 string, param2 int) {
    // code goes here 
}

This code declares a function with two parameters, a string and an integer. The function is named “DoSomething” and it needs two parameters to be passed into it: a string (param1) and an integer (param2). Inside the curly braces, you can write code that will be executed when the function is called. For example, parameters can be used to do calculations, add values to a variable or use data to output something. The name of the function and the types of the parameters can be changed to match your needs. By declaring a function like this, you can easily reuse it in different parts of your code by simply calling it in the right place.

go