上传编解码优化
This commit is contained in:
parent
9a4388e94d
commit
f47005cc18
@ -108,22 +108,36 @@ func (this *mapEncoder) Encode(ptr unsafe.Pointer, stream core.IStream) {
|
||||
|
||||
func (this *mapEncoder) EncodeToMapJson(ptr unsafe.Pointer) (ret map[string]string, err error) {
|
||||
ret = make(map[string]string)
|
||||
var (
|
||||
k, v string
|
||||
)
|
||||
|
||||
keystream := this.codec.BorrowStream()
|
||||
elemstream := this.codec.BorrowStream()
|
||||
iter := this.mapType.UnsafeIterate(ptr)
|
||||
for i := 0; iter.HasNext(); i++ {
|
||||
key, elem := iter.UnsafeNext()
|
||||
if this.keyEncoder.GetType() != reflect.String {
|
||||
this.keyEncoder.Encode(key, keystream)
|
||||
if keystream.Error() != nil && keystream.Error() != io.EOF {
|
||||
err = keystream.Error()
|
||||
return
|
||||
}
|
||||
k = BytesToString(keystream.Buffer())
|
||||
} else {
|
||||
k = *((*string)(key))
|
||||
}
|
||||
if this.elemEncoder.GetType() != reflect.String {
|
||||
this.elemEncoder.Encode(elem, elemstream)
|
||||
if elemstream.Error() != nil && elemstream.Error() != io.EOF {
|
||||
err = elemstream.Error()
|
||||
return
|
||||
}
|
||||
ret[BytesToString(keystream.Buffer())] = BytesToString(elemstream.Buffer())
|
||||
v = BytesToString(elemstream.Buffer())
|
||||
} else {
|
||||
v = *((*string)(elem))
|
||||
}
|
||||
ret[k] = v
|
||||
keystream.Reset(512)
|
||||
elemstream.Reset(512)
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
func newOptions(config map[string]interface{}, opts ...core.Option) core.Options {
|
||||
options := core.Options{
|
||||
IndentionStep: 2,
|
||||
TagKey: "json",
|
||||
}
|
||||
if config != nil {
|
||||
mapstructure.Decode(config, &options)
|
||||
@ -25,6 +26,7 @@ func newOptions(config map[string]interface{}, opts ...core.Option) core.Options
|
||||
func newOptionsByOption(opts ...core.Option) core.Options {
|
||||
options := core.Options{
|
||||
IndentionStep: 2,
|
||||
TagKey: "json",
|
||||
}
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
|
@ -24,5 +24,6 @@ func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core
|
||||
this.gin, err = gin.NewSys(gin.SetListenPort(this.options.Port))
|
||||
this.gin.POST("/register", this.Register)
|
||||
this.gin.GET("/serverlist", this.ServerList)
|
||||
this.gin.GET("/createnotify", this.CreateNotify)
|
||||
return
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"go_dreamfactory/lego/sys/gin/engine"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type CreateNotifyReq struct {
|
||||
@ -16,31 +15,31 @@ type CreateNotifyReq struct {
|
||||
//服务列表
|
||||
func (this *Api_Comp) CreateNotify(c *engine.Context) {
|
||||
req := &CreateNotifyReq{}
|
||||
c.BindJSON(&req)
|
||||
defer log.Debugf("CreateNotify:%+v", req)
|
||||
err := c.BindJSON(&req)
|
||||
log.Debugf("CreateNotify:%+v err:%v", req, err)
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
msg string
|
||||
data interface{}
|
||||
err error
|
||||
// code pb.ErrorCode
|
||||
// msg string
|
||||
// data interface{}
|
||||
// err error
|
||||
)
|
||||
c.JSON(http.StatusOK, &Respond{Code: code, Message: msg, Data: data})
|
||||
// defer c.JSON(http.StatusOK, &Respond{Code: code, Message: msg, Data: data})
|
||||
if sign := gin.ParamSign(this.options.Key, map[string]interface{}{"Title": req.Title, "Ctime": req.Ctime, "Rtime": req.Rtime}); sign != req.Sign {
|
||||
log.Errorf("LoginByCaptchaReq SignError sgin:%s", sign)
|
||||
code = pb.ErrorCode_SignError
|
||||
msg = pb.GetErrorCodeMsg(code)
|
||||
// code = pb.ErrorCode_SignError
|
||||
// msg = pb.GetErrorCodeMsg(code)
|
||||
return
|
||||
}
|
||||
if len(req.Title) == 0 {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
msg = pb.GetErrorCodeMsg(code)
|
||||
// code = pb.ErrorCode_ReqParameterError
|
||||
// msg = pb.GetErrorCodeMsg(code)
|
||||
return
|
||||
}
|
||||
if err = this.module.modelNotify.CreateSystemNotify(&req.DBSystemNotify); err != nil {
|
||||
log.Errorf("LoginByCaptchaReq CreateSystemNotify err:%v", err)
|
||||
code = pb.ErrorCode_DBError
|
||||
msg = pb.GetErrorCodeMsg(code)
|
||||
// code = pb.ErrorCode_DBError
|
||||
// msg = pb.GetErrorCodeMsg(code)
|
||||
return
|
||||
}
|
||||
msg = pb.GetErrorCodeMsg(code)
|
||||
// msg = pb.GetErrorCodeMsg(code)
|
||||
}
|
||||
|
21
modules/gm/gm_test.http
Normal file
21
modules/gm/gm_test.http
Normal file
@ -0,0 +1,21 @@
|
||||
package gm_test
|
||||
|
||||
###
|
||||
GET http://127.0.0.1:8000/createnotify HTTP/2.0
|
||||
Content-Type:application/json
|
||||
|
||||
{
|
||||
"title": "游戏公告",
|
||||
"content":"hello",
|
||||
"sign": "f5c3fddfe9002563082f61838154c890",
|
||||
}
|
||||
|
||||
### 注册账号测试
|
||||
POST http://127.0.0.1:8000/register HTTP/1.1
|
||||
Content-Type:application/json
|
||||
|
||||
{
|
||||
"register": "liwei2",
|
||||
"content":0,
|
||||
"sign": "f5c3fddfe9002563082f61838154c890",
|
||||
}
|
Loading…
Reference in New Issue
Block a user