forked from yeyulmq/7yue_api_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (46 loc) · 1.13 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
package main
import (
"github.com/gin-gonic/gin"
"7yue_api_server/router"
"log"
"net/http"
"7yue_api_server/model"
"github.com/spf13/viper"
"7yue_api_server/mock"
"7yue_api_server/config"
)
func main() {
config.InitConfig()
gin.SetMode(viper.GetString("runmode"))
g := gin.New()
g.Static("/static", "static")
g.LoadHTMLGlob("templates/*")
g.StaticFile("/favicon.ico", "static/favicon.ico")
db := model.InitDB()
db.AutoMigrate(
&model.Classic{},
&model.Book{},
&model.BookComment{},
&model.Favor{},
&model.User{},
&model.HotKeyword{})
defer db.Close()
// 首次运行时可通过该方法添加一些 mock 数据
// mockInit()
router.Register(g)
log.Printf("Start to listening the incoming requests on http address: %s", viper.GetString("port"))
log.Fatal(http.ListenAndServe(viper.GetString("port"), g).Error())
}
// mock 数据
func mockInit() {
// mock user
mock.PushDataIntoUserTable()
// mock classic
mock.PushDataIntoClassicTable()
// mock book
mock.PushDataIntoBookTable()
// mock book short comment
mock.PushDataIntoBookCommentTable()
// mock hot keyword
mock.PushDataIntoHotKeyWordTable()
}