zjxpcyc 6 years ago
parent
commit
a26d0890bb
5 changed files with 15 additions and 5 deletions
  1. 4
    0
      bootstrap/bootstrap.go
  2. 0
    1
      main.go
  3. 1
    1
      routers/router.go
  4. 8
    0
      tests/utils.go
  5. 2
    3
      utils/utils.go

+ 4
- 0
bootstrap/bootstrap.go View File

@@ -2,6 +2,7 @@ package bootstrap
2 2
 
3 3
 import (
4 4
 	"spaceofcheng/services/models"
5
+	"spaceofcheng/services/routers"
5 6
 	"spaceofcheng/services/service/events"
6 7
 	"spaceofcheng/services/utils"
7 8
 )
@@ -22,4 +23,7 @@ func SystemInit() {
22 23
 
23 24
 	// 事件系统
24 25
 	events.EventInit()
26
+
27
+	// 路由系统
28
+	routers.RouteInit()
25 29
 }

+ 0
- 1
main.go View File

@@ -2,7 +2,6 @@ package main
2 2
 
3 3
 import (
4 4
 	"spaceofcheng/services/bootstrap"
5
-	_ "spaceofcheng/services/routers"
6 5
 
7 6
 	"github.com/astaxie/beego"
8 7
 )

+ 1
- 1
routers/router.go View File

@@ -14,7 +14,7 @@ import (
14 14
 	"github.com/astaxie/beego"
15 15
 )
16 16
 
17
-func init() {
17
+func RouteInit() {
18 18
 	appRoot := utils.GetAppRoot()
19 19
 
20 20
 	appConf, _ := utils.GetConfiger(appRoot + "/conf/app.conf")

+ 8
- 0
tests/utils.go View File

@@ -12,6 +12,7 @@ import (
12 12
 	"net/http/httptest"
13 13
 	"net/url"
14 14
 	"os"
15
+	"spaceofcheng/services/utils"
15 16
 	"strconv"
16 17
 	"strings"
17 18
 	"time"
@@ -49,6 +50,13 @@ func (t *RequestMock) AddWechatUA() *RequestMock {
49 50
 	return t
50 51
 }
51 52
 
53
+// AddToken 添加Token
54
+func (t *RequestMock) AddToken(dt map[string]interface{}) *RequestMock {
55
+	token, _ := utils.CreateToken(dt)
56
+	t.Headers[utils.TokenHeader] = utils.TokenSchema + " " + token
57
+	return t
58
+}
59
+
52 60
 // SetHost 设置 host 包含 port
53 61
 func (t *RequestMock) SetHost(host string) *RequestMock {
54 62
 	t.Host = host

+ 2
- 3
utils/utils.go View File

@@ -4,8 +4,8 @@ import (
4 4
 	"encoding/base64"
5 5
 	"math/rand"
6 6
 	"net/http"
7
+	"os"
7 8
 	"path/filepath"
8
-	"runtime"
9 9
 	"strconv"
10 10
 	"strings"
11 11
 	"time"
@@ -161,7 +161,6 @@ func GetFiveSeconds(t time.Time) string {
161 161
 
162 162
 // GetAppRoot 获取系统根目录
163 163
 func GetAppRoot() string {
164
-	_, file, _, _ := runtime.Caller(1)
165
-	appRoot, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
164
+	appRoot, _ := filepath.Abs(filepath.Dir(os.Args[0]))
166 165
 	return appRoot
167 166
 }