This question already has an answer here:
I want to call a function in Go, and attach to the argument values the argument names
func sum(a int, b int) int {
return a + b
}
func main() {
result := sum(a=4, b=5) // result == 9
}
Is it possible?
</div>
There is no such thing like named arguments in go
, your code isn't logical
This:
result := sum(a=4, b=5)
Is the same as this:
a=4
b=5
result := sum(a, b)
At the moment Go does not have a way to use named argument in functions. If you really need to use named arguments you can try this library go-named-params