spec does not allow you to specify parameter names when calling a function. You can only list the values you want to pass as arguments. You must specify values for all parameters (except the variational parameter), and you must specify them in the expected order.
The closest thing you can get to what you want is to convey the structure. Create a structure type that wraps your current parameters and modifies your function to accept the value of this structure (or a pointer to it):
type Params struct { name, address, nick string age, value int } func MyFunction(p Params) {
Then, of course, you should access these fields using selector in the p parameter, for example:
func MyFunction(p Params) { // perform some operations fmt.Printf("%s lives in %s.\n", p.name, p.address) }
Also note that as an additional “gain” (or load), the “parameters” (which are the fields of the structure parameter) become optional and disordered: you do not have to specify a value for all fields and you can list the fields in any order.
You can also call it like this:
MyFunction(Params{ name: "Alice", address: "Washington", })
Output the above calls (try on the Go Playground ):
Bob lives in New York. Alice lives in Washington.
If you do not want (or cannot) change the function to accept the struct parameter, then you can leave it as is and create a new helper function that will have this struct parameter, and all this will call the original function, passing the corresponding fields as arguments:
func MyFunction(name, address, nick string, age, value int) {
And then you can call MyFunction() indirectly as follows:
MyFunction2(Params{ name: "Bob", address: "New York", nick: "Builder", age: 30, value: 1000, })
See this related question: Getting method parameter names in the Golang