* feat: add alist v3 driver (close #1833) * chore: use generics Co-authored-by: Noah Hsu <i@nn.ci>
This commit is contained in:
@ -28,7 +28,7 @@ func ErrorResp(c *gin.Context, err error, code int, l ...bool) {
|
||||
log.Errorf("%v", err)
|
||||
}
|
||||
}
|
||||
c.JSON(200, Resp{
|
||||
c.JSON(200, Resp[interface{}]{
|
||||
Code: code,
|
||||
Message: hidePrivacy(err.Error()),
|
||||
Data: nil,
|
||||
@ -40,7 +40,7 @@ func ErrorStrResp(c *gin.Context, str string, code int, l ...bool) {
|
||||
if len(l) != 0 && l[0] {
|
||||
log.Error(str)
|
||||
}
|
||||
c.JSON(200, Resp{
|
||||
c.JSON(200, Resp[interface{}]{
|
||||
Code: code,
|
||||
Message: hidePrivacy(str),
|
||||
Data: nil,
|
||||
@ -50,14 +50,14 @@ func ErrorStrResp(c *gin.Context, str string, code int, l ...bool) {
|
||||
|
||||
func SuccessResp(c *gin.Context, data ...interface{}) {
|
||||
if len(data) == 0 {
|
||||
c.JSON(200, Resp{
|
||||
c.JSON(200, Resp[interface{}]{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(200, Resp{
|
||||
c.JSON(200, Resp[interface{}]{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: data[0],
|
||||
|
@ -1,9 +1,9 @@
|
||||
package common
|
||||
|
||||
type Resp struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
type Resp[T any] struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data T `json:"data"`
|
||||
}
|
||||
|
||||
type PageResp struct {
|
||||
|
Reference in New Issue
Block a user