Skip to content

Instantly share code, notes, and snippets.

@mmitou
Created October 18, 2020 08:58
Show Gist options
  • Save mmitou/8ccbd58b338d5eb1e4661d8a2d995e0a to your computer and use it in GitHub Desktop.
Save mmitou/8ccbd58b338d5eb1e4661d8a2d995e0a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/go-playground/validator/v10"
)
type Hoge struct {
Num string `validate:"number"`
Date string `validate:"datetime=20060102"`
}
func main() {
h := Hoge{Num: "1234.01", Date: "20201231"}
validate := validator.New()
err := validate.Struct(h)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("%+v\n", h)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment