18 changed files with 187 additions and 50 deletions
@ -0,0 +1,16 @@
|
||||
package consts |
||||
|
||||
type JsonResultCode int |
||||
|
||||
const ( |
||||
JRCodeSucc JsonResultCode = iota |
||||
JRCodeFailed |
||||
JRCode302 = 302 //跳转至地址
|
||||
JRCode401 = 401 //未授权访问
|
||||
) |
||||
|
||||
const ( |
||||
Deleted = iota - 1 |
||||
Disabled |
||||
Enabled |
||||
) |
@ -0,0 +1,27 @@
|
||||
package controllers |
||||
|
||||
import ( |
||||
"github.com/ziyoubiancheng/xcms/consts" |
||||
"github.com/ziyoubiancheng/xcms/models" |
||||
) |
||||
|
||||
type MenuController struct { |
||||
BaseController |
||||
} |
||||
|
||||
func (c *MenuController) Index() { |
||||
models.MenuModel.List() |
||||
c.jsonResult(consts.JRCodeSucc, "1", "b") |
||||
} |
||||
|
||||
func (c *MenuController) Add() { |
||||
c.jsonResult(consts.JRCodeSucc, "1", "b") |
||||
} |
||||
|
||||
func (c *MenuController) Delete() { |
||||
c.jsonResult(consts.JRCodeSucc, "1", "b") |
||||
} |
||||
|
||||
func (c *MenuController) Edit() { |
||||
c.jsonResult(consts.JRCodeSucc, "1", "b") |
||||
} |
Binary file not shown.
@ -0,0 +1,21 @@
|
||||
package models |
||||
|
||||
import ( |
||||
"database/sql" |
||||
"fmt" |
||||
|
||||
_ "github.com/go-sql-driver/mysql" |
||||
) |
||||
|
||||
type BaseModel struct { |
||||
} |
||||
|
||||
func (m *BaseModel) exec(query string, args ...interface{}) (*sql.Rows, error) { |
||||
db, err := sql.Open("mysql", "root:135246@tcp(127.0.0.1:3307)/xcms?charset=utf8") //TODO
|
||||
if err != nil { |
||||
fmt.Println(err) |
||||
} |
||||
defer db.Close() |
||||
|
||||
return db.Query(query, args...) |
||||
} |
@ -0,0 +1,12 @@
|
||||
package models |
||||
|
||||
import ( |
||||
"github.com/ziyoubiancheng/xcms/consts" |
||||
) |
||||
|
||||
// JsonResult 用于返回ajax请求的基类
|
||||
type JsonResult struct { |
||||
Code consts.JsonResultCode `json:"code"` |
||||
Msg string `json:"msg"` |
||||
Obj interface{} `json:"obj"` |
||||
} |
@ -0,0 +1,24 @@
|
||||
package models |
||||
|
||||
import ( |
||||
"fmt" |
||||
) |
||||
|
||||
type MenuModel struct { |
||||
BaseModel |
||||
} |
||||
|
||||
func (m *MenuModel) TableName() string { |
||||
return "xcms_menu" |
||||
} |
||||
|
||||
func (m *MenuModel) List() { |
||||
rows, err := m.BaseModel.exec("select mid,name from xcms_menu limit 10") |
||||
mid := 0 |
||||
name := " " |
||||
for rows.Next() { |
||||
rows.Scan(&mid, &name) |
||||
fmt.Println(mid, name) |
||||
} |
||||
fmt.Println(err) |
||||
} |
@ -1,8 +0,0 @@
|
||||
package models |
||||
|
||||
// "github.com/astaxie/beego"
|
||||
// "github.com/astaxie/beego/orm"
|
||||
|
||||
func init() { |
||||
// orm.RegisterModel(new(Test))
|
||||
} |
@ -1,31 +0,0 @@
|
||||
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 |
||||
} |
||||
} |
Binary file not shown.
Loading…
Reference in new issue