init repo

This commit is contained in:
VaalaCat
2024-08-28 00:02:28 +08:00
committed by vaalacat
commit 13148b95e3
97 changed files with 10214 additions and 0 deletions

34
common/request.go Normal file
View File

@@ -0,0 +1,34 @@
package common
import (
"github.com/nose7en/ToyBoomServer/defs"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
type ReqType interface {
gin.H |
defs.CommonPaginationRequest | defs.CommonQueryPaginationRequest |
defs.CommonQueryRequest | defs.CommonRequest
}
func GetProtoRequest[T ReqType](c *gin.Context) (r *T, err error) {
r = new(T)
if c.Request.ContentLength == 0 {
return r, nil
}
if c.ContentType() == "application/x-protobuf" {
err = c.Copy().ShouldBindWith(r, binding.ProtoBuf)
if err != nil {
return nil, err
}
} else {
err = c.Copy().ShouldBindJSON(r)
if err != nil {
return nil, err
}
}
return r, nil
}