From 6eca18b3740749c8699dece1de06a98504406ea1 Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Thu, 20 Feb 2020 15:06:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BF=E9=97=AEip=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E7=AD=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 26 +++++++++++++++++++++++--- application.go | 6 ++++++ example/config/config.json | 16 ++++++++++------ var.go | 8 ++++---- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index eedd6eb..800d99c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,12 @@ - + + + + + + + + + + + @@ -135,6 +154,7 @@ - \ No newline at end of file diff --git a/application.go b/application.go index f7ee562..6a1b246 100644 --- a/application.go +++ b/application.go @@ -14,6 +14,7 @@ import ( "path/filepath" "strconv" "strings" + "time" ) type Application struct { @@ -330,6 +331,11 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) { //跨域设置 CrossDomain(&context) + //是否展示日志 + if this.Config.GetInt("connectLogShow") != 0 { + log.Println(context.HandlerStr + time.Now().Format(" 2006-01-02 15:04 ") + Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))) + } + //访问拦截true继续false暂停 connectListenerLen := len(this.connectListener) if connectListenerLen != 0 { diff --git a/example/config/config.json b/example/config/config.json index 492d7da..5aeb86a 100644 --- a/example/config/config.json +++ b/example/config/config.json @@ -1,6 +1,7 @@ { "cacheLongTime": 2592000, "cacheShortTime": 7200, + "crossDomain": "", "dbCached": 0, "dbHost": "127.0.0.1", "dbName": "test", @@ -12,16 +13,19 @@ "index.html", "index.htm" ], - "error": {}, - "logLevel": 0, + "error": { + "1": "内部系统异常", + "2": "访问权限异常", + "3": "请求参数异常", + "4": "数据处理异常", + "5": "数据结果异常" + }, + "logLevel": 1, "modeRouterStrict": false, "port": "8080", - "redisHost": "192.168.6.254:6379", - "redisPort": "6379", - "redisPwd": "9rusdfjk482fjdfo2e023", "sessionName": "HOTIME", "tlsCert": "", "tlsKey": "", "tlsPort": "0", - "tpt": "example/tpt" + "tpt": "tpt" } \ No newline at end of file diff --git a/var.go b/var.go index ea3792c..1181870 100644 --- a/var.go +++ b/var.go @@ -6,10 +6,9 @@ var App = map[string]*Application{} //整个项目 //var Db = HoTimeDB{} //数据库实例 var Config = Map{ - "debug": 1, //debug 0关闭1开启 - "logLevel": LOG_NIL, - "dbHost": "127.0.0.1", - //"dbHost":"localhost", + "debug": 1, //debug 0关闭1开启 + "logLevel": LOG_NIL, + "dbHost": "127.0.0.1", "dbName": "test", "dbUser": "root", "dbPwd": "root", @@ -62,6 +61,7 @@ var ConfigNote = Map{ "defFile": "默认访问文件,默认访问index.html或者index.htm文件", "crossDomain": "跨域设置,空字符串为不开启,*为开启所有网站允许跨域,http://www.baidu.com为指定域允许跨域", //是否开启跨域 "modeRouterStrict": "路由严格模式false,为大小写忽略必须匹配,true必须大小写匹配", //路由严格模式/a/b/c + "connectLogShow": "web访问链接、访问ip、访问时间打印,0为关闭其他数字开启此功能", "sessionName": "设置session的cookie名默认HOTIME", "port": "web服务开启Http端口,0为不启用http服务", "tlsPort": "web服务https端口,0为不启用https服务",