form icon indicating copy to clipboard operation
form copied to clipboard

Fails to decode struct if field is missing

Open fogfish opened this issue 5 years ago • 1 comments

The library fails to decode a struct if field is missing.

E.g. I do have a struct

type TokenExchange struct {
  Type string `form:"grant_type"`
  Code string `form:"code"`
}

The input string to parse

grant_type=authorization_code&code=xxx&client_id=xxx

The library fails to decode string with an error

client_id doesn't exist in main.TokenExchange

I would expect that library skips client_id.

fogfish avatar Apr 04 '20 15:04 fogfish

If you can set ignoreUnknownKeys to true and you won't have this problem anymore. https://github.com/ajg/form/blob/523a5da1a92f01b01f840b61689c0340a0243532/decode.go#L59

fizzy123 avatar Jul 30 '20 22:07 fizzy123