Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

want to fix panic:about " json: cannot unmarshal array into Go value of type xx" #25

Open
Piwriw opened this issue Mar 8, 2024 · 1 comment

Comments

@Piwriw
Copy link

Piwriw commented Mar 8, 2024

How to reproduce

when I use the client to GetReposiory will be panic

	repositories, err := harborClientV2.Repository.GetRepository(context.TODO(), &repository.GetRepositoryParams{ProjectName: "library"})
	if err != nil {
		t.Error(err)
	}
	t.Log(repositories.GetPayload())

How to solve

I find it is a problem about there is a array but it hope to is a struct json .
This issue will be resolved by modification readResponse.

func (o *GetRepositoryOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {

	o.Payload = make([]models.Repository,0)

	if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
		return err
	}

	return nil
}

You will get suceess.
image

Want to support

I want to know it is ok? .There are a lot of problems just like this. If it is no problem, I will create PR to sovle and add some Test Func
If you agree with me, Please LGMT Your name.

Link Other issues

#18

@Piwriw Piwriw changed the title want to fix panic:about " json: cannot unmarshal array into Go value of type models.Repository" want to fix panic:about " json: cannot unmarshal array into Go value of type xx" Mar 8, 2024
@Piwriw
Copy link
Author

Piwriw commented Mar 8, 2024

/label help wanted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant