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

bug: don't call NumField on anything other than a struct #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zsiec
Copy link

@zsiec zsiec commented Dec 6, 2019

This patch fixes a panic when the request object is a slice rather than a struct or pointer to a struct.

Example panic-ing method: https://github.com/bitmovin/bitmovin-api-sdk-go/blob/master/encoding/encoding_encodings_streams_filters_api.go#L28

NumField is called without checking if the value is a struct and documentation states NumField returns the number of fields in the struct v, It panics if v's Kind is not Struct. (https://github.com/golang/go/blob/master/src/reflect/value.go#L1345)

@zsiec
Copy link
Author

zsiec commented Dec 6, 2019

I've taken a basic approach to fix this here. Depending on your needs, you may choose to loop through the slice and try to enrich structs that have props of type time.Time or *time.Time inside the slice, or even introduce some recursion if the slice is holding slices.

@CLAassistant
Copy link

CLA assistant check
All committers have signed the CLA.

Base automatically changed from master to main February 2, 2021 11:14
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

Successfully merging this pull request may close these issues.

2 participants