add api route, but not use

This commit is contained in:
Jay
2019-02-25 23:16:16 +08:00
parent 0dc1db02b0
commit 21987754f1
6 changed files with 127 additions and 14 deletions
+7 -4
View File
@@ -1,7 +1,9 @@
package context
import (
"fmt"
"net/http"
"reflect"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
@@ -32,6 +34,7 @@ func parseResponse(body interface{}) interface{} {
"message": body,
}
case map[string]interface{}:
return body
case map[string]string:
return body
default:
@@ -39,7 +42,6 @@ func parseResponse(body interface{}) interface{} {
"message": "empty",
}
}
return nil
}
// BindData client body data
@@ -50,9 +52,10 @@ func (p *Context) BindData(i interface{}) error {
// Success -
func (p *Context) Success(res ...interface{}) {
fmt.Println("get type ", reflect.TypeOf(res[0]))
var resBody interface{}
if len(res) > 0 {
resBody = parseResponse(res)
resBody = parseResponse(res[0])
} else {
resBody = parseResponse("success")
}
@@ -63,7 +66,7 @@ func (p *Context) Success(res ...interface{}) {
func (p *Context) ClientError(res ...interface{}) {
var resBody interface{}
if len(res) > 0 {
resBody = parseResponse(res)
resBody = parseResponse(res[0])
} else {
resBody = parseResponse("bad request")
}
@@ -74,7 +77,7 @@ func (p *Context) ClientError(res ...interface{}) {
func (p *Context) ServerError(res ...interface{}) {
var resBody interface{}
if len(res) > 0 {
resBody = parseResponse(res)
resBody = parseResponse(res[0])
} else {
resBody = parseResponse("internal error")
}