Skip to content

is.Latitude/Longitude #185

@kurennoy16

Description

@kurennoy16

I faced the issue with validating geo coordinates using is pkg.
Code example:

type GeoPosition struct {
	Latitude  float32
	Longitude float32
}

func (g *GeoPosition) Validate() error {
	return validation.ValidateStruct(g,
		validation.Field(&g.Latitude, validation.Required, is.Latitude),
		validation.Field(&g.Longitude, validation.Required, is.Longitude),
	)
}

It returns an error like that: GeoPosition: (Latitude: must be either a string or byte slice.)..
That confuses me a bit. I dug into the issues and found that is pkg only applicable to string/slice byte types.

So what's the way to address Latitude/Longitude validation for float types?
I see only one option - custom validation creation, but that's an inconvenient way to handle that. Any plans to use generics for that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions