diff --git a/context.go b/context.go index 3d21cbc..30c750b 100644 --- a/context.go +++ b/context.go @@ -68,36 +68,6 @@ func (c *Context) RequestParamExists(key string) bool { return c.Request.httpRequest.Form.Has(key) } -func (c *Context) GetRequesForm() interface{} { - return c.Request.httpRequest.Form -} - -func (c *Context) GetRequesBodyMap() map[string]interface{} { - var dat map[string]any - body := c.Request.httpRequest.Body - if body != nil { - if content, err := io.ReadAll(body); err == nil { - json.Unmarshal(content, &dat) - } - } - return dat -} - -// get json body and bind to dest interface -func (c *Context) GetRequesBodyStruct(dest interface{}) error { - body := c.Request.httpRequest.Body - if body != nil { - value := reflect.ValueOf(dest) - if value.Kind() != reflect.Ptr { - fmt.Println("dest is not a pointer") - return errors.New("dest is not a pointer") - } - err := json.NewDecoder(body).Decode(dest) - return err - } - return nil -} - func (c *Context) GetHeader(key string) string { return c.Request.httpRequest.Header.Get(key) } diff --git a/validator.go b/validator.go index ba4d8a2..7d8eac8 100644 --- a/validator.go +++ b/validator.go @@ -33,14 +33,18 @@ func (v *Validator) Validate(data map[string]interface{}, rules map[string]inter vr = validationResult{} vr.hasFailed = false res := map[string]string{} - for rule_key, rule_val := range rules { - rls, err := parseRules(rule_val) + for key, val := range data { + _, ok := rules[key] + if !ok { + continue + } + rls, err := parseRules(rules[key]) if err != nil { panic(err.Error()) } - err = validation.Validate(data[rule_key], rls...) + err = validation.Validate(val, rls...) if err != nil { - res[rule_key] = fmt.Sprintf("%v: %v", rule_key, err.Error()) + res[key] = fmt.Sprintf("%v: %v", key, err.Error()) } }