4 Star 12 Fork 3

yasenagat / gokit-inaction

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
transport.go 665 Bytes
一键复制 编辑 原始数据 按行查看 历史
yasenagat 提交于 2020-04-09 10:31 . U-更新readme
package api
import (
"encoding/json"
"golang.org/x/net/context"
"io/ioutil"
"log"
"net/http"
)
func DecodeLoginReq(ctx context.Context, r *http.Request) (request interface{}, err error) {
req := ReqLogin{}
bytes, e := ioutil.ReadAll(r.Body)
defer func() {
r.Body.Close()
}()
if e != nil {
return nil, e
}
if e := json.Unmarshal(bytes, &req); e != nil {
log.Println("DecodeLoginReq", e)
return nil, e
}
return req, nil
}
func EncodeRes(ctx context.Context, writer http.ResponseWriter, i interface{}) error {
bytes, e := json.Marshal(i)
if e != nil {
log.Println("EncodeRes", e)
return e
}
_, e = writer.Write(bytes)
return e
}
Go
1
https://gitee.com/godY/gokit-inaction.git
git@gitee.com:godY/gokit-inaction.git
godY
gokit-inaction
gokit-inaction
201036b8f164

搜索帮助