asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
6.02k stars 556 forks source link

How to verify that the string is empty? Use length to judge? #395

Closed rookiefront closed 4 years ago

rookiefront commented 4 years ago
package main

import (
    "fmt"
    "github.com/asaskevich/govalidator"
)

type T struct {
    Title  string `json:"title" valid:"required"`
    Content string `json:"content" `
    Text string `json:"text" valid:"required"`
}

func main() {
    _f := T{
        Title:   "",
        Content: "",
        Text:    "",
    }

    _, err := govalidator.ValidateStruct(_f)
    fmt.Println(err)
    // IS nil
}

How to verify that the string is empty? Use length to judge?

migueleliasweb commented 3 years ago

I'm having the same problem. What was the solution for this? @codexuexi

migueleliasweb commented 3 years ago

Might be related to: https://github.com/asaskevich/govalidator/issues/359