Home > Backend Development > Golang > Why am I getting \'too many arguments\' when passing a struct to a function?

Why am I getting \'too many arguments\' when passing a struct to a function?

Patricia Arquette
Release: 2024-10-31 23:54:28
Original
1090 people have browsed it

Why am I getting

Compiler Issue: Excess Arguments While Using a Struct as a Parameter

When attempting to utilize a struct as a parameter for the JSON function, an erroneous message surfaces, indicating excessive arguments despite providing all necessary inputs. The struct in question, DataResponse, requires two parameters: Status and Data.

Code Snippet:

Error Message:

Resolution:

The syntax employed for initializing the DataResponse struct is incorrect. The correct approach is to utilize curly braces:

By utilizing curly braces, the struct is properly initialized with the required values and the compiler issue is resolved, enabling the seamless utilization of the struct as a parameter.

The above is the detailed content of Why am I getting 'too many arguments' when passing a struct to a function?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template