mirror of
https://gitee.com/goploy/goploy.git
synced 2024-12-05 21:48:39 +08:00
26 lines
470 B
Go
26 lines
470 B
Go
|
package controller
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"errors"
|
||
|
"github.com/zhenorzz/goploy/core"
|
||
|
"gopkg.in/go-playground/validator.v9"
|
||
|
)
|
||
|
|
||
|
// Controller struct
|
||
|
type Controller struct {
|
||
|
}
|
||
|
|
||
|
func verify(data []byte, v interface{}) error {
|
||
|
err := json.Unmarshal(data, v)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if err := core.Validate.Struct(v); err != nil {
|
||
|
for _, err := range err.(validator.ValidationErrors) {
|
||
|
return errors.New(err.Translate(core.Trans))
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|