30 lines
621 B
Go
30 lines
621 B
Go
package app
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"gin-server/lib/messages"
|
|
"github.com/astaxie/beego/validation"
|
|
"net/http"
|
|
)
|
|
|
|
// BindAndValid binds and validates data
|
|
func BindAndValid(c *gin.Context, form interface{}) (int, int) {
|
|
err := c.Bind(form)
|
|
if err != nil {
|
|
return http.StatusBadRequest, messages.INVALID_PARAMS
|
|
}
|
|
|
|
valid := validation.Validation{}
|
|
check, err := valid.Valid(form)
|
|
if err != nil {
|
|
return http.StatusInternalServerError, messages.ERROR
|
|
}
|
|
if !check {
|
|
MarkErrors(valid.Errors)
|
|
return http.StatusBadRequest, messages.INVALID_PARAMS
|
|
}
|
|
|
|
return http.StatusOK, messages.SUCCESS
|
|
}
|
|
|