From babf6595eece4d0776117f4641a0f05c8d514c74 Mon Sep 17 00:00:00 2001 From: hoteas Date: Sat, 22 May 2021 04:52:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95demo=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/main.go | 23 ++++++++++++----------- tools/db/auto.go | 6 +++--- tools/mysql/mysql.go | 2 +- tools/sqlite/sqlite.go | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/example/main.go b/example/main.go index 9066f02..b6591ce 100644 --- a/example/main.go +++ b/example/main.go @@ -1,8 +1,9 @@ package main import ( - "code.hoteas.com/golang/hotime" - "code.hoteas.com/golang/hotime/tools/db" + "../../hotime" + "../tools/db" + "database/sql" "fmt" //"go.hoteas.com/hotime/cache" "golang.org/x/net/websocket" @@ -51,15 +52,15 @@ func main() { appIns.SetCache(hotime.CacheIns(&hotime.CacheMemory{})) //快捷模式 - //appIns.SetDefault(func(err ...*hotime.Error) *sql.DB { - // query := appIns.Config.GetString("dbUser") + ":" + appIns.Config.GetString("dbPwd") + - // "@tcp(" + appIns.Config.GetString("dbHost") + ":" + appIns.Config.GetString("dbPort") + ")/" + appIns.Config.GetString("dbName") + "?charset=utf8" - // DB, e := sql.Open("mysql", query) - // if e != nil && len(err) != 0 { - // err[0].SetError(e) - // } - // return DB - //}) + appIns.SetDefault(func(err ...*hotime.Error) *sql.DB { + query := appIns.Config.GetString("dbUser") + ":" + appIns.Config.GetString("dbPwd") + + "@tcp(" + appIns.Config.GetString("dbHost") + ":" + appIns.Config.GetString("dbPort") + ")/" + appIns.Config.GetString("dbName") + "?charset=utf8" + DB, e := sql.Open("mysql", query) + if e != nil && len(err) != 0 { + err[0].SetError(e) + } + return DB + }) appIns.Run(hotime.Router{ "app": hotime.Proj{ diff --git a/tools/db/auto.go b/tools/db/auto.go index 261ea10..42938ef 100644 --- a/tools/db/auto.go +++ b/tools/db/auto.go @@ -1,9 +1,9 @@ package db import ( - "code.hoteas.com/golang/hotime" - "code.hoteas.com/golang/hotime/tools/mysql" - "code.hoteas.com/golang/hotime/tools/sqlite" + "../../../hotime" + "../mysql" + "../sqlite" "strings" ) diff --git a/tools/mysql/mysql.go b/tools/mysql/mysql.go index 23cfb3a..7942286 100644 --- a/tools/mysql/mysql.go +++ b/tools/mysql/mysql.go @@ -1,7 +1,7 @@ package mysql import ( - "code.hoteas.com/golang/hotime" + "../../../hotime" "database/sql" _ "github.com/go-sql-driver/mysql" ) diff --git a/tools/sqlite/sqlite.go b/tools/sqlite/sqlite.go index e7d9534..e101bc5 100644 --- a/tools/sqlite/sqlite.go +++ b/tools/sqlite/sqlite.go @@ -1,7 +1,7 @@ package sqlite import ( - "code.hoteas.com/golang/hotime" + "../../../hotime" "database/sql" _ "github.com/mattn/go-sqlite3" )