diff --git a/code/core/config.go b/code/core/config.go index bbbe8b8..d100c76 100644 --- a/code/core/config.go +++ b/code/core/config.go @@ -14,14 +14,14 @@ const ( type Config interface { //是否已经安装 - IsInstalled() bool + Installed() bool //启动端口 - GetServerPort() int + ServerPort() int //获取mysql链接 - GetMysqlUrl() string + MysqlUrl() string //文件存放路径 - GetMatterPath() string + MatterPath() string //完成安装过程,主要是要将配置写入到文件中 FinishInstall(mysqlPort int, mysqlHost string, mysqlSchema string, mysqlUsername string, mysqlPassword string) } diff --git a/code/rest/footprint_service.go b/code/rest/footprint_service.go index 3043488..4d8271c 100644 --- a/code/rest/footprint_service.go +++ b/code/rest/footprint_service.go @@ -76,7 +76,7 @@ func (this *FootprintService) Trace(writer http.ResponseWriter, request *http.Re } //有可能DB尚且没有配置 直接打印出内容,并且退出 - if core.CONFIG.IsInstalled() { + if core.CONFIG.Installed() { user := this.findUser(writer, request) userUuid := "" if user != nil { diff --git a/code/rest/matter_dao.go b/code/rest/matter_dao.go index 40ec5aa..f535052 100644 --- a/code/rest/matter_dao.go +++ b/code/rest/matter_dao.go @@ -366,7 +366,7 @@ func (this *MatterDao) Cleanup() { db := core.CONTEXT.GetDB().Where("uuid is not null").Delete(Matter{}) this.PanicError(db.Error) - err := os.RemoveAll(core.CONFIG.GetMatterPath()) + err := os.RemoveAll(core.CONFIG.MatterPath()) this.PanicError(err) } diff --git a/code/rest/matter_model.go b/code/rest/matter_model.go index 3c525f9..9e24bb0 100644 --- a/code/rest/matter_model.go +++ b/code/rest/matter_model.go @@ -68,7 +68,7 @@ func NewRootMatter(user *User) *Matter { //获取到用户文件的根目录。 func GetUserFileRootDir(username string) (rootDirPath string) { - rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.GetMatterPath(), username, MATTER_ROOT) + rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.MatterPath(), username, MATTER_ROOT) return rootDirPath } @@ -76,7 +76,7 @@ func GetUserFileRootDir(username string) (rootDirPath string) { //获取到用户缓存的根目录。 func GetUserCacheRootDir(username string) (rootDirPath string) { - rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.GetMatterPath(), username, MATTER_CACHE) + rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.MatterPath(), username, MATTER_CACHE) return rootDirPath } diff --git a/code/support/tank_config.go b/code/support/tank_config.go index 3e7d5f6..ea6c1ed 100644 --- a/code/support/tank_config.go +++ b/code/support/tank_config.go @@ -20,15 +20,15 @@ flush privileges; //依赖外部定义的变量。 type TankConfig struct { //默认监听端口号 - ServerPort int + serverPort int //网站是否已经完成安装 - Installed bool + installed bool //上传的文件路径,要求不以/结尾。如果没有指定,默认在根目录下的matter文件夹中。eg: /var/www/matter - MatterPath string + matterPath string //数据库连接信息。 - MysqlUrl string + mysqlUrl string //配置文件中的项 - Item *ConfigItem + item *ConfigItem } //和tank.json文件中的键值一一对应。 @@ -108,7 +108,7 @@ func (this *TankConfig) Init() { }, nil) //默认从6010端口启动 - this.ServerPort = 6010 + this.serverPort = 6010 this.ReadFromConfigFile() @@ -122,64 +122,64 @@ func (this *TankConfig) ReadFromConfigFile() { content, err := ioutil.ReadFile(filePath) if err != nil { core.LOGGER.Warn("无法找到配置文件:%s 即将进入安装过程!", filePath) - this.Installed = false + this.installed = false } else { - this.Item = &ConfigItem{} + this.item = &ConfigItem{} core.LOGGER.Warn("读取配置文件:%s", filePath) - err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(content, this.Item) + err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(content, this.item) if err != nil { core.LOGGER.Error("配置文件格式错误! 即将进入安装过程!") - this.Installed = false + this.installed = false return } //验证项是否齐全 - itemValidate := this.Item.validate() + itemValidate := this.item.validate() if !itemValidate { core.LOGGER.Error("配置文件信息不齐全! 即将进入安装过程!") - this.Installed = false + this.installed = false return } //使用配置项中的文件路径 - if this.Item.MatterPath == "" { - this.MatterPath = util.GetHomePath() + "/matter" + if this.item.MatterPath == "" { + this.matterPath = util.GetHomePath() + "/matter" } else { - this.MatterPath = this.Item.MatterPath + this.matterPath = this.item.MatterPath } - util.MakeDirAll(this.MatterPath) + util.MakeDirAll(this.matterPath) //使用配置项中的端口 - if this.Item.ServerPort != 0 { - this.ServerPort = this.Item.ServerPort + if this.item.ServerPort != 0 { + this.serverPort = this.item.ServerPort } - this.MysqlUrl = util.GetMysqlUrl(this.Item.MysqlPort, this.Item.MysqlHost, this.Item.MysqlSchema, this.Item.MysqlUsername, this.Item.MysqlPassword) - this.Installed = true + this.mysqlUrl = util.GetMysqlUrl(this.item.MysqlPort, this.item.MysqlHost, this.item.MysqlSchema, this.item.MysqlUsername, this.item.MysqlPassword) + this.installed = true core.LOGGER.Info("使用配置文件:%s", filePath) - core.LOGGER.Info("上传文件存放路径:%s", this.MatterPath) + core.LOGGER.Info("上传文件存放路径:%s", this.matterPath) } } //是否已经安装 -func (this *TankConfig) IsInstalled() bool { - return this.Installed +func (this *TankConfig) Installed() bool { + return this.installed } //启动端口 -func (this *TankConfig) GetServerPort() int { - return this.ServerPort +func (this *TankConfig) ServerPort() int { + return this.serverPort } //获取mysql链接 -func (this *TankConfig) GetMysqlUrl() string { - return this.MysqlUrl +func (this *TankConfig) MysqlUrl() string { + return this.mysqlUrl } //文件存放路径 -func (this *TankConfig) GetMatterPath() string { - return this.MatterPath +func (this *TankConfig) MatterPath() string { + return this.matterPath } //完成安装过程,主要是要将配置写入到文件中 @@ -187,9 +187,9 @@ func (this *TankConfig) FinishInstall(mysqlPort int, mysqlHost string, mysqlSche var configItem = &ConfigItem{ //默认监听端口号 - ServerPort: core.CONFIG.GetServerPort(), + ServerPort: core.CONFIG.ServerPort(), //上传的文件路径,要求不以/结尾。如果没有指定,默认在根目录下的matter文件夹中。eg: /var/www/matter - MatterPath: core.CONFIG.GetMatterPath(), + MatterPath: core.CONFIG.MatterPath(), //mysql相关配置。 //数据库端口 MysqlPort: mysqlPort, diff --git a/code/support/tank_context.go b/code/support/tank_context.go index 131de83..cf3e8b5 100644 --- a/code/support/tank_context.go +++ b/code/support/tank_context.go @@ -76,7 +76,7 @@ func (this *TankContext) ServeHTTP(writer http.ResponseWriter, request *http.Req func (this *TankContext) OpenDb() { var err error = nil - this.db, err = gorm.Open("mysql", core.CONFIG.GetMysqlUrl()) + this.db, err = gorm.Open("mysql", core.CONFIG.MysqlUrl()) if err != nil { core.LOGGER.Panic("failed to connect mysql database") @@ -204,7 +204,7 @@ func (this *TankContext) initBeans() { //系统如果安装好了就调用这个方法。 func (this *TankContext) InstallOk() { - if core.CONFIG.IsInstalled() { + if core.CONFIG.Installed() { this.OpenDb() for _, bean := range this.BeanMap { diff --git a/code/support/tank_router.go b/code/support/tank_router.go index fb6c7e6..38c6571 100644 --- a/code/support/tank_router.go +++ b/code/support/tank_router.go @@ -132,7 +132,7 @@ func (this *TankRouter) ServeHTTP(writer http.ResponseWriter, request *http.Requ writer.Header().Set("Cache-Control", "no-cache") writer.Header().Set("Expires", "0") - if core.CONFIG.IsInstalled() { + if core.CONFIG.Installed() { //已安装的模式 //统一处理用户的身份信息。 diff --git a/main.go b/main.go index 27011fa..72899ff 100644 --- a/main.go +++ b/main.go @@ -30,9 +30,9 @@ func main() { //第四步。启动http服务 http.Handle("/", core.CONTEXT) - core.LOGGER.Info("App started at http://localhost:%v", core.CONFIG.GetServerPort()) + core.LOGGER.Info("App started at http://localhost:%v", core.CONFIG.ServerPort()) - dotPort := fmt.Sprintf(":%v", core.CONFIG.GetServerPort()) + dotPort := fmt.Sprintf(":%v", core.CONFIG.ServerPort()) err1 := http.ListenAndServe(dotPort, nil) if err1 != nil { log.Fatal("ListenAndServe: ", err1)