-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (60 loc) · 1.73 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
package main
import (
c "baseadmin/controller"
dbhelper "baseadmin/db"
h "baseadmin/helper"
m "baseadmin/model"
"fmt"
"github.com/go-gorp/gorp"
_ "github.com/go-sql-driver/mysql"
"github.com/valyala/fasthttp"
"time"
)
func init() {
var Conf h.Conf = h.GetConfig()
h.PrintlnIf(fmt.Sprintf("Config values are the following: %+v", Conf), Conf.Mode.Debug)
var tableModels = []m.DbInterface{
m.Status{},
m.Config{},
m.UserRole{},
m.UserGroup{},
m.User{},
m.Ban{},
m.Block{},
m.Request{},
m.Upgrade{},
m.EntityType{},
m.Entity{},
m.Attribute{},
m.AttributeOption{},
m.EntityAttributeValue{},
}
_, err := dbhelper.DbMap.Exec("SET GLOBAL FOREIGN_KEY_CHECKS=0;")
h.Error(err, "", h.ErrorLvlError)
h.PrintlnIf("Rebuild table structure because config rebuild flag is true", h.GetConfig().Mode.RebuildStructure)
var tablemap *gorp.TableMap
for _, cm := range tableModels {
tablemap = dbhelper.DbMap.AddTableWithName(cm, cm.GetTable())
tablemap.SetKeys(cm.IsAutoIncrement(), cm.GetPrimaryKey()...)
if h.GetConfig().Mode.RebuildStructure {
cm.BuildStructure(dbhelper.DbMap)
}
}
dbhelper.DbMap.Exec("SET GLOBAL FOREIGN_KEY_CHECKS=1;")
defer func() {
h.PrintlnIf("STRUCTURE BUILDING DONE", h.GetConfig().Mode.Debug)
}()
}
func main() {
defer func() {
srv := &fasthttp.Server{
Name: h.GetConfig().Server.Name,
ReadTimeout: time.Duration(h.GetConfig().Server.ReadTimeoutSeconds) * time.Second,
WriteTimeout: time.Duration(h.GetConfig().Server.WriteTimeoutSeconds) * time.Second,
Handler: c.Route,
}
err := srv.ListenAndServe(fmt.Sprintf(":%s", h.GetConfig().ListenPort))
h.Error(err, "", h.ErrorLvlError)
h.PrintlnIf("The server is listening...", h.GetConfig().Mode.Debug)
}()
}