30 lines
555 B
Go
30 lines
555 B
Go
|
package utils
|
||
|
|
||
|
import (
|
||
|
"approveflow/app/http/base"
|
||
|
"encoding/json"
|
||
|
"github.com/Superdanda/hade/framework/gin"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func QuickBind[T any](c *gin.Context) *T {
|
||
|
var params T
|
||
|
if err := c.ShouldBindJSON(¶ms); err != nil {
|
||
|
c.ISetStatus(http.StatusBadRequest).IJson(base.Fail("参数错误"))
|
||
|
return nil
|
||
|
}
|
||
|
return ¶ms
|
||
|
}
|
||
|
|
||
|
func Convert(origin interface{}, target interface{}) error {
|
||
|
data, err := json.Marshal(origin)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
err = json.Unmarshal(data, target)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|