引入数据库,代码,配置文件三位一体内容,准备进行一体化配置

This commit is contained in:
hoteas 2021-06-03 05:31:09 +08:00
parent 9af232840c
commit 99933e02f4
9 changed files with 166 additions and 10 deletions

View File

@ -180,8 +180,8 @@ func (that *Application) SetCache() {
cacheIns := HoTimeCache{}
cacheIns.Init(that.Config.GetMap("cache"), HoTimeDBInterface(&that.Db), &that.Error)
that.HoTimeCache = &cacheIns
//debug模式开启的时候关闭数据库缓存,防止调试出问题
if that.Config.GetInt("debug") == 0 {
//mode生产模式开启的时候才开启数据库缓存,防止调试出问题
if that.Config.GetInt("mode") == 0 {
that.Db.HoTimeCache = &cacheIns
}
}
@ -382,8 +382,10 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
//设置header
delete(header, "Content-Type")
if that.Config.GetInt("debug") != 1 {
if that.Config.GetInt("mode") == 0 {
header.Set("Cache-Control", "public")
} else {
header.Set("Cache-Control", "no-cache")
}
if strings.Index(path, ".m3u8") != -1 {

View File

@ -4,6 +4,9 @@ import (
. "../../../hotime"
)
var AdminProj = Proj{
var ID = "2f92h3herh23rh2y8"
// Project 管理端项目
var Project = Proj{
"user": UserCtr,
}

View File

@ -8,9 +8,7 @@ import (
var UserCtr = Ctr{
"info": func(this *Context) {
user := this.Db.Get(this.RouterString[1], "*", Map{"uid": this.RouterString[2]})
fmt.Println(user.Get("utime"), user.GetFloat64("utime"), user.GetInt("utime"))
user := this.Db.Get(this.RouterString[1], "*", Map{"id": this.RouterString[2]})
this.Display(0, user)
},
"add": func(this *Context) {

46
example/config/app.json Normal file
View File

@ -0,0 +1,46 @@
{
"name":"HoTimeDashBoard",
"ID": "2f92h3herh23rh2y8",
"label":"HoTime管理平台",
"menu":[
{"label":"平台首页", "name":"HelloWorld", "icon": "el-icon-s-home"},
{"label":"测试表格", "table":"table", "icon": "el-icon-suitcase"},
{"label":"系统管理", "name":"setting","icon": "el-icon-setting",
"menu":[
{"label":"用户管理", "table":"user"},
{"label":"组织管理", "table":"organization"},
{"label":"角色管理", "table":"role"},
{"label":"系统设置", "table":"system", "default": "edit"}
]
}
],
"tables": [
{"label":"用户管理",
"table":"user",
"auth":["add", "delete", "edit", "info"],
"columns": [
{"name": "id", "type": "int", "label": "ID","add":false, "info": false, "edit": false, "list": true,"must": false},
{"name": "password", "type": "password", "label": "密码","add":true, "info": true, "edit": true, "list": false, "must": true},
{"name": "date", "type": "date", "label": "注册日期", "add":true, "info": true, "edit": true, "list": true, "must": true,"sortable": true},
{"name": "role_id", "type": "text", "label": "角色","value": "role.name", "link": "role","add":true, "info": true, "edit": true, "list": true, "must": true},
{"name": "organization_id","link": "organization", "type": "checkbox","value": "organization.name",
"label": "组织","add":true, "info": true, "edit": true, "list": true,"must": true},
{"name": "state", "type": "state", "label": "状态","add":true, "info": true, "edit": true, "list": true, "must": true,
"option":[
{"name":"正常", "value":0},
{"name":"异常", "value":1},
{"name":"全部", "value":null}]}
],
"search":[
{"type": "tree", "name": "oid","label": "组织","table": "organization","showName": "label","children": "children"},
{"type": "text", "name":"keyword", "label":"请输入关键词", "value": null},
{"type": "date", "name":"date", "label":"时间段", "value": null},
{"type": "select", "name":"state", "label":"状态", "value": null,
"option":[
{"name":"正常", "value":0},
{"name":"异常", "value":1},
{"name":"全部", "value":null}]}
]
}
]
}

View File

@ -0,0 +1,32 @@
{
"cache": {
"memory": {
"db": true,
"session": true,
"timeout": 7200
}
},
"db": {
"sqlite": {
"path": "example/config/data.db"
}
},
"defFile": [
"index.html",
"index.htm"
],
"devConfig": {
"admin": "config/app.json"
},
"error": {
"1": "内部系统异常",
"2": "访问权限异常",
"3": "请求参数异常",
"4": "数据处理异常",
"5": "数据结果异常"
},
"mode": 2,
"port": "80",
"sessionName": "HOTIME",
"tpt": "tpt"
}

View File

@ -0,0 +1,68 @@
{
"cache": {
"db": {
"db": "默认false非必须缓存数据库启用后能减少数据库的读写压力",
"session": "默认true非必须缓存web session同时缓存session保持的用户缓存",
"timeout": "默认60 * 60 * 24 * 30非必须过期时间超时自动删除"
},
"memory": {
"db": "默认true非必须缓存数据库启用后能减少数据库的读写压力",
"session": "默认true非必须缓存web session同时缓存session保持的用户缓存",
"timeout": "默认60 * 60 * 2非必须过期时间超时自动删除"
},
"redis": {
"db": "默认true非必须缓存数据库启用后能减少数据库的读写压力",
"host": "默认服务ip127.0.0.1必须如果需要使用redis服务时配置",
"password": "默认密码空必须如果需要使用redis服务时配置默认密码空",
"port": "默认服务端口6379必须如果需要使用redis服务时配置",
"session": "默认true非必须缓存web session同时缓存session保持的用户缓存",
"timeout": "默认60 * 60 * 24 * 15非必须过期时间超时自动删除"
},
"注释": "可配置memorydbredis默认启用memory默认优先级为memory\u003eredis\u003edb,memory与数据库缓存设置项一致缓存数据填充会自动反方向反哺加入memory缓存过期将自动从redis更新但memory永远不会更新redis如果是集群建议不要开启memory配置即启用"
},
"crossDomain": "默认空 非必须空字符串为不开启如果需要跨域设置auto为智能开启所有网站允许跨域http://www.baidu.com为指定域允许跨域",
"db": {
"mysql": {
"host": "默认127.0.0.1必须数据库ip地址",
"name": "默认test必须数据库名称",
"password": "默认root必须数据库密码",
"port": "默认3306必须数据库端口",
"prefix": "默认空,非必须,数据表前缀",
"slave": {
"host": "默认127.0.0.1必须数据库ip地址",
"name": "默认test必须数据库名称",
"password": "默认root必须数据库密码",
"port": "默认3306必须数据库端口",
"user": "默认root必须数据库用户名",
"注释": "从数据库配置mysql里配置slave项即启用主从读写减少数据库压力"
},
"user": "默认root必须数据库用户名",
"注释": "除prefix及主从数据库slave项其他全部必须"
},
"sqlite": {
"path": "默认config/data.db必须数据库位置"
},
"注释": "配置即启用非必须默认使用sqlite数据库"
},
"defFile": "默认访问index.html或者index.htm文件必须默认访问文件类型",
"error": {
"1": "内部系统异常,在环境配置,文件访问权限等基础运行环境条件不足造成严重错误时使用",
"2": "访问权限异常,没有登录或者登录异常等时候使用",
"3": "请求参数异常request参数不满足要求比如参数不足参数类型错误参数不满足要求等时候使用",
"4": "数据处理异常,数据库操作或者三方请求返回的结果非正常结果,比如数据库突然中断等时候使用",
"5": "数据结果异常一般用于无法给出response要求的格式要求下使用比如response需要的是string格式但你只能提供int数据时",
"注释": "web服务内置错误提示自定义异常建议10开始"
},
"logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成a/b/c/年月日时分秒.txt按需设置",
"logLevel": "默认0必须0关闭1打印日志等级",
"mode": "默认0,非必须0生产模式1测试模式2开发模式在开发模式下会显示更多的数据用于开发测试并能够辅助研发自动生成配置文件、代码等功能,web无缓存数据库不启用缓存",
"modeRouterStrict": "默认false,必须路由严格模式false,为大小写忽略必须匹配true必须大小写匹配",
"port": "默认80必须web服务开启Http端口0为不启用http服务,默认80",
"sessionName": "默认HOTIME必须设置session的cookie名",
"tlsCert": "默认空非必须https证书",
"tlsKey": "默认空非必须https密钥",
"tlsPort": "默认空非必须web服务https端口0为不启用https服务",
"tpt": "默认tpt必须web静态文件目录默认为程序目录下tpt目录",
"webConnectLogFile": "无默认非必须webConnectLogShow开启之后才能使用如果需要存储日志文件时使用保存格式为:a/b/c/20060102150405.txt,将生成a/b/c/年月日时分秒.txt按需设置",
"webConnectLogShow": "默认true非必须访问日志如果需要web访问链接、访问ip、访问时间打印false为关闭true开启此功能"
}

BIN
example/config/data.db Normal file

Binary file not shown.

View File

@ -55,7 +55,7 @@ func main() {
})
appIns.Run(hotime.Router{
"admin": admin.AdminProj,
"admin": admin.Project,
"app": hotime.Proj{
"index": hotime.Ctr{
"test": func(this *hotime.Context) {

11
var.go
View File

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