How Do You Troubleshoot the Golang Error “missing function body”?

Problem scenario
You run a Golang program with a function that uses a map. You get this error:

./foobar.go:33:6: missing function body
./foobar.go:33:44: syntax error: unexpected {, expecting comma or )

What should you do?

Solution
Omit the "{}" in passing map data types to the function. The syntax for declaring a map will include {}.

Here is an example of how to properly define a map:

goodmap := map[string][5]string{}

But when you are defining a function that will accept a map as a parameter, omit the "{}" from the syntax. Here is an example:

func coolone(mapofb map[string][5]string, foobar string) string { ...

Leave a comment

Your email address will not be published. Required fields are marked *