已经接入配置文件,开始准备生成代码

This commit is contained in:
hoteas 2021-06-04 02:57:56 +08:00
parent 99933e02f4
commit fe085ce889
9 changed files with 96 additions and 20 deletions

View File

@ -2,6 +2,7 @@ package hotime
import ( import (
. "./cache" . "./cache"
"./code"
. "./common" . "./common"
. "./db" . "./db"
. "./log" . "./log"
@ -19,6 +20,7 @@ import (
) )
type Application struct { type Application struct {
*code.MakeCode
MethodRouter MethodRouter
Router Router
ContextBase ContextBase
@ -307,10 +309,9 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
unescapeUrl = req.RequestURI unescapeUrl = req.RequestURI
} }
//访问实例 //访问实例
context := Context{SessionIns: SessionIns{SessionId: sessionId, context := Context{SessionIns: SessionIns{SessionId: sessionId, HoTimeCache: that.HoTimeCache},
HoTimeCache: that.HoTimeCache, Resp: w, Req: req, Application: that, RouterString: s, Config: that.Config, Db: &that.Db,
}, HandlerStr: unescapeUrl}
Resp: w, Req: req, Application: that, RouterString: s, Config: that.Config, Db: &that.Db, HandlerStr: unescapeUrl}
//header默认设置 //header默认设置
header := w.Header() header := w.Header()
header.Set("Content-Type", "text/html; charset=utf-8") header.Set("Content-Type", "text/html; charset=utf-8")
@ -448,6 +449,15 @@ func Init(config string) Application {
SetDB(&appIns) SetDB(&appIns)
appIns.SetCache() 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 return appIns
} }

23
code/config.go Normal file
View 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"},
},
},
},
}

View File

@ -44,6 +44,8 @@ func (that *Context) Display(statu int, data interface{}) {
temp["type"] = tpe temp["type"] = tpe
temp["msg"] = data temp["msg"] = data
resp["result"] = temp resp["result"] = temp
//兼容android等需要json转对象的服务
resp["error"] = temp
} else { } else {
resp["result"] = data resp["result"] = data
} }

View File

@ -3,26 +3,58 @@ package admin
import ( import (
. "../../../hotime" . "../../../hotime"
. "../../../hotime/common" . "../../../hotime/common"
"fmt"
) )
var UserCtr = Ctr{ var UserCtr = Ctr{
"info": func(this *Context) { "info": func(that *Context) {
user := this.Db.Get(this.RouterString[1], "*", Map{"id": this.RouterString[2]}) re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]})
this.Display(0, user) 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)
}, if re == 0 {
"update": func(this *Context) { 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) { "remove": func(that *Context) {
user := this.Db.Select(this.RouterString[1], "*") re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
fmt.Println(user, user[0].GetFloat64("age"))
this.Display(0, user) 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)
}, },
} }

View File

@ -6,6 +6,9 @@
"timeout": 7200 "timeout": 7200
} }
}, },
"codeConfig": {
"admin": "config/app.json"
},
"db": { "db": {
"sqlite": { "sqlite": {
"path": "example/config/data.db" "path": "example/config/data.db"
@ -16,7 +19,7 @@
"index.htm" "index.htm"
], ],
"devConfig": { "devConfig": {
"admin": "config/app.json" "admin": "example/config/app.json"
}, },
"error": { "error": {
"1": "内部系统异常", "1": "内部系统异常",

Binary file not shown.

View File

@ -54,6 +54,9 @@ func main() {
return false return false
}) })
//makeCode := code.MakeCode{}
//fmt.Println(common.ObjToStr(makeCode.Db2JSON("admin","test",appIns.Db)))
appIns.Run(hotime.Router{ appIns.Run(hotime.Router{
"admin": admin.Project, "admin": admin.Project,
"app": hotime.Proj{ "app": hotime.Proj{

9
var.go
View File

@ -11,7 +11,7 @@ var App = map[string]*Application{} //整个项目
var Config = Map{ var Config = Map{
"mode": 2, //模式 0生产模式1测试模式2开发模式 "mode": 2, //模式 0生产模式1测试模式2开发模式
"devConfig": Map{ "codeConfig": Map{
"admin": "config/app.json", "admin": "config/app.json",
}, },
"db": Map{ "db": Map{
@ -45,8 +45,11 @@ var ConfigNote = Map{
"webConnectLogShow": "默认true非必须访问日志如果需要web访问链接、访问ip、访问时间打印false为关闭true开启此功能", "webConnectLogShow": "默认true非必须访问日志如果需要web访问链接、访问ip、访问时间打印false为关闭true开启此功能",
"webConnectLogFile": "无默认非必须webConnectLogShow开启之后才能使用如果需要存储日志文件时使用保存格式为:a/b/c/20060102150405.txt,将生成a/b/c/年月日时分秒.txt按需设置", "webConnectLogFile": "无默认非必须webConnectLogShow开启之后才能使用如果需要存储日志文件时使用保存格式为:a/b/c/20060102150405.txt,将生成a/b/c/年月日时分秒.txt按需设置",
"mode": "默认0,非必须0生产模式1测试模式2开发模式在开发模式下会显示更多的数据用于开发测试并能够辅助研发自动生成配置文件、代码等功能,web无缓存数据库不启用缓存", //debug 0关闭1开启 "mode": "默认0,非必须0生产模式1测试模式2开发模式在开发模式下会显示更多的数据用于开发测试并能够辅助研发自动生成配置文件、代码等功能,web无缓存数据库不启用缓存", //debug 0关闭1开启
"devConfig": Map{ "codeConfig": Map{
"注释": "配置即启用,非必须,默认无", "注释": "配置即启用,非必须,默认无",
//"package":"默认admin必须mode模式为2时会自动生成包文件夹和代码文件",
//"path":""
"packageName": "默认无必须包名称以及应用名生成代码的配置文件地址比如config/app.json数据库有更新时自动更新配置文件以及对应的生成文件", "packageName": "默认无必须包名称以及应用名生成代码的配置文件地址比如config/app.json数据库有更新时自动更新配置文件以及对应的生成文件",
}, },
"db": Map{ "db": Map{