Try to abstract the core package.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/eyebluecn/tank/code/tool/inter"
|
||||
"github.com/eyebluecn/tank/code/core"
|
||||
"github.com/eyebluecn/tank/code/tool/util"
|
||||
"github.com/json-iterator/go"
|
||||
"io/ioutil"
|
||||
@ -65,7 +65,7 @@ type ConfigItem struct {
|
||||
func (this *ConfigItem) validate() bool {
|
||||
|
||||
if this.ServerPort == 0 {
|
||||
inter.LOGGER.Error("ServerPort 未配置")
|
||||
core.LOGGER.Error("ServerPort 未配置")
|
||||
return false
|
||||
} else {
|
||||
//只要配置文件中有配置端口,就使用。
|
||||
@ -73,27 +73,27 @@ func (this *ConfigItem) validate() bool {
|
||||
}
|
||||
|
||||
if this.MysqlUsername == "" {
|
||||
inter.LOGGER.Error("MysqlUsername 未配置")
|
||||
core.LOGGER.Error("MysqlUsername 未配置")
|
||||
return false
|
||||
}
|
||||
|
||||
if this.MysqlPassword == "" {
|
||||
inter.LOGGER.Error("MysqlPassword 未配置")
|
||||
core.LOGGER.Error("MysqlPassword 未配置")
|
||||
return false
|
||||
}
|
||||
|
||||
if this.MysqlHost == "" {
|
||||
inter.LOGGER.Error("MysqlHost 未配置")
|
||||
core.LOGGER.Error("MysqlHost 未配置")
|
||||
return false
|
||||
}
|
||||
|
||||
if this.MysqlPort == 0 {
|
||||
inter.LOGGER.Error("MysqlPort 未配置")
|
||||
core.LOGGER.Error("MysqlPort 未配置")
|
||||
return false
|
||||
}
|
||||
|
||||
if this.MysqlSchema == "" {
|
||||
inter.LOGGER.Error("MysqlSchema 未配置")
|
||||
core.LOGGER.Error("MysqlSchema 未配置")
|
||||
return false
|
||||
}
|
||||
|
||||
@ -135,14 +135,14 @@ func (this *Config) ReadFromConfigFile() {
|
||||
filePath := util.GetConfPath() + "/tank.json"
|
||||
content, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
inter.LOGGER.Warn("无法找到配置文件:%s 即将进入安装过程!", filePath)
|
||||
core.LOGGER.Warn("无法找到配置文件:%s 即将进入安装过程!", filePath)
|
||||
this.Installed = false
|
||||
} else {
|
||||
this.Item = &ConfigItem{}
|
||||
inter.LOGGER.Warn("读取配置文件:%s", filePath)
|
||||
core.LOGGER.Warn("读取配置文件:%s", filePath)
|
||||
err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(content, this.Item)
|
||||
if err != nil {
|
||||
inter.LOGGER.Error("配置文件格式错误! 即将进入安装过程!")
|
||||
core.LOGGER.Error("配置文件格式错误! 即将进入安装过程!")
|
||||
this.Installed = false
|
||||
return
|
||||
}
|
||||
@ -150,7 +150,7 @@ func (this *Config) ReadFromConfigFile() {
|
||||
//验证项是否齐全
|
||||
itemValidate := this.Item.validate()
|
||||
if !itemValidate {
|
||||
inter.LOGGER.Error("配置文件信息不齐全! 即将进入安装过程!")
|
||||
core.LOGGER.Error("配置文件信息不齐全! 即将进入安装过程!")
|
||||
this.Installed = false
|
||||
return
|
||||
}
|
||||
@ -171,8 +171,8 @@ func (this *Config) ReadFromConfigFile() {
|
||||
this.MysqlUrl = util.GetMysqlUrl(this.Item.MysqlPort, this.Item.MysqlHost, this.Item.MysqlSchema, this.Item.MysqlUsername, this.Item.MysqlPassword)
|
||||
this.Installed = true
|
||||
|
||||
inter.LOGGER.Info("使用配置文件:%s", filePath)
|
||||
inter.LOGGER.Info("上传文件存放路径:%s", this.MatterPath)
|
||||
core.LOGGER.Info("使用配置文件:%s", filePath)
|
||||
core.LOGGER.Info("上传文件存放路径:%s", this.MatterPath)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package inter
|
||||
package core
|
||||
|
||||
//日志系统必须高保
|
||||
//全局唯一的日志对象(在main函数中初始化)
|
@ -2,7 +2,7 @@ package rest
|
||||
|
||||
import (
|
||||
"github.com/eyebluecn/tank/code/config"
|
||||
"github.com/eyebluecn/tank/code/tool/inter"
|
||||
"github.com/eyebluecn/tank/code/core"
|
||||
"github.com/eyebluecn/tank/code/tool/result"
|
||||
"github.com/eyebluecn/tank/code/tool/util"
|
||||
"net/http"
|
||||
@ -20,11 +20,11 @@ type IBean interface {
|
||||
}
|
||||
|
||||
type Bean struct {
|
||||
logger inter.Logger
|
||||
logger core.Logger
|
||||
}
|
||||
|
||||
func (this *Bean) Init() {
|
||||
this.logger = inter.LOGGER
|
||||
this.logger = core.LOGGER
|
||||
}
|
||||
|
||||
func (this *Bean) Bootstrap() {
|
||||
|
@ -3,8 +3,8 @@ package rest
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/eyebluecn/tank/code/config"
|
||||
"github.com/eyebluecn/tank/code/core"
|
||||
cache2 "github.com/eyebluecn/tank/code/tool/cache"
|
||||
"github.com/eyebluecn/tank/code/tool/inter"
|
||||
"github.com/jinzhu/gorm"
|
||||
"reflect"
|
||||
)
|
||||
@ -56,7 +56,7 @@ func (this *Context) OpenDb() {
|
||||
this.DB, err = gorm.Open("mysql", config.CONFIG.MysqlUrl)
|
||||
|
||||
if err != nil {
|
||||
inter.LOGGER.Panic("failed to connect mysql database")
|
||||
core.LOGGER.Panic("failed to connect mysql database")
|
||||
}
|
||||
|
||||
//是否打开sql日志(在调试阶段可以打开,以方便查看执行的SQL)
|
||||
@ -68,7 +68,7 @@ func (this *Context) CloseDb() {
|
||||
if this.DB != nil {
|
||||
err := this.DB.Close()
|
||||
if err != nil {
|
||||
inter.LOGGER.Error("关闭数据库连接出错 %s", err.Error())
|
||||
core.LOGGER.Error("关闭数据库连接出错 %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,7 +83,7 @@ func (this *Context) registerBean(bean IBean) {
|
||||
|
||||
err := fmt.Sprintf("【%s】已经被注册了,跳过。", typeName)
|
||||
if _, ok := this.BeanMap[typeName]; ok {
|
||||
inter.LOGGER.Error(fmt.Sprintf(err))
|
||||
core.LOGGER.Error(fmt.Sprintf(err))
|
||||
} else {
|
||||
this.BeanMap[typeName] = element
|
||||
|
||||
@ -95,7 +95,7 @@ func (this *Context) registerBean(bean IBean) {
|
||||
}
|
||||
|
||||
} else {
|
||||
inter.LOGGER.Panic("注册的【%s】不是Bean类型。", typeName)
|
||||
core.LOGGER.Panic("注册的【%s】不是Bean类型。", typeName)
|
||||
}
|
||||
|
||||
}
|
||||
@ -165,7 +165,7 @@ func (this *Context) GetBean(bean IBean) IBean {
|
||||
if val, ok := this.BeanMap[typeName]; ok {
|
||||
return val
|
||||
} else {
|
||||
inter.LOGGER.Panic("【%s】没有注册。", typeName)
|
||||
core.LOGGER.Panic("【%s】没有注册。", typeName)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package rest
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/eyebluecn/tank/code/config"
|
||||
"github.com/eyebluecn/tank/code/tool/inter"
|
||||
"github.com/eyebluecn/tank/code/core"
|
||||
"github.com/eyebluecn/tank/code/tool/result"
|
||||
"github.com/eyebluecn/tank/code/tool/util"
|
||||
"github.com/json-iterator/go"
|
||||
@ -72,7 +72,7 @@ func NewRouter() *Router {
|
||||
func (this *Router) GlobalPanicHandler(writer http.ResponseWriter, request *http.Request, startTime time.Time) {
|
||||
if err := recover(); err != nil {
|
||||
|
||||
inter.LOGGER.Error("错误: %v", err)
|
||||
core.LOGGER.Error("错误: %v", err)
|
||||
|
||||
var webResult *result.WebResult = nil
|
||||
if value, ok := err.(string); ok {
|
||||
|
6
main.go
6
main.go
@ -3,9 +3,9 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/eyebluecn/tank/code/config"
|
||||
"github.com/eyebluecn/tank/code/core"
|
||||
"github.com/eyebluecn/tank/code/rest"
|
||||
"github.com/eyebluecn/tank/code/support"
|
||||
"github.com/eyebluecn/tank/code/tool/inter"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -17,7 +17,7 @@ func main() {
|
||||
tankLogger := &support.TankLogger{}
|
||||
tankLogger.Init()
|
||||
defer tankLogger.Destroy()
|
||||
inter.LOGGER = tankLogger
|
||||
core.LOGGER = tankLogger
|
||||
|
||||
//装载配置文件,这个决定了是否需要执行安装过程
|
||||
config.CONFIG.Init()
|
||||
@ -28,7 +28,7 @@ func main() {
|
||||
|
||||
http.Handle("/", rest.CONTEXT.Router)
|
||||
|
||||
inter.LOGGER.Info("App started at http://localhost:%v", config.CONFIG.ServerPort)
|
||||
core.LOGGER.Info("App started at http://localhost:%v", config.CONFIG.ServerPort)
|
||||
|
||||
dotPort := fmt.Sprintf(":%v", config.CONFIG.ServerPort)
|
||||
err1 := http.ListenAndServe(dotPort, nil)
|
||||
|
Reference in New Issue
Block a user