上传编解码优化
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) {
|
func (this *mapEncoder) EncodeToMapJson(ptr unsafe.Pointer) (ret map[string]string, err error) {
|
||||||
ret = make(map[string]string)
|
ret = make(map[string]string)
|
||||||
|
var (
|
||||||
|
k, v string
|
||||||
|
)
|
||||||
|
|
||||||
keystream := this.codec.BorrowStream()
|
keystream := this.codec.BorrowStream()
|
||||||
elemstream := this.codec.BorrowStream()
|
elemstream := this.codec.BorrowStream()
|
||||||
iter := this.mapType.UnsafeIterate(ptr)
|
iter := this.mapType.UnsafeIterate(ptr)
|
||||||
for i := 0; iter.HasNext(); i++ {
|
for i := 0; iter.HasNext(); i++ {
|
||||||
key, elem := iter.UnsafeNext()
|
key, elem := iter.UnsafeNext()
|
||||||
this.keyEncoder.Encode(key, keystream)
|
if this.keyEncoder.GetType() != reflect.String {
|
||||||
if keystream.Error() != nil && keystream.Error() != io.EOF {
|
this.keyEncoder.Encode(key, keystream)
|
||||||
err = keystream.Error()
|
if keystream.Error() != nil && keystream.Error() != io.EOF {
|
||||||
return
|
err = keystream.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
k = BytesToString(keystream.Buffer())
|
||||||
|
} else {
|
||||||
|
k = *((*string)(key))
|
||||||
}
|
}
|
||||||
this.elemEncoder.Encode(elem, elemstream)
|
if this.elemEncoder.GetType() != reflect.String {
|
||||||
if elemstream.Error() != nil && elemstream.Error() != io.EOF {
|
this.elemEncoder.Encode(elem, elemstream)
|
||||||
err = elemstream.Error()
|
if elemstream.Error() != nil && elemstream.Error() != io.EOF {
|
||||||
return
|
err = elemstream.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
v = BytesToString(elemstream.Buffer())
|
||||||
|
} else {
|
||||||
|
v = *((*string)(elem))
|
||||||
}
|
}
|
||||||
ret[BytesToString(keystream.Buffer())] = BytesToString(elemstream.Buffer())
|
ret[k] = v
|
||||||
keystream.Reset(512)
|
keystream.Reset(512)
|
||||||
elemstream.Reset(512)
|
elemstream.Reset(512)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
func newOptions(config map[string]interface{}, opts ...core.Option) core.Options {
|
func newOptions(config map[string]interface{}, opts ...core.Option) core.Options {
|
||||||
options := core.Options{
|
options := core.Options{
|
||||||
IndentionStep: 2,
|
IndentionStep: 2,
|
||||||
|
TagKey: "json",
|
||||||
}
|
}
|
||||||
if config != nil {
|
if config != nil {
|
||||||
mapstructure.Decode(config, &options)
|
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 {
|
func newOptionsByOption(opts ...core.Option) core.Options {
|
||||||
options := core.Options{
|
options := core.Options{
|
||||||
IndentionStep: 2,
|
IndentionStep: 2,
|
||||||
|
TagKey: "json",
|
||||||
}
|
}
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
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, err = gin.NewSys(gin.SetListenPort(this.options.Port))
|
||||||
this.gin.POST("/register", this.Register)
|
this.gin.POST("/register", this.Register)
|
||||||
this.gin.GET("/serverlist", this.ServerList)
|
this.gin.GET("/serverlist", this.ServerList)
|
||||||
|
this.gin.GET("/createnotify", this.CreateNotify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"go_dreamfactory/lego/sys/gin/engine"
|
"go_dreamfactory/lego/sys/gin/engine"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateNotifyReq struct {
|
type CreateNotifyReq struct {
|
||||||
@ -16,31 +15,31 @@ type CreateNotifyReq struct {
|
|||||||
//服务列表
|
//服务列表
|
||||||
func (this *Api_Comp) CreateNotify(c *engine.Context) {
|
func (this *Api_Comp) CreateNotify(c *engine.Context) {
|
||||||
req := &CreateNotifyReq{}
|
req := &CreateNotifyReq{}
|
||||||
c.BindJSON(&req)
|
err := c.BindJSON(&req)
|
||||||
defer log.Debugf("CreateNotify:%+v", req)
|
log.Debugf("CreateNotify:%+v err:%v", req, err)
|
||||||
var (
|
var (
|
||||||
code pb.ErrorCode
|
// code pb.ErrorCode
|
||||||
msg string
|
// msg string
|
||||||
data interface{}
|
// data interface{}
|
||||||
err error
|
// 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 {
|
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)
|
log.Errorf("LoginByCaptchaReq SignError sgin:%s", sign)
|
||||||
code = pb.ErrorCode_SignError
|
// code = pb.ErrorCode_SignError
|
||||||
msg = pb.GetErrorCodeMsg(code)
|
// msg = pb.GetErrorCodeMsg(code)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(req.Title) == 0 {
|
if len(req.Title) == 0 {
|
||||||
code = pb.ErrorCode_ReqParameterError
|
// code = pb.ErrorCode_ReqParameterError
|
||||||
msg = pb.GetErrorCodeMsg(code)
|
// msg = pb.GetErrorCodeMsg(code)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = this.module.modelNotify.CreateSystemNotify(&req.DBSystemNotify); err != nil {
|
if err = this.module.modelNotify.CreateSystemNotify(&req.DBSystemNotify); err != nil {
|
||||||
log.Errorf("LoginByCaptchaReq CreateSystemNotify err:%v", err)
|
log.Errorf("LoginByCaptchaReq CreateSystemNotify err:%v", err)
|
||||||
code = pb.ErrorCode_DBError
|
// code = pb.ErrorCode_DBError
|
||||||
msg = pb.GetErrorCodeMsg(code)
|
// msg = pb.GetErrorCodeMsg(code)
|
||||||
return
|
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