Finish all the i18n things of code.
This commit is contained in:
@ -17,39 +17,37 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
//启动web服务,默认是这种方式
|
||||
//start web. This is the default mode.
|
||||
MODE_WEB = "web"
|
||||
//映射本地文件到云盘中
|
||||
//mirror local files to EyeblueTank.
|
||||
MODE_MIRROR = "mirror"
|
||||
//将远程的一个文件爬取到蓝眼云盘中
|
||||
//crawl remote file to EyeblueTank
|
||||
MODE_CRAWL = "crawl"
|
||||
//TODO: 查看当前蓝眼云盘版本
|
||||
//Current version.
|
||||
MODE_VERSION = "version"
|
||||
)
|
||||
|
||||
//命令行输入相关的对象
|
||||
type TankApplication struct {
|
||||
//模式
|
||||
//mode
|
||||
mode string
|
||||
|
||||
//蓝眼云盘的主机,需要带上协议和端口号。默认: http://127.0.0.1:core.DEFAULT_SERVER_PORT
|
||||
//EyeblueTank host and port default: http://127.0.0.1:core.DEFAULT_SERVER_PORT
|
||||
host string
|
||||
//用户名
|
||||
//username
|
||||
username string
|
||||
//密码
|
||||
//password
|
||||
password string
|
||||
|
||||
//源文件/文件夹,本地绝对路径/远程资源url
|
||||
//source file/directory different mode has different usage.
|
||||
src string
|
||||
//目标(表示的是文件夹)路径,蓝眼云盘中的路径。相对于root的路径。
|
||||
//destination directory path(relative to root) in EyeblueTank
|
||||
dest string
|
||||
//同名文件或文件夹是否直接替换 true 全部替换; false 跳过
|
||||
//true: overwrite, false:skip
|
||||
overwrite bool
|
||||
//拉取文件存储的名称
|
||||
filename string
|
||||
filename string
|
||||
}
|
||||
|
||||
//启动应用。可能是web形式,也可能是命令行工具。
|
||||
//Start the application.
|
||||
func (this *TankApplication) Start() {
|
||||
|
||||
defer func() {
|
||||
@ -58,7 +56,6 @@ func (this *TankApplication) Start() {
|
||||
}
|
||||
}()
|
||||
|
||||
//超级管理员信息
|
||||
modePtr := flag.String("mode", this.mode, "cli mode web/mirror/crawl")
|
||||
hostPtr := flag.String("host", this.username, "tank host")
|
||||
usernamePtr := flag.String("username", this.username, "username")
|
||||
@ -68,7 +65,7 @@ func (this *TankApplication) Start() {
|
||||
overwritePtr := flag.Bool("overwrite", this.overwrite, "whether same file overwrite")
|
||||
filenamePtr := flag.String("filename", this.filename, "filename when crawl")
|
||||
|
||||
//flag.Parse()方法必须要在使用之前调用。
|
||||
//flag.Parse() must invoke before use.
|
||||
flag.Parse()
|
||||
|
||||
this.mode = *modePtr
|
||||
@ -80,36 +77,30 @@ func (this *TankApplication) Start() {
|
||||
this.overwrite = *overwritePtr
|
||||
this.filename = *filenamePtr
|
||||
|
||||
//默认采用web的形式启动
|
||||
//default start as web.
|
||||
if this.mode == "" || strings.ToLower(this.mode) == MODE_WEB {
|
||||
|
||||
//直接web启动
|
||||
this.HandleWeb()
|
||||
|
||||
} else if strings.ToLower(this.mode) == MODE_VERSION {
|
||||
|
||||
//直接web启动
|
||||
this.HandleVersion()
|
||||
|
||||
} else {
|
||||
|
||||
//准备蓝眼云盘地址
|
||||
//default host.
|
||||
if this.host == "" {
|
||||
this.host = fmt.Sprintf("http://127.0.0.1:%d", core.DEFAULT_SERVER_PORT)
|
||||
}
|
||||
|
||||
//准备用户名
|
||||
if this.username == "" {
|
||||
panic(result.BadRequest("%s模式下,用户名必填", this.mode))
|
||||
panic(result.BadRequest("in mode %s, username is required", this.mode))
|
||||
}
|
||||
|
||||
//准备密码
|
||||
if this.password == "" {
|
||||
|
||||
if util.EnvDevelopment() {
|
||||
|
||||
panic(result.BadRequest("IDE中请运行请直接使用 -password yourPassword 的形式输入密码"))
|
||||
|
||||
panic(result.BadRequest("If run in IDE, use -password yourPassword to input password"))
|
||||
} else {
|
||||
|
||||
fmt.Print("Enter Password:")
|
||||
@ -125,42 +116,39 @@ func (this *TankApplication) Start() {
|
||||
|
||||
if strings.ToLower(this.mode) == MODE_MIRROR {
|
||||
|
||||
//映射本地文件到蓝眼云盘
|
||||
this.HandleMirror()
|
||||
|
||||
} else if strings.ToLower(this.mode) == MODE_CRAWL {
|
||||
|
||||
//将远程文件拉取到蓝眼云盘中
|
||||
this.HandleCrawl()
|
||||
|
||||
} else {
|
||||
panic(result.BadRequest("不能处理命名行模式: %s \r\n", this.mode))
|
||||
panic(result.BadRequest("cannot handle mode %s \r\n", this.mode))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//采用Web的方式启动应用
|
||||
func (this *TankApplication) HandleWeb() {
|
||||
|
||||
//第1步。日志
|
||||
//Step 1. Logger
|
||||
tankLogger := &TankLogger{}
|
||||
core.LOGGER = tankLogger
|
||||
tankLogger.Init()
|
||||
defer tankLogger.Destroy()
|
||||
|
||||
//第2步。配置
|
||||
//Step 2. Configuration
|
||||
tankConfig := &TankConfig{}
|
||||
core.CONFIG = tankConfig
|
||||
tankConfig.Init()
|
||||
|
||||
//第3步。全局运行的上下文
|
||||
//Step 3. Global Context
|
||||
tankContext := &TankContext{}
|
||||
core.CONTEXT = tankContext
|
||||
tankContext.Init()
|
||||
defer tankContext.Destroy()
|
||||
|
||||
//第4步。启动http服务
|
||||
//Step 4. Start http
|
||||
http.Handle("/", core.CONTEXT)
|
||||
core.LOGGER.Info("App started at http://localhost:%v", core.CONFIG.ServerPort())
|
||||
|
||||
@ -172,17 +160,16 @@ func (this *TankApplication) HandleWeb() {
|
||||
|
||||
}
|
||||
|
||||
//处理本地映射的情形
|
||||
func (this *TankApplication) HandleMirror() {
|
||||
|
||||
if this.src == "" {
|
||||
panic("src 必填")
|
||||
panic("src is required")
|
||||
}
|
||||
if this.dest == "" {
|
||||
panic("dest 必填")
|
||||
panic("dest is required")
|
||||
}
|
||||
|
||||
fmt.Printf("开始映射本地文件 %s 到蓝眼云盘 %s\r\n", this.src, this.dest)
|
||||
fmt.Printf("start mirror %s to EyeblueTank %s\r\n", this.src, this.dest)
|
||||
|
||||
urlString := fmt.Sprintf("%s/api/matter/mirror", this.host)
|
||||
|
||||
@ -203,7 +190,7 @@ func (this *TankApplication) HandleMirror() {
|
||||
|
||||
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(bodyBytes, webResult)
|
||||
if err != nil {
|
||||
fmt.Printf("返回格式错误!%s \r\n", err.Error())
|
||||
fmt.Printf("error response format %s \r\n", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@ -215,21 +202,20 @@ func (this *TankApplication) HandleMirror() {
|
||||
|
||||
}
|
||||
|
||||
//拉取远程文件到本地。
|
||||
func (this *TankApplication) HandleCrawl() {
|
||||
|
||||
if this.src == "" {
|
||||
panic("src 必填")
|
||||
panic("src is required")
|
||||
}
|
||||
if this.dest == "" {
|
||||
panic("dest 必填")
|
||||
panic("dest is required")
|
||||
}
|
||||
|
||||
if this.filename == "" {
|
||||
panic("filename 必填")
|
||||
panic("filename is required")
|
||||
}
|
||||
|
||||
fmt.Printf("开始映射拉取远程文件 %s 到蓝眼云盘 %s\r\n", this.src, this.dest)
|
||||
fmt.Printf("crawl %s to EyeblueTank %s\r\n", this.src, this.dest)
|
||||
|
||||
urlString := fmt.Sprintf("%s/api/matter/crawl", this.host)
|
||||
|
||||
@ -250,7 +236,7 @@ func (this *TankApplication) HandleCrawl() {
|
||||
|
||||
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(bodyBytes, webResult)
|
||||
if err != nil {
|
||||
fmt.Printf("返回格式错误!%s \r\n", err.Error())
|
||||
fmt.Printf("Error response format %s \r\n", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user