Finish half translation work.

This commit is contained in:
zicla
2019-05-04 23:36:05 +08:00
parent 900924d196
commit 5625149766
52 changed files with 613 additions and 950 deletions

View File

@ -1,9 +1,6 @@
package core
/**
* 从命令行输入的相关信息
*/
type Application interface {
//启动整个应用
//start the application
Start()
}

View File

@ -1,15 +1,15 @@
package core
/**
* 系统中的Bean接口即系统中单例模式
* bean interface means singleton in application
*/
type Bean interface {
//初始化方法
//init the bean when constructing
Init()
//系统清理方法
//cleanup the bean when system's cleanup
Cleanup()
//所有配置都加载完成后调用的方法,包括数据库加载完毕
//when everything(including db's connection) loaded, this method will be invoked.
Bootstrap()
//快速的Panic方法
//shortcut for panic check.
PanicError(err error)
}

View File

@ -1,33 +1,27 @@
package core
const (
//用户身份的cookie字段名
//authentication key of cookie
COOKIE_AUTH_KEY = "_ak"
//使用用户名密码给接口授权key
USERNAME_KEY = "_username"
PASSWORD_KEY = "_password"
//默认端口号
DEFAULT_SERVER_PORT = 6010
//数据库表前缀 tank30_表示当前应用版本是tank:3.0.x版数据库结构发生变化必然是中型升级
//db table's prefix. tank30_ means current version is tank:3.0.x
TABLE_PREFIX = "tank30_"
//当前版本
VERSION = "3.0.0.beta1"
)
type Config interface {
//是否已经安装
Installed() bool
//启动端口
ServerPort() int
//获取mysql链接
//get the mysql url. eg. tank:tank123@tcp(127.0.0.1:3306)/tank?charset=utf8&parseTime=True&loc=Local
MysqlUrl() string
//文件存放路径
//files storage location.
MatterPath() string
//完成安装过程,主要是要将配置写入到文件中
//when installed by user. Write configs to tank.json
FinishInstall(mysqlPort int, mysqlHost string, mysqlSchema string, mysqlUsername string, mysqlPassword string)
}

View File

@ -7,24 +7,21 @@ import (
)
type Context interface {
//具备响应http请求的能力
http.Handler
//获取数据库链接
//get the gorm.DB. all the db connection will use this
GetDB() *gorm.DB
//获取一个Bean
GetBean(bean Bean) Bean
//获取全局的Session缓存
//get the global session cache
GetSessionCache() *cache.Table
//获取全局的ControllerMap
GetControllerMap() map[string]Controller
//系统安装成功
//when application installed. this method will invoke every bean's Bootstrap method
InstallOk()
//清空系统
//this method will invoke every bean's Cleanup method
Cleanup()
}

View File

@ -4,8 +4,8 @@ import "net/http"
type Controller interface {
Bean
//注册自己固定的路由。
//register self's fixed routes
RegisterRoutes() map[string]func(writer http.ResponseWriter, request *http.Request)
//处理一些特殊的路由。
//handle some special routes, eg. params in the url.
HandleRoutes(writer http.ResponseWriter, request *http.Request) (func(writer http.ResponseWriter, request *http.Request), bool)
}

View File

@ -1,16 +1,15 @@
package core
//该文件中记录的是应用系统中全局变量。主要有日志LOGGER和上下文CONTEXT
//the global variables in the application.
//命令行输入等相关信息
//application
var APPLICATION Application
//日志系统必须高保
//全局唯一的日志对象(在main函数中初始化)
//logger
var LOGGER Logger
//全局唯一配置
//config
var CONFIG Config
//全局唯一的上下文(在main函数中初始化)
//context
var CONTEXT Context

View File

@ -1,18 +1,18 @@
package core
//带有panic恢复的方法
//run a method with panic recovery.
func RunWithRecovery(f func()) {
defer func() {
if err := recover(); err != nil {
LOGGER.Error("异步任务错误: %v", err)
LOGGER.Error("error in async method: %v", err)
}
}()
//执行函数
//execute the method
f()
}
//处理错误的统一方法 可以省去if err!=nil 这段代码
//shortcut for panic check
func PanicError(err error) {
if err != nil {
panic(err)

View File

@ -2,10 +2,10 @@ package core
type Logger interface {
//处理日志的统一方法。
//basic log method
Log(prefix string, format string, v ...interface{})
//不同级别的日志处理
//log with different level.
Debug(format string, v ...interface{})
Info(format string, v ...interface{})
Warn(format string, v ...interface{})