-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
50 lines (39 loc) · 977 Bytes
/
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
package main
import (
"fmt"
_ "go-crud-beego-api/models"
_ "go-crud-beego-api/routers"
"os"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"
)
func main() {
// if in develop mode
if beego.BConfig.RunMode == "dev" {
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
}
// get database configuration from environment variables
dbUser := os.Getenv("db_user")
dbPwd := os.Getenv("db_pwd")
dbName := "go_user_mgmt"
dbString := dbUser + ":" + dbPwd + "@/" + dbName + "?charset=utf8"
// Register Driver
orm.RegisterDriver("mysql", orm.DRMySQL)
// Register default database
orm.RegisterDataBase("default", "mysql", dbString)
// autosync
// db alias
name := "default"
// drop table and re-create
force := false
// print log
verbose := true
// error
err := orm.RunSyncdb(name, force, verbose)
if err != nil {
fmt.Println(err)
}
beego.Run()
}