zjxpcyc 6 年前
父节点
当前提交
a26d0890bb
共有 5 个文件被更改,包括 15 次插入5 次删除
  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 查看文件

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

+ 0
- 1
main.go 查看文件

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

+ 1
- 1
routers/router.go 查看文件

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

+ 8
- 0
tests/utils.go 查看文件

12
 	"net/http/httptest"
12
 	"net/http/httptest"
13
 	"net/url"
13
 	"net/url"
14
 	"os"
14
 	"os"
15
+	"spaceofcheng/services/utils"
15
 	"strconv"
16
 	"strconv"
16
 	"strings"
17
 	"strings"
17
 	"time"
18
 	"time"
49
 	return t
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
 // SetHost 设置 host 包含 port
60
 // SetHost 设置 host 包含 port
53
 func (t *RequestMock) SetHost(host string) *RequestMock {
61
 func (t *RequestMock) SetHost(host string) *RequestMock {
54
 	t.Host = host
62
 	t.Host = host

+ 2
- 3
utils/utils.go 查看文件

4
 	"encoding/base64"
4
 	"encoding/base64"
5
 	"math/rand"
5
 	"math/rand"
6
 	"net/http"
6
 	"net/http"
7
+	"os"
7
 	"path/filepath"
8
 	"path/filepath"
8
-	"runtime"
9
 	"strconv"
9
 	"strconv"
10
 	"strings"
10
 	"strings"
11
 	"time"
11
 	"time"
161
 
161
 
162
 // GetAppRoot 获取系统根目录
162
 // GetAppRoot 获取系统根目录
163
 func GetAppRoot() string {
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
 	return appRoot
165
 	return appRoot
167
 }
166
 }