-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
73 lines (62 loc) · 1.45 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
66
67
68
69
70
71
72
73
package main
import (
"database/sql"
"github.com/Wuvist/decho/conf"
"github.com/Wuvist/decho/controller"
"github.com/Wuvist/decho/models"
"github.com/Wuvist/dechoconf"
_ "github.com/go-sql-driver/mysql"
"github.com/labstack/echo/v4"
"github.com/volatiletech/sqlboiler/boil"
"github.com/volatiletech/sqlboiler/queries/qm"
)
func main() {
webApp, err := getWebApp()
if err != nil {
panic(err)
}
webApp.Run()
}
// WebApp represent a web application
type WebApp struct {
*echo.Echo
config *conf.App
blog *controller.BlogController
cate *controller.CateController
home *controller.HomeController
static *controller.StaticController
}
// Run the web app
func (e *WebApp) Run() {
db, err := sql.Open("mysql", e.config.Mysql+"?parseTime=true")
if err != nil {
panic(err)
}
boil.SetDB(db)
e.Logger.Fatal(e.Start(e.config.Address))
}
func loadTomlConf() (*conf.App, error) {
var conf conf.App
if err := dechoconf.DecodeTomlFile("conf.toml", &conf); err != nil {
return nil, err
}
return &conf, nil
}
// db providers
func getBloggerDB() models.BloggerQuery {
return models.Bloggers
}
func getArticalDB() models.ArticlesQuery {
return models.Articles
}
func getCategoryDB() models.UserdefinecategoryQuery {
return models.Userdefinecategories
}
func getLinkDB() models.LinkQuery {
return func(mods ...qm.QueryMod) models.LinkExecutor {
return models.Links(mods...)
}
}
func getCommentDB() models.CommentQuery {
return models.Comments
}