已经接入配置文件,开始准备生成代码
This commit is contained in:
parent
99933e02f4
commit
fe085ce889
@ -2,6 +2,7 @@ package hotime
|
||||
|
||||
import (
|
||||
. "./cache"
|
||||
"./code"
|
||||
. "./common"
|
||||
. "./db"
|
||||
. "./log"
|
||||
@ -19,6 +20,7 @@ import (
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
*code.MakeCode
|
||||
MethodRouter
|
||||
Router
|
||||
ContextBase
|
||||
@ -307,10 +309,9 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
unescapeUrl = req.RequestURI
|
||||
}
|
||||
//访问实例
|
||||
context := Context{SessionIns: SessionIns{SessionId: sessionId,
|
||||
HoTimeCache: that.HoTimeCache,
|
||||
},
|
||||
Resp: w, Req: req, Application: that, RouterString: s, Config: that.Config, Db: &that.Db, HandlerStr: unescapeUrl}
|
||||
context := Context{SessionIns: SessionIns{SessionId: sessionId, HoTimeCache: that.HoTimeCache},
|
||||
Resp: w, Req: req, Application: that, RouterString: s, Config: that.Config, Db: &that.Db,
|
||||
HandlerStr: unescapeUrl}
|
||||
//header默认设置
|
||||
header := w.Header()
|
||||
header.Set("Content-Type", "text/html; charset=utf-8")
|
||||
@ -448,6 +449,15 @@ func Init(config string) Application {
|
||||
|
||||
SetDB(&appIns)
|
||||
appIns.SetCache()
|
||||
appIns.MakeCode = &code.MakeCode{}
|
||||
codeConfig := appIns.Config.GetMap("codeConfig")
|
||||
if codeConfig != nil {
|
||||
for k, _ := range codeConfig {
|
||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), appIns.Db)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return appIns
|
||||
}
|
||||
|
||||
|
23
code/config.go
Normal file
23
code/config.go
Normal file
@ -0,0 +1,23 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
. "../common"
|
||||
)
|
||||
|
||||
var Config = Map{
|
||||
"name": "HoTimeDashBoard",
|
||||
"ID": "2f92h3herh23rh2y8",
|
||||
"label": "HoTime管理平台",
|
||||
"menu": []Map{
|
||||
{"label": "平台首页", "name": "HelloWorld", "icon": "el-icon-s-home"},
|
||||
{"label": "测试表格", "table": "table", "icon": "el-icon-suitcase"},
|
||||
{"label": "系统管理", "name": "setting", "icon": "el-icon-setting",
|
||||
"menu": []Map{
|
||||
{"label": "用户管理", "table": "user"},
|
||||
{"label": "组织管理", "table": "organization"},
|
||||
{"label": "角色管理", "table": "role"},
|
||||
{"label": "系统设置", "table": "system", "default": "edit"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
@ -44,6 +44,8 @@ func (that *Context) Display(statu int, data interface{}) {
|
||||
temp["type"] = tpe
|
||||
temp["msg"] = data
|
||||
resp["result"] = temp
|
||||
//兼容android等需要json转对象的服务
|
||||
resp["error"] = temp
|
||||
} else {
|
||||
resp["result"] = data
|
||||
}
|
||||
|
@ -3,26 +3,58 @@ package admin
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var UserCtr = Ctr{
|
||||
"info": func(this *Context) {
|
||||
user := this.Db.Get(this.RouterString[1], "*", Map{"id": this.RouterString[2]})
|
||||
this.Display(0, user)
|
||||
"info": func(that *Context) {
|
||||
re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]})
|
||||
that.Display(0, re)
|
||||
},
|
||||
"add": func(this *Context) {
|
||||
"add": func(that *Context) {
|
||||
inData := that.MakeCode.Add(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
}
|
||||
re := that.Db.Insert(that.RouterString[1], inData)
|
||||
|
||||
},
|
||||
"update": func(this *Context) {
|
||||
if re == 0 {
|
||||
that.Display(4, "无法插入对应数据")
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
"remove": func(this *Context) {
|
||||
"update": func(that *Context) {
|
||||
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "没有找到要更新的数据")
|
||||
return
|
||||
}
|
||||
re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]})
|
||||
|
||||
if re == 0 {
|
||||
that.Display(4, "更新数据失败")
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
"search": func(this *Context) {
|
||||
user := this.Db.Select(this.RouterString[1], "*")
|
||||
fmt.Println(user, user[0].GetFloat64("age"))
|
||||
this.Display(0, user)
|
||||
"remove": func(that *Context) {
|
||||
re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
|
||||
|
||||
if re == 0 {
|
||||
that.Display(4, "删除数据失败")
|
||||
return
|
||||
}
|
||||
that.Display(0, re)
|
||||
},
|
||||
"search": func(that *Context) {
|
||||
|
||||
columnStr, where := that.MakeCode.Search(that.RouterString[1], that.Req)
|
||||
reData := that.Db.Page(ObjToInt(that.Req.FormValue("page")), ObjToInt(that.Req.FormValue("pageRow"))).
|
||||
Select(that.RouterString[1], columnStr, where)
|
||||
|
||||
that.Display(0, reData)
|
||||
},
|
||||
}
|
||||
|
@ -6,6 +6,9 @@
|
||||
"timeout": 7200
|
||||
}
|
||||
},
|
||||
"codeConfig": {
|
||||
"admin": "config/app.json"
|
||||
},
|
||||
"db": {
|
||||
"sqlite": {
|
||||
"path": "example/config/data.db"
|
||||
@ -16,7 +19,7 @@
|
||||
"index.htm"
|
||||
],
|
||||
"devConfig": {
|
||||
"admin": "config/app.json"
|
||||
"admin": "example/config/app.json"
|
||||
},
|
||||
"error": {
|
||||
"1": "内部系统异常",
|
||||
|
Binary file not shown.
@ -54,6 +54,9 @@ func main() {
|
||||
return false
|
||||
})
|
||||
|
||||
//makeCode := code.MakeCode{}
|
||||
//fmt.Println(common.ObjToStr(makeCode.Db2JSON("admin","test",appIns.Db)))
|
||||
|
||||
appIns.Run(hotime.Router{
|
||||
"admin": admin.Project,
|
||||
"app": hotime.Proj{
|
||||
|
9
var.go
9
var.go
@ -11,7 +11,7 @@ var App = map[string]*Application{} //整个项目
|
||||
|
||||
var Config = Map{
|
||||
"mode": 2, //模式 0生产模式,1,测试模式,2,开发模式
|
||||
"devConfig": Map{
|
||||
"codeConfig": Map{
|
||||
"admin": "config/app.json",
|
||||
},
|
||||
"db": Map{
|
||||
@ -45,8 +45,11 @@ var ConfigNote = Map{
|
||||
"webConnectLogShow": "默认true,非必须,访问日志如果需要web访问链接、访问ip、访问时间打印,false为关闭true开启此功能",
|
||||
"webConnectLogFile": "无默认,非必须,webConnectLogShow开启之后才能使用,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
||||
"mode": "默认0,非必须,0生产模式,1,测试模式,2,开发模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", //debug 0关闭1开启
|
||||
"devConfig": Map{
|
||||
"注释": "配置即启用,非必须,默认无",
|
||||
"codeConfig": Map{
|
||||
"注释": "配置即启用,非必须,默认无",
|
||||
//"package":"默认admin,必须,mode模式为2时会自动生成包文件夹和代码文件",
|
||||
//"path":""
|
||||
|
||||
"packageName": "默认无,必须,包名称以及应用名,生成代码的配置文件地址,比如config/app.json,数据库有更新时自动更新配置文件以及对应的生成文件",
|
||||
},
|
||||
"db": Map{
|
||||
|
Loading…
Reference in New Issue
Block a user