GoogleCloudPlatform / go-endpoints

Cloud Endpoints for Go
https://go-endpoints.appspot.com
Apache License 2.0
255 stars 56 forks source link

Structures using custom types fail to set default values during validation. #139

Open danjacques opened 8 years ago

danjacques commented 8 years ago

In validateField, reflect.Value's Set method is called on a type to install its default value. If the target field is a custom type, this will panic with a type mismatch in reflect.

type Trinary string

type CoolRequest struct {
  Value Trinary `endpoints:"d=ohai"`
}

Minimally, this should error instead of panic. Ideally, it would check Kind and use SetString or equivalent instead of raw Set.

s-mang commented 7 years ago

the current behavior (panic) is to try to ensure an issue like in your example is caught in dev or testing, and not production.

but +1 your proposed enhancement sounds good to me. if you can send a PR, I'd be grateful.