#go validator problem

20 messages · Page 1 of 1 (latest)

zinc ore
#

I want to check whether the string named RedirectUri is a url, but it gives an error, my data schema is like this;

type TokenReq struct {
    ClientId     string `json:"clientId" validate:"excluded_unless=GrantType password"`
    ClientSecret string `json:"clientSecret" validate:"excluded_unless=GrantType password"`
    Username     string `json:"username" validate:"required_if=grantType password,email"`
    Password     string `json:"password" validate:"required_if=grantType password"`
    GrantType    string `json:"grantType" validate:"required,oneof=password authorization_code refresh_token"`
    RefreshToken string `json:"refreshToken" validate:"required_if=GrantType refresh_token"`
    RedirectUri  string `json:"redirectUri" validate:"url,excluded_unless=GrantType password"`
}
#

Validator lib: github.com/go-playground/validator/v10

#

Error msg: Key: 'TokenReq.RedirectUri' Error:Field validation for 'RedirectUri' failed on the 'url' tag

forest tulip
#

Are you sure it's a url, not a uri?

zinc ore
#

yes it is a url

forest tulip
#

Then why is it called RedirectUri 😛

zinc ore
forest tulip
#

RedirectUri string `json...

final wave
#

how is the input looks like?

zinc ore
final wave
final wave
#

fix the input

forest tulip
#

What's the input?

zinc ore
#

intput is not a problem 1 second

#

This is a input

final wave
zinc ore
forest tulip
#

excluded_unless=GrantType password

It means it will try to validate RedirectUri if grantType=password

#

maybe you want excluded_if?