axfor/bast

add validate to bast

Opened this issue · 1 comments

axfor commented

add validate to bast

support struct

josn etc...

such as:

    type vv struct {
		A string  `json:"a" v:"required|min:1"`
		B *string `json:"b" v:"required|min:1"`
	}

	g := "a"
	v := vv{A: "a", B: &g}
	v2 := []vv{{A: "b", B: &g}}
	v3 := map[string]vv{"c": vv{A: "c", B: &g}}

	vr := Validator{}

	err := vr.Struct(v)
	if err != nil {
		t.Error(err)
	}

	err = vr.Struct(v2)
	if err != nil {
		t.Error(err)
	}

	err = vr.Struct(v3)
	if err != nil {
		t.Error(err)
	}

support url.Values

*http.Request etc...

such as:

    v4 := url.Values{
        "d": {
            "15",
        },
        "e": {
            "eeeee",
        },
        "f": {
            "ff",
        },
    }
    vr := Validator{}
    err := vr.Request(v4, "d@required|int|min:12|max:16", "e@required|min:5")
    if err != nil {
        t.Error(err)
    }
axfor commented

Support for the validator

note:will continue to add new validator

  • date
  • email
  • int
  • ip
  • match
  • max
  • min
  • required
  • sometimes