1 Star 2 Fork 3

kristas/booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
value_builder.go 2.84 KB
一键复制 编辑 原始数据 按行查看 历史
kristas 提交于 2021-04-02 18:30 . feat: add filter function
package iris_restful_plugin
//
//import (
// "encoding/json"
// "gitee.com/kristas/booting-go/framework/common/util/lang"
// "github.com/kataras/iris/v12/context"
// "reflect"
//)
//
//type ValueBuilder interface {
//
//}
//
//type ValueBuilderProcessor struct {
//
//}
//
//var valueMap = map[reflect.Kind]func(c context.Context, param Param) interface{}{
// reflect.Bool: buildBool,
// reflect.Int: buildInt,
// reflect.Float64: buildFloat64,
// reflect.Map: buildMap,
// reflect.Slice: buildSlice,
// reflect.Struct: buildStruct,
// reflect.String: buildString,
//}
//
//func readBody(c context.Context, in reflect.Type) interface{} {
// v := reflect.New(in).Interface()
// c.ReadJSON(v)
// return reflect.ValueOf(v).Elem().Interface()
//}
//
//func buildInt(c context.Context, param Param) interface{} {
// switch param.source {
// case "path":
// return c.Params().GetIntDefault(param.name, 0)
// case "query":
// return c.URLParamIntDefault(param.name, 0)
// case "body":
// return readBody(c, param.typ)
// default:
// return nil
// }
//}
//
//func buildBool(c context.Context, param Param) interface{} {
// switch param.source {
// case "path":
// return c.Params().GetBoolDefault(param.name, false)
// case "query":
// paramBool, _ := c.URLParamBool(param.name)
// return paramBool
// case "body":
// return readBody(c, param.typ)
// default:
// return nil
// }
//}
//
//func buildFloat64(c context.Context, param Param) interface{} {
// switch param.source {
// case "path":
// return c.Params().GetFloat64Default(param.name, 0.00)
// case "query":
// return c.URLParamFloat64Default(param.name, 0.00)
// case "body":
// return readBody(c, param.typ)
// default:
// return nil
// }
//}
//
//func buildMap(c context.Context, param Param) interface{} {
// switch param.source {
// case "query":
// return c.URLParams()
// case "body":
// return readBody(c, param.typ)
// default:
// return nil
// }
//}
//
//func buildSlice(c context.Context, param Param) interface{} {
// switch param.source {
// case "query":
// split := lang.NewString(c.URLParam(param.name)).Split(",")
// return lang.TransferSliceToSimple(split)
// case "body":
// return readBody(c, param.typ)
// default:
// return nil
// }
//}
//
//func buildStruct(c context.Context, param Param) interface{} {
// switch param.source {
// case "path":
// str := c.Params().GetString(param.name)
// var v interface{}
// json.Unmarshal([]byte(str), &v)
// return v
// case "query":
// return c.URLParam(param.name)
// case "body":
// return readBody(c, param.typ)
// default:
// return nil
// }
//}
//
//func buildString(c context.Context, param Param) interface{} {
// switch param.source {
// case "path":
// return c.Params().GetString(param.name)
// case "query":
// return c.URLParam(param.name)
// case "body":
// return readBody(c, param.typ)
// default:
// return nil
// }
//}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.1.5

搜索帮助