gorilla/schema

Decode value of type *string

aigoya opened this issue · 2 comments

I'm struggling with schema.decode of type *string from html form.

schema version: v1.2.0
golang version: v1.15.6

Here is my go code

type Staff struct {
	ID          string
	Birthday   *string
}

Here is my html form

<form>
	<input type="text" name="ID" value="ST00001"> 
	<input type="date" name="Birthday" value=""> 
</form>

because birthday is not provide, after I bind this I wish to get <nil>
but schema provide pointer to blank string instead of <nil>

my question is
How can I get <nil> instead of pointer to the blank string?

Dri0m commented

I stumbled upon this too. Unless we're both missing something, schema seems to zero nil values even if it's configured not to zeroEmpty. Since it's still worth it for me to use the parser, I use a bit of reflection to convert all empty strings in the struct back to nil. Annoying.

stale commented

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.