From 99933e02f47851de4887c84bee8aaec80ba12052 Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Thu, 3 Jun 2021 05:31:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=EF=BC=8C=E4=BB=A3=E7=A0=81=EF=BC=8C=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=89=E4=BD=8D=E4=B8=80=E4=BD=93=E5=86=85=E5=AE=B9?= =?UTF-8?q?=EF=BC=8C=E5=87=86=E5=A4=87=E8=BF=9B=E8=A1=8C=E4=B8=80=E4=BD=93?= =?UTF-8?q?=E5=8C=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application.go | 8 ++-- example/admin/init.go | 5 ++- example/admin/user.go | 4 +- example/config/app.json | 46 ++++++++++++++++++++++ example/config/config.json | 32 ++++++++++++++++ example/config/configNote.json | 68 +++++++++++++++++++++++++++++++++ example/config/data.db | Bin 0 -> 16384 bytes example/main.go | 2 +- var.go | 11 +++++- 9 files changed, 166 insertions(+), 10 deletions(-) create mode 100644 example/config/app.json create mode 100644 example/config/config.json create mode 100644 example/config/configNote.json create mode 100644 example/config/data.db diff --git a/application.go b/application.go index 233b601..c654e16 100644 --- a/application.go +++ b/application.go @@ -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 { diff --git a/example/admin/init.go b/example/admin/init.go index 084f46e..5f20a66 100644 --- a/example/admin/init.go +++ b/example/admin/init.go @@ -4,6 +4,9 @@ import ( . "../../../hotime" ) -var AdminProj = Proj{ +var ID = "2f92h3herh23rh2y8" + +// Project 管理端项目 +var Project = Proj{ "user": UserCtr, } diff --git a/example/admin/user.go b/example/admin/user.go index b7e6c91..56378a6 100644 --- a/example/admin/user.go +++ b/example/admin/user.go @@ -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) { diff --git a/example/config/app.json b/example/config/app.json new file mode 100644 index 0000000..f7eda70 --- /dev/null +++ b/example/config/app.json @@ -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}]} + ] + } + ] +} diff --git a/example/config/config.json b/example/config/config.json new file mode 100644 index 0000000..672855e --- /dev/null +++ b/example/config/config.json @@ -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" +} \ No newline at end of file diff --git a/example/config/configNote.json b/example/config/configNote.json new file mode 100644 index 0000000..77545b2 --- /dev/null +++ b/example/config/configNote.json @@ -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": "默认服务ip:127.0.0.1,必须,如果需要使用redis服务时配置,", + "password": "默认密码空,必须,如果需要使用redis服务时配置,默认密码空", + "port": "默认服务端口:6379,必须,如果需要使用redis服务时配置,", + "session": "默认true,非必须,缓存web session,同时缓存session保持的用户缓存", + "timeout": "默认60 * 60 * 24 * 15,非必须,过期时间,超时自动删除" + }, + "注释": "可配置memory,db,redis,默认启用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开启此功能" +} \ No newline at end of file diff --git a/example/config/data.db b/example/config/data.db new file mode 100644 index 0000000000000000000000000000000000000000..f657161208d0a8f542e3661907cd42ef773c8a2a GIT binary patch literal 16384 zcmeI&zfQtH90%|_O2Dgs>e3LmOI&Cm#>5v8wF8k5QAl(ml^&#l7HF>tjErtRf{)?g zTlfn41P&|?UW*uEaB?Ew%U$k%zuuqrvt81gM$MCgcZZ?xNPa^038mzeb3%xwT2{4X z$*95am@Xgu(QD-B@^M#9(Dq)55gUi9LxBJUAOHafKmY;|fB*y_009X6hd^D+6)cnb zUf_yJ9Eq^)x$XET%AQ}_m8Q*G^=hMK^J@LVzU8aabT$mq6fb(Nb(P5#N+o(Ho%?}^ z#shUj z+zX`Wsfe-8Foa! ze@=|~=6oQ&1OgC%00bZa0SG_<0uX=z1Rwx`R3J|^lcj$csE`_;L{$_BKmY;|fB*y_ U009U<00Izz00cHrK+_oe0=8s%f&c&j literal 0 HcmV?d00001 diff --git a/example/main.go b/example/main.go index 5a5e171..f8ed49e 100644 --- a/example/main.go +++ b/example/main.go @@ -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) { diff --git a/var.go b/var.go index 07cb138..bb8eaa3 100644 --- a/var.go +++ b/var.go @@ -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{