Mac 3 years ago
parent
commit
ea01450d26
  1. 10
      conf/app.conf
  2. 13
      controllers/BaseController.go
  3. 13
      controllers/default.go
  4. 5
      main.go
  5. 1
      models/Test.go
  6. 6
      models/UserModel.go
  7. 8
      models/init.go
  8. 4
      routers/router.go
  9. 31
      sysinit/initDB.go
  10. 5
      sysinit/sysinit.go
  11. BIN
      xcms

10
conf/app.conf

@ -1,3 +1,13 @@
appname = xcms
httpport = 8080
runmode = dev
#mysql
db_alias = "default"
db_name = "xcms"
db_user = "root"
db_pwd = "135246"
db_host = "localhost"
db_port = 3307
db_charset = "utf8"

13
controllers/BaseController.go

@ -0,0 +1,13 @@
package controllers
import (
"github.com/astaxie/beego"
"github.com/ziyoubiancheng/xcms/models"
)
type BaseController struct {
beego.Controller
controllerName string
actionName string
curUser models.UserModel
}

13
controllers/default.go

@ -1,7 +1,12 @@
package controllers
import (
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql" // import your used driver
)
type MainController struct {
@ -9,6 +14,14 @@ type MainController struct {
}
func (c *MainController) Get() {
orm.RegisterDataBase("default", "mysql", "root:135246@tcp(127.0.0.1:3307)/xcms?charset=utf8", 30)
// o := orm.NewOrm()
// var r RawSeter
//r := o.Raw("INSERT INTO xcms_formats (name) VALUES ('?');", "test2").Exec()
fmt.Println("hello")
c.Data["Website"] = "beego.me"
c.Data["Email"] = "astaxie@gmail.com"
c.TplName = "index.tpl"

5
main.go

@ -1,11 +1,12 @@
package main
import (
_ "xcms/routers"
_ "github.com/ziyoubiancheng/xcms/routers"
_ "github.com/ziyoubiancheng/xcms/sysinit"
"github.com/astaxie/beego"
)
func main() {
beego.Run()
}

1
models/Test.go

@ -0,0 +1 @@
package models

6
models/UserModel.go

@ -0,0 +1,6 @@
package models
type UserModel struct {
userId string
role int8
}

8
models/init.go

@ -0,0 +1,8 @@
package models
// "github.com/astaxie/beego"
// "github.com/astaxie/beego/orm"
func init() {
// orm.RegisterModel(new(Test))
}

4
routers/router.go

@ -1,10 +1,10 @@
package routers
import (
"xcms/controllers"
"github.com/astaxie/beego"
"github.com/ziyoubiancheng/xcms/controllers"
)
func init() {
beego.Router("/", &controllers.MainController{})
beego.Router("/", &controllers.MainController{})
}

31
sysinit/initDB.go

@ -0,0 +1,31 @@
package sysinit
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
_ "github.com/ziyoubiancheng/xcms/models"
)
func initDB() {
//连接名称
dbAlias := beego.AppConfig.String("db_alias")
//数据库名称
dbName := beego.AppConfig.String("db_name")
//数据库连接用户名
dbUser := beego.AppConfig.String("db_user")
//数据库连接用户名
dbPwd := beego.AppConfig.String("db_pwd")
//数据库IP(域名)
dbHost := beego.AppConfig.String("db_host")
//数据库端口
dbPort := beego.AppConfig.String("db_port")
//数据库编码
dbCharset := beego.AppConfig.String("db_charset")
orm.RegisterDataBase(dbAlias, "mysql", dbUser+":"+dbPwd+"@tcp("+dbHost+":"+dbPort+")/"+dbName+"?charset="+dbCharset, 30)
isDev := (beego.AppConfig.String("runmode") == "dev")
if isDev {
orm.Debug = isDev
}
}

5
sysinit/sysinit.go

@ -0,0 +1,5 @@
package sysinit
func init() {
initDB()
}

BIN
xcms

Binary file not shown.
Loading…
Cancel
Save