-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (48 loc) · 1.22 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
package main
import (
_ "dough_go/routers"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql" // import your used driver
)
type User struct {
Id int
Name string `orm:"size(100)"`
}
func init() {
// set default database
_ = orm.RegisterDataBase("default", "mysql", "root:Budengyu1.@tcp(localhost:3306)/dough_app?charset=utf8mb4&parseTime=True", 30)
// register model
orm.RegisterModel(new(User))
// create table
_ = orm.RunSyncdb("default", false, true)
}
func main() {
//o := orm.NewOrm()
//
//user := User{Name: "slene", Id: 1}
//
//// insert
//id, err := o.Insert(&user)
//fmt.Printf("ID: %d, ERR: %v\n", id, err)
//
//// update
//user.Name = "astaxie"
//num, err := o.Update(&user)
//fmt.Printf("update::NUM: %d, ERR: %v\n", num, err)
// read one
//u := User{Id: user.Id}
//err := o.Read(&u)
//fmt.Printf("Read::ERR: %v\n", err)
// delete
//num, err = o.Delete(&u)
//fmt.Printf("Delete::NUM: %d, ERR: %v\n", num, err)
str := beego.AppConfig.String("mysqluser")
fmt.Printf("MyConfig::%v\n", str)
if beego.BConfig.RunMode == "dev" {
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
}
beego.Run()
}