add api route, but not use
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user