-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
65 lines (55 loc) · 1.53 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"QuickMock/config"
"QuickMock/controllers"
"QuickMock/tools"
"fmt"
"net/http"
"os"
)
func startApiServer() {
apiMux := http.NewServeMux()
apiMux.HandleFunc("/", controllers.AllPathHandler)
apiServer := &http.Server{
Addr: fmt.Sprintf(":%d", config.RunConfig.ApiServerPort),
Handler: apiMux,
}
go func() {
err := apiServer.ListenAndServe()
if err != nil {
fmt.Println(err)
os.Exit(2)
}
}()
}
func startAdminServer() {
adminMux := http.NewServeMux()
adminMux.HandleFunc("/", controllers.Home)
adminMux.HandleFunc("/apiList", controllers.GetApiList)
adminMux.HandleFunc("/apiDetail", controllers.GetApiDetail)
adminMux.HandleFunc("/upsert", controllers.UpsertApi)
adminMux.HandleFunc("/delete", controllers.DelApi)
adminMux.HandleFunc("/edit.html", controllers.Edit)
adminMux.HandleFunc("/jquery3.js", controllers.Jquery)
adminMux.HandleFunc("/vue2.js", controllers.Vue)
adminServer := &http.Server{
Addr: fmt.Sprintf(":%d", config.RunConfig.AdminServerPort),
Handler: adminMux,
}
go func() {
err := adminServer.ListenAndServe()
if err != nil {
fmt.Println(err)
os.Exit(2)
}
}()
}
func main() {
startApiServer()
startAdminServer()
fmt.Printf("启动成功!api接口运行端口%d\r\n"+
"admin后台运行端口%d\r\n"+
"你可以通过http://127.0.0.1:%d 或者 http://%s:%d 进行接口管理",
config.RunConfig.ApiServerPort, config.RunConfig.AdminServerPort, config.RunConfig.AdminServerPort, tools.GetLocalIp(), config.RunConfig.AdminServerPort)
select {}
}