Documentation ¶
Index ¶
- Variables
- func Body() qiwlar.Decorator
- func Cookie(c *http.Cookie) qiwlar.Decorator
- func CustomFormat(formatter func(qiwlar.AnswerScheme) interface{}) qiwlar.Decorator
- func Delete(path string) qiwlar.Decorator
- func Get(path string) qiwlar.Decorator
- func Head(path string) qiwlar.Decorator
- func Header(key, value string) qiwlar.Decorator
- func Options(path string) qiwlar.Decorator
- func Params() qiwlar.Decorator
- func Patch(path string) qiwlar.Decorator
- func Post(path string) qiwlar.Decorator
- func Put(path string) qiwlar.Decorator
- func Query() qiwlar.Decorator
- func StatusCode(code int) qiwlar.Decorator
- type RCBody
Constants ¶
This section is empty.
Variables ¶
View Source
var Validate = func() func(interface{}) qiwlar.Decorator { validate := validator.New(validator.WithRequiredStructEnabled()) return func(dto interface{}) qiwlar.Decorator { nDto := reflect.New(reflect.TypeOf(dto)).Interface() return func(q *qiwlar.QResponse) interface{} { b, err := io.ReadAll(q.R.Body) if err != nil { q.StatusCode = 400 q.Results = append(q.Results, nDto) return "failed to read request body" } err = json.Unmarshal(b, nDto) if err != nil { q.StatusCode = 400 q.Results = append(q.Results, nDto) return "unable to convert" } err = validate.Struct(nDto) if err != nil { q.StatusCode = 400 q.Results = append(q.Results, nDto) if _, ok := err.(*validator.InvalidValidationError); ok { fmt.Println(err) return err } var errors []map[string]interface{} for _, err := range err.(validator.ValidationErrors) { errors = append(errors, map[string]interface{}{ "field": err.Field(), "tag": err.Tag(), "param": err.Param(), }) } return errors } q.Results = append(q.Results, reflect.ValueOf(nDto).Elem().Interface()) return nil } } }()
Functions ¶
func CustomFormat ¶
func CustomFormat(formatter func(qiwlar.AnswerScheme) interface{}) qiwlar.Decorator
func StatusCode ¶
Types ¶
type RCBody ¶
type RCBody io.ReadCloser
Click to show internal directories.
Click to hide internal directories.