Commit 4eacf0ee authored by duanjinfei's avatar duanjinfei

update resp data

parent f8d7992e
......@@ -13,10 +13,10 @@ func (d *BaseController) ResponseInfo(code int, msg interface{}, result interfac
switch code {
case 500:
logs.Error(msg, result)
d.Data["json"] = map[string]interface{}{"code": "500", "msg": msg, "content": result}
d.Data["json"] = map[string]interface{}{"code": "500", "msg": msg, "data": result}
case 200:
logs.Info(msg, result)
d.Data["json"] = map[string]interface{}{"code": "200", "msg": msg, "content": result}
d.Data["json"] = map[string]interface{}{"code": "200", "msg": msg, "data": result}
}
d.ServeJSON()
}
package test
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"runtime"
"path/filepath"
"runtime"
"sync"
"testing"
"time"
_ "token-uri/routers"
"github.com/astaxie/beego"
......@@ -14,11 +17,10 @@ import (
func init() {
_, file, _, _ := runtime.Caller(0)
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator))))
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
beego.TestBeegoInit(apppath)
}
// TestBeego is a sample to run an endpoint test
func TestBeego(t *testing.T) {
r, _ := http.NewRequest("GET", "/", nil)
......@@ -37,3 +39,53 @@ func TestBeego(t *testing.T) {
})
}
func TestGoRoutine(t *testing.T) {
handlerIns := &handler{
wg: &sync.WaitGroup{},
}
msg := make(chan int, 0)
for i := 0; i < 2; i++ {
go handlerMsg(handlerIns, msg, i)
}
for {
i := 10
if i%10 == 0 {
time.Sleep(time.Second * 2)
msg <- 1
}
i++
}
}
type handler struct {
wg *sync.WaitGroup
}
func handlerMsg(h *handler, msg chan int, count int) {
for {
fmt.Println("xxxx:", count)
select {
case rev := <-msg:
{
if rev == 1 {
fmt.Println("exec xxxx:", count)
go func(h *handler) {
h.wg.Add(1)
h.handlerXXX()
h.wg.Wait()
fmt.Println("exec task")
}(h)
continue
}
}
}
}
}
func (h *handler) handlerXXX() {
defer h.wg.Done()
time.Sleep(time.Second * 2)
fmt.Println("wg done")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment