接入RESTfull风格接口

This commit is contained in:
hoteas 2021-05-30 00:01:15 +08:00
parent c46fdd8985
commit 465ea889a2
4 changed files with 15 additions and 5 deletions

View File

@ -180,8 +180,11 @@ func (that *Application) SetCache() {
cacheIns := HoTimeCache{} cacheIns := HoTimeCache{}
cacheIns.Init(that.Config.GetMap("cache"), HoTimeDBInterface(&that.Db), &that.Error) cacheIns.Init(that.Config.GetMap("cache"), HoTimeDBInterface(&that.Db), &that.Error)
that.HoTimeCache = &cacheIns that.HoTimeCache = &cacheIns
//debug模式开启的时候关闭数据库缓存防止调试出问题
if that.Config.GetInt("debug") == 0 {
that.Db.HoTimeCache = &cacheIns that.Db.HoTimeCache = &cacheIns
} }
}
// SetConfig 设置配置文件路径全路径或者相对路径 // SetConfig 设置配置文件路径全路径或者相对路径
func (that *Application) SetConfig(configPath ...string) { func (that *Application) SetConfig(configPath ...string) {

View File

@ -142,7 +142,7 @@ func (that *HoTimeDB) Row(resl *sql.Rows) []Map {
if a[j] != nil && reflect.ValueOf(a[j]).Type().String() == "[]uint8" { if a[j] != nil && reflect.ValueOf(a[j]).Type().String() == "[]uint8" {
lis[strs[j]] = string(a[j].([]byte)) lis[strs[j]] = string(a[j].([]byte))
} else { } else {
lis[strs[j]] = a[j] lis[strs[j]] = a[j] //取实际类型
} }
} }
@ -472,7 +472,7 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
//如果缓存有则从缓存取 //如果缓存有则从缓存取
cacheData := that.HoTimeCache.Db(table + ":" + md5) cacheData := that.HoTimeCache.Db(table + ":" + md5)
if cacheData.Data != nil { if cacheData != nil && cacheData.Data != nil {
return cacheData.ToMapArray() return cacheData.ToMapArray()
} }
} }

View File

@ -2,11 +2,16 @@ package admin
import ( import (
. "../../../hotime" . "../../../hotime"
. "../../../hotime/common"
"fmt"
) )
var UserCtr = Ctr{ var UserCtr = Ctr{
"info": func(this *Context) { "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"))
this.Display(0, user)
}, },
"add": func(this *Context) { "add": func(this *Context) {
@ -18,6 +23,8 @@ var UserCtr = Ctr{
}, },
"search": func(this *Context) { "search": func(this *Context) {
user := this.Db.Select(this.RouterString[1], "*")
fmt.Println(user)
this.Display(0, user)
}, },
} }

2
var.go
View File

@ -41,7 +41,7 @@ var ConfigNote = Map{
"logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成a/b/c/年月日时分秒.txt按需设置", "logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成a/b/c/年月日时分秒.txt按需设置",
"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按需设置",
"debug": "默认1必须0关闭其他开启0用于生产环境其他值用于开发测试会显示更多内容并能够辅助研发自动生成配置文件、代码等功能,web无缓存", //debug 0关闭1开启 "debug": "默认1必须0关闭其他开启0用于生产环境其他值用于开发测试会显示更多内容并能够辅助研发自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", //debug 0关闭1开启
"db": Map{ "db": Map{
"注释": "配置即启用非必须默认使用sqlite数据库", "注释": "配置即启用非必须默认使用sqlite数据库",
"mysql": Map{ "mysql": Map{