diff --git a/install.ps1 b/install.ps1 index 77eb641..ece0a60 100644 --- a/install.ps1 +++ b/install.ps1 @@ -42,5 +42,5 @@ if (!(";$Path;".ToLower() -like "*;$BinDir;*".ToLower())) { $Env:Path += ";$BinDir" } -Write-Output "ipgw was installed successfully to $TargetPath" -Write-Output "Run 'ipgw --help' to get started" \ No newline at end of file +Write-Output "ipgw成功安装至 $TargetPath" +Write-Output "运行 'ipgw --help' 来获取帮助" \ No newline at end of file diff --git a/install.sh b/install.sh index ea05ea9..2833cc5 100644 --- a/install.sh +++ b/install.sh @@ -3,7 +3,7 @@ set -e if ! command -v unzip >/dev/null; then - echo "Error: unzip is required to install ipgw." 1>&2 + echo "Error: 安装ipgw需要unzip。" 1>&2 exit 1 fi @@ -37,15 +37,15 @@ unzip -d "$bin_dir" -o "$target_path.zip" chmod +x "$target_path" rm "$target_path.zip" -echo "ipgw was installed successfully to $target_path" +echo "ipgw成功安装至 $target_path" if command -v ipgw >/dev/null; then - echo "Run 'ipgw --help' to get started" + echo "运行 'ipgw --help' 来获取帮助" else case $SHELL in /bin/zsh) shell_profile=".zshrc" ;; *) shell_profile=".bash_profile" ;; esac - echo "Manually add the directory to your \$HOME/$shell_profile (or similar)" + echo "请手动添加目录至 \$HOME/$shell_profile (or similar)" echo " export PATH=\"$bin_dir:\$PATH\"" - echo "Run '$target_path --help' to get started" + echo "运行 'ipgw --help' 来获取帮助" fi \ No newline at end of file diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index 0a7abe3..212904c 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -14,7 +14,7 @@ var ( App = &cli.App{ Name: "ipgw", HelpName: "ipgw", - Copyright: "Home page:\thttps://github.com/neucn/ipgw\nFeedback:\thttps://github.com/neucn/ipgw/issues/new", + Copyright: "主页:\thttps://github.com/neucn/ipgw\nFeedback:\thttps://github.com/neucn/ipgw/issues/new", Commands: []*cli.Command{ LoginCommand, LogoutCommand, @@ -27,7 +27,7 @@ var ( }, Action: func(ctx *cli.Context) error { if ctx.NArg() != 0 { - console.InfoL("command not found\n") + console.InfoL("未找到命令\n") cli.ShowAppHelpAndExit(ctx, 1) return nil } @@ -43,7 +43,7 @@ var ( &cli.StringFlag{ Name: "config", Aliases: []string{"f"}, - Usage: "load configuration from specific `file`", + Usage: "载入配置文件", }, }, OnUsageError: onUsageError, @@ -58,13 +58,13 @@ func loginUseDefaultAccount(ctx *cli.Context) error { } account := store.Config.GetDefaultAccount() if account == nil { - return errors.New("no account stored") + return errors.New("无储存账户") } - console.InfoF("using account '%s'\n", account.Username) + console.InfoF("正在使用账户 '%s'\n", account.Username) account.Secret = ctx.String("secret") if err = login(handler.NewIpgwHandler(), account); err != nil { - return fmt.Errorf("login failed: \n\t%v", err) + return fmt.Errorf("登陆失败:\n\t%v", err) } return nil } @@ -83,13 +83,13 @@ func getAccountByContext(ctx *cli.Context) (account *model.Account, err error) { } else if u := ctx.String("username"); u == "" { // use stored default account if account = store.Config.GetDefaultAccount(); account == nil { - return nil, errors.New("no stored account\n\tplease provide username and password") + return nil, errors.New("无储存账户\n\t请提供账号与密码") } - console.InfoF("using account '%s'\n", account.Username) + console.InfoF("正在使用账户 '%s'\n", account.Username) } else if p := ctx.String("password"); p == "" { // use stored account if account = store.Config.GetAccount(u); account == nil { - return nil, fmt.Errorf("account '%s' not found", u) + return nil, fmt.Errorf("账号 '%s' 未找到", u) } } else { // use username and password @@ -120,46 +120,46 @@ func onUsageError(ctx *cli.Context, err error, isSubcommand bool) error { } func init() { - cli.AppHelpTemplate = `USAGE: + cli.AppHelpTemplate = `用法: {{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}} {{if .Commands}} -COMMANDS: +命令: {{range .Commands}}{{if not .HideHelp}} {{join .Names ", "}}{{ "\t"}}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{end}} -OPTIONS: +选项: {{range .VisibleFlags}}{{.}} {{end}} {{.Copyright}} ` cli.CommandHelpTemplate = `{{.Usage}} -USAGE: +用法: {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}} -CATEGORY: +目录: {{.Category}}{{end}}{{if .Description}} -DESCRIPTION: +描述: {{.Description | nindent 3 | trim}}{{end}}{{if .VisibleFlags}} -OPTIONS: +选项: {{range .VisibleFlags}}{{.}} {{end}}{{end}} ` cli.SubcommandHelpTemplate = `{{.Usage}} -USAGE: +用法: {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}} -DESCRIPTION: +描述: {{.Description | nindent 3 | trim}}{{end}} -COMMANDS:{{range .VisibleCategories}}{{if .Name}} +命令:{{range .VisibleCategories}}{{if .Name}} {{.Name}}:{{range .VisibleCommands}} {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}} {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} -OPTIONS: +选项: {{range .VisibleFlags}}{{.}} {{end}}{{end}} ` diff --git a/pkg/cmd/config.go b/pkg/cmd/config.go index 12c2a6f..354610f 100644 --- a/pkg/cmd/config.go +++ b/pkg/cmd/config.go @@ -10,11 +10,11 @@ import ( var ( ConfigCommand = &cli.Command{ Name: "config", - Usage: "manage config", + Usage: "管理配置文件", Subcommands: []*cli.Command{ { Name: "account", - Usage: "manage accounts stored in config", + Usage: "管理配置文件中的账户", Subcommands: []*cli.Command{ configAccountAddCommand, configAccountDelCommand, @@ -29,28 +29,28 @@ var ( configAccountAddCommand = &cli.Command{ Name: "add", - Usage: "add account into config", + Usage: "在配置文件中添加账户", Flags: []cli.Flag{ &cli.StringFlag{ Name: "username", Aliases: []string{"u"}, Required: true, - Usage: "student number `id`", + Usage: "学号", }, &cli.StringFlag{ Name: "password", Aliases: []string{"p"}, Required: true, - Usage: "`password` for pass.neu.edu.cn", + Usage: "网关密码", }, &cli.StringFlag{ Name: "secret", Aliases: []string{"s"}, - Usage: "`secret` for stored account", + Usage: "密保问题", }, &cli.BoolFlag{ Name: "default", - Usage: "add the account as the default one", + Usage: "添加默认账户", }, }, Action: func(ctx *cli.Context) error { @@ -64,7 +64,7 @@ var ( username, password, ctx.String("secret")); err != nil { - return fmt.Errorf("fail to add account:\n\t%v", err) + return fmt.Errorf("无法添加账户:\n\t%v", err) } if ctx.Bool("default") { @@ -73,7 +73,7 @@ var ( if err = store.Persist(); err != nil { return err } - console.InfoF("'%s' added successfully\n", username) + console.InfoF("'%s' 添加成功\n", username) return nil }, OnUsageError: onUsageError, @@ -81,13 +81,13 @@ var ( configAccountDelCommand = &cli.Command{ Name: "del", - Usage: "delete account from config", + Usage: "从配置文件中删除账户", Flags: []cli.Flag{ &cli.StringFlag{ Name: "username", Aliases: []string{"u"}, Required: true, - Usage: "student number `id` to be deleted", + Usage: "要删除的账户学号", }, }, Action: func(ctx *cli.Context) error { @@ -98,13 +98,13 @@ var ( username := ctx.String("username") if !store.Config.DelAccount(username) { - return fmt.Errorf("fail to delete account:\n\t'%s' not found", username) + return fmt.Errorf("无法删除账户:\n\t'%s' 账户没有找到", username) } if err = store.Persist(); err != nil { return err } - console.InfoF("'%s' deleted successfully\n", username) + console.InfoF("'%s' 删除成功\n", username) return nil }, OnUsageError: onUsageError, @@ -112,27 +112,27 @@ var ( configAccountSetCommand = &cli.Command{ Name: "set", - Usage: "edit account in config", + Usage: "编辑配置文件中的账户", Flags: []cli.Flag{ &cli.StringFlag{ Name: "username", Aliases: []string{"u"}, Required: true, - Usage: "student number `id` to be edited", + Usage: "要编辑的账户学号", }, &cli.StringFlag{ Name: "password", Aliases: []string{"p"}, - Usage: "new `password` for pass.neu.edu.cn", + Usage: "新的登陆网关密码", }, &cli.StringFlag{ Name: "secret", Aliases: []string{"s"}, - Usage: "new `secret` for stored account, must be used with --password, -p", + Usage: "为帐户设置新密保,输入格式: --password, -p", }, &cli.BoolFlag{ Name: "default", - Usage: "set the account as the default one", + Usage: "设置为默认账户", }, }, Action: func(ctx *cli.Context) error { @@ -143,13 +143,13 @@ var ( username := ctx.String("username") account := store.Config.GetAccount(username) if account == nil { - return fmt.Errorf("fail to set account:\n\t'%s' not found", username) + return fmt.Errorf("无法设置账户:\n\t'%s' 账户没有找到", username) } password := ctx.String("password") if password != "" { if err = account.SetPassword(ctx.String("password"), []byte(ctx.String("secret"))); err != nil { - return fmt.Errorf("fail to set account:\n\t'%s' not found", username) + return fmt.Errorf("无法设置账户:\n\t'%s' 账户没有找到", username) } } @@ -160,7 +160,7 @@ var ( if err = store.Persist(); err != nil { return err } - console.InfoF("'%s' edited successfully\n", username) + console.InfoF("'%s' 编辑成功\n", username) return nil }, OnUsageError: onUsageError, @@ -169,7 +169,7 @@ var ( configAccountListCommand = &cli.Command{ Name: "list", Aliases: []string{"ls"}, - Usage: "list accounts in config", + Usage: "配置文件中的账户列表", Action: func(ctx *cli.Context) error { store, err := getStoreHandler(ctx) if err != nil { diff --git a/pkg/cmd/info.go b/pkg/cmd/info.go index 57422f5..e89066c 100644 --- a/pkg/cmd/info.go +++ b/pkg/cmd/info.go @@ -11,23 +11,23 @@ import ( var ( InfoCommand = &cli.Command{ Name: "info", - Usage: "list account info", + Usage: "列出账户信息", UseShortOptionHandling: true, Flags: []cli.Flag{ &cli.StringFlag{ Name: "username", Aliases: []string{"u"}, - Usage: "student number `id` (required only if not use the default or first stored account)", + Usage: "学号(仅在使用非默认账户或者首次储存默认账户时使用)", }, &cli.StringFlag{ Name: "password", Aliases: []string{"p"}, - Usage: "`password` for pass.neu.edu.cn (required only if account is not stored)", + Usage: "网关登陆密码(仅在账户未储存时需要)", }, &cli.StringFlag{ Name: "secret", Aliases: []string{"s"}, - Usage: "`secret` for stored account (required only if secret is not empty)", + Usage: "账户密保问题(仅在未设置时需要)", }, &cli.BoolFlag{Name: "all", Aliases: []string{"a"}, Usage: "list all kind of info, equivalent to -lbird"}, @@ -44,7 +44,7 @@ var ( } h := handler.NewDashboardHandler() if err := h.Login(account); err != nil { - return fmt.Errorf("fail to login:\n\t%v", err) + return fmt.Errorf("无法登陆:\n\t%v", err) } processInfoPrint(ctx, &infoPrinter{h}) return nil diff --git a/pkg/cmd/kick.go b/pkg/cmd/kick.go index e4583a6..185c49d 100644 --- a/pkg/cmd/kick.go +++ b/pkg/cmd/kick.go @@ -9,30 +9,30 @@ import ( var ( KickCommand = &cli.Command{ Name: "kick", - Usage: "logout any specific device by SID", + Usage: "通过SID使特定设备下线", ArgsUsage: "[sid list]", UseShortOptionHandling: true, Flags: []cli.Flag{ &cli.StringFlag{ Name: "username", Aliases: []string{"u"}, - Usage: "student number `id` (required only if not use the default or first stored account)", + Usage: "学号(仅在使用非默认账户或者首次储存默认账户时使用)", }, &cli.StringFlag{ Name: "password", Aliases: []string{"p"}, - Usage: "`password` for pass.neu.edu.cn (required only if account is not stored)", + Usage: "网关登陆密码(仅在账户未储存时需要)", }, &cli.StringFlag{ Name: "secret", Aliases: []string{"s"}, - Usage: "`secret` for stored account (required only if secret is not empty)", + Usage: "账户密保问题(仅在未设置时需要)", }, }, Action: func(ctx *cli.Context) error { sids := ctx.Args().Slice() if len(sids) == 0 { - console.InfoL("no sid") + console.InfoL("无sid") return nil } account, err := getAccountByContext(ctx) @@ -50,9 +50,9 @@ var ( for _, sid := range sids { result, err := h.Kick(sid) if result { - console.InfoF("#%s: done\n", sid) + console.InfoF("#%s: 完成\n", sid) } else { - console.InfoF("#%s: fail\n", sid) + console.InfoF("#%s: 失败\n", sid) if err != nil { console.InfoF("\t%v\n", err) } diff --git a/pkg/cmd/login.go b/pkg/cmd/login.go index 871a3bf..a21aa2c 100644 --- a/pkg/cmd/login.go +++ b/pkg/cmd/login.go @@ -13,17 +13,17 @@ import ( var ( LoginCommand = &cli.Command{ Name: "login", - Usage: "login ipgw", + Usage: "登陆网关", Flags: []cli.Flag{ &cli.StringFlag{ Name: "username", Aliases: []string{"u"}, - Usage: "student number `id` (required only if not use the default or first stored account)", + Usage: "学号(仅在使用非默认账户或者首次储存默认账户时使用)", }, &cli.StringFlag{ Name: "password", Aliases: []string{"p"}, - Usage: "`password` for pass.neu.edu.cn (required only if account is not stored)", + Usage: "网关登陆密码(仅在账户未储存时需要)", }, &cli.StringFlag{ Name: "cookie", @@ -33,7 +33,7 @@ var ( &cli.StringFlag{ Name: "secret", Aliases: []string{"s"}, - Usage: "`secret` for stored account (required only if secret is not empty)", + Usage: "账户密保问题(仅在未设置时需要)", }, &cli.BoolFlag{ Name: "info", @@ -48,11 +48,11 @@ var ( } h := handler.NewIpgwHandler() if err = login(h, account); err != nil { - return fmt.Errorf("login failed: \n\t%v", err) + return fmt.Errorf("登陆失败: \n\t%v", err) } if ctx.Bool("info") { if err = h.FetchUsageInfo(); err != nil { - return fmt.Errorf("fetch info failed: \n\t%v", err) + return fmt.Errorf("获取信息失败: \n\t%v", err) } info := h.GetInfo() console.InfoF("\tIP\t%16s\n\t余额\t%16s\n\t流量\t%16s\n\t时长\t%16s\n", @@ -71,18 +71,18 @@ func login(h *handler.IpgwHandler, account *model.Account) error { // check logged connected, loggedIn := h.IsConnectedAndLoggedIn() if !connected { - return errors.New("not in campus network") + return errors.New("未连接到校园网") } if loggedIn { - return fmt.Errorf("already logged in as '%s'", h.GetInfo().Username) + return fmt.Errorf("已登陆为 '%s'", h.GetInfo().Username) } if err := h.Login(account); err != nil { return err } info := h.GetInfo() if info.Username == "" { - return fmt.Errorf("unknown reason") + return fmt.Errorf("未知原因") } - console.InfoL("login successfully") + console.InfoL("登陆成功") return nil } diff --git a/pkg/cmd/logout.go b/pkg/cmd/logout.go index 3e5b875..e682d27 100644 --- a/pkg/cmd/logout.go +++ b/pkg/cmd/logout.go @@ -11,21 +11,21 @@ import ( var ( LogoutCommand = &cli.Command{ Name: "logout", - Usage: "logout ipgw", + Usage: "退出登陆", Action: func(ctx *cli.Context) error { h := handler.NewIpgwHandler() connected, loggedIn := h.IsConnectedAndLoggedIn() if !connected { - return errors.New("not in campus network") + return errors.New("未连接到校园网") } if !loggedIn { - return errors.New("not logged in yet") + return errors.New("未登陆") } info := h.GetInfo() if err := h.Logout(); err != nil { - return fmt.Errorf("fail to logout account '%s':\n\t%v", info.Username, err) + return fmt.Errorf("无法退出登陆账户 '%s':\n\t%v", info.Username, err) } - console.InfoF("logout account '%s' successfully\n", info.Username) + console.InfoF("退出登陆 '%s' 成功\n", info.Username) return nil }, OnUsageError: onUsageError, diff --git a/pkg/cmd/test.go b/pkg/cmd/test.go index a738f9c..e20400b 100644 --- a/pkg/cmd/test.go +++ b/pkg/cmd/test.go @@ -9,21 +9,21 @@ import ( var ( TestCommand = &cli.Command{ Name: "test", - Usage: "test whether is connected to the campus network and whether has logged in ipgw", + Usage: "测试是否连接校园网以及登陆网关", Action: func(ctx *cli.Context) error { h := handler.NewIpgwHandler() connected, loggedIn := h.IsConnectedAndLoggedIn() - console.Info("campus network: ") + console.Info("校园网: ") if connected { - console.InfoL("connected") + console.InfoL("已连接") } else { - console.InfoL("disconnected") + console.InfoL("未连接") } - console.Info("ipgw logged in: ") + console.Info("网关已登陆: ") if loggedIn { - console.InfoL("yes") + console.InfoL("是") } else { - console.InfoL("no") + console.InfoL("否") } return nil }, diff --git a/pkg/cmd/update.go b/pkg/cmd/update.go index 84a1324..97662f7 100644 --- a/pkg/cmd/update.go +++ b/pkg/cmd/update.go @@ -10,7 +10,7 @@ import ( var ( UpdateCommand = &cli.Command{ Name: "update", - Usage: "check latest version of ipgw and update", + Usage: "检查程序版本", Action: func(ctx *cli.Context) error { h := handler.NewUpdateHandler() newer, err := h.CheckLatestVersion() @@ -18,14 +18,14 @@ var ( return err } if !newer { - console.InfoL("already the latest version") + console.InfoL("已是最新版本") return nil } err = h.Update() if err != nil { - return fmt.Errorf("fail to update:\n\t%v", err) + return fmt.Errorf("无法更新:\n\t%v", err) } - console.InfoL("update successfully") + console.InfoL("更新成功") return nil }, } diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index e07f2ef..5094225 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -9,7 +9,7 @@ import ( var ( VersionCommand = &cli.Command{ Name: "version", - Usage: "show version and build info", + Usage: "显示版本及构建信息", Action: func(ctx *cli.Context) error { console.InfoF("ipgw %s+%s\n", ipgw.Version, ipgw.Build) return nil diff --git a/pkg/handler/dashboard.go b/pkg/handler/dashboard.go index e36f94a..7621cd7 100644 --- a/pkg/handler/dashboard.go +++ b/pkg/handler/dashboard.go @@ -117,7 +117,7 @@ func (d *DashboardHandler) GetPackage() (*Package, error) { infos, _ := utils.MatchMultiple(regexp.MustCompile(`(.+?)(.+?)(.+?)(.+?)`), body) if len(infos) < 1 { - return nil, errors.New("fail to get package info") + return nil, errors.New("无法获取包信息") } info := infos[0] @@ -171,7 +171,7 @@ func (d *DashboardHandler) GetBill(page int) ([]BillRecord, error) { } t, _ := utils.MatchSingle(regexp.MustCompile(`(.+?)`), body) if t != "结算清单" { - return []BillRecord{}, errors.New("error occurs when parsing bill page") + return []BillRecord{}, errors.New("获取结算清单时发生错误") } bills, _ := utils.MatchMultiple(regexp.MustCompile(`(\d+).+?(.+?)(.+?).+?(.+?)(\d+)(.+?)`), body) @@ -204,7 +204,7 @@ func (d *DashboardHandler) GetUsageRecords(page int) ([]UsageRecord, error) { } t, _ := utils.MatchSingle(regexp.MustCompile(`(.+?)`), body) if t != "上网明细" { - return []UsageRecord{}, errors.New("error occurs when parsing usage log page") + return []UsageRecord{}, errors.New("获取上网明细时发生错误") } hs, _ := utils.MatchMultiple(regexp.MustCompile(`(.+?)(.+?)(.+?).+?.+?.+?(.+?).+?(.+?).+?`), body) @@ -228,7 +228,7 @@ func (d *DashboardHandler) GetRecharge(page int) ([]RechargeRecord, error) { } t, _ := utils.MatchSingle(regexp.MustCompile(`(.+?)`), body) if t != "缴费清单" { - return []RechargeRecord{}, errors.New("error occurs when parsing recharge page") + return []RechargeRecord{}, errors.New("获取缴费清单时发生错误") } rs, _ := utils.MatchMultiple(regexp.MustCompile(`(.+?)\d+(.+?).+?(.+?)`), body) diff --git a/pkg/handler/ipgw.go b/pkg/handler/ipgw.go index 0ce9cfd..c6e6639 100644 --- a/pkg/handler/ipgw.go +++ b/pkg/handler/ipgw.go @@ -62,7 +62,7 @@ func (h *IpgwHandler) Login(account *model.Account) error { } if strings.Contains(body, "Arrearage users") { - return fmt.Errorf("overdue") + return fmt.Errorf("已欠费") } return h.ParseBasicInfo() // 解析信息 diff --git a/pkg/handler/store.go b/pkg/handler/store.go index 3dddf50..9522cec 100644 --- a/pkg/handler/store.go +++ b/pkg/handler/store.go @@ -16,7 +16,7 @@ type StoreHandler struct { func NewStoreHandler(path string) (*StoreHandler, error) { path, err := getConfigPath(path) if err != nil { - return nil, fmt.Errorf("fail to open config:\n\t%s", err) + return nil, fmt.Errorf("无法打开配置文件:\n\t%s", err) } return &StoreHandler{ Path: path, @@ -27,7 +27,7 @@ func getConfigPath(path string) (string, error) { if path == "" { homeDir, err := utils.GetHomeDir() if err != nil { - return "", fmt.Errorf("fail to get home dir %v", err) + return "", fmt.Errorf("无法获得安装目录 %v", err) } path = homeDir + string(os.PathSeparator) + ".ipgw" } @@ -40,7 +40,7 @@ func getConfigPath(path string) (string, error) { func (h *StoreHandler) Persist() error { content, err := json.Marshal(h.Config) if err != nil { - return fmt.Errorf("fail to save config:\n\t%v", err) + return fmt.Errorf("无法保存配置:\n\t%v", err) } return os.WriteFile(h.Path, content, 0666) } @@ -48,12 +48,12 @@ func (h *StoreHandler) Persist() error { func (h *StoreHandler) Load() error { content, err := os.ReadFile(h.Path) if err != nil { - return fmt.Errorf("fail to load config:\n\t%v", err) + return fmt.Errorf("无法加载配置:\n\t%v", err) } h.Config = &model.Config{} err = json.Unmarshal(content, &h.Config) if err == nil || err.Error() == "unexpected end of JSON input" { return nil } - return fmt.Errorf("fail to save config:\n\t%v", err) + return fmt.Errorf("无法保存配置:\n\t%v", err) } diff --git a/pkg/handler/update.go b/pkg/handler/update.go index 1a4ab2f..0b49219 100644 --- a/pkg/handler/update.go +++ b/pkg/handler/update.go @@ -28,7 +28,7 @@ type UpdateHandler struct { func (d *downloader) Read(p []byte) (n int, err error) { n, err = d.Reader.Read(p) d.current += int64(n) - console.InfoF("\rdownloading %.2f%%", float64(d.current*10000/d.total)/100) + console.InfoF("\r下载中 %.2f%%", float64(d.current*10000/d.total)/100) return } @@ -42,7 +42,7 @@ func NewUpdateHandler() *UpdateHandler { func (u *UpdateHandler) CheckLatestVersion() (bool, error) { resp, err := u.client.Get(fmt.Sprintf("https://api.github.com/repos/%s/releases/latest", ipgw.Repo)) if err != nil { - return false, fmt.Errorf("fail to check latest version:\n\t%v", err) + return false, fmt.Errorf("无法检查最新版本:\n\t%v", err) } body := utils.ReadBody(resp) latestVersion, _ := utils.MatchSingle(regexp.MustCompile(`"tag_name": *"(.+?)"`), body) @@ -57,7 +57,7 @@ func (u *UpdateHandler) download(url string) (string, error) { } // not found if resp.StatusCode == http.StatusNotFound { - return "", errors.New("release not found") + return "", errors.New("未找到发布版本") } raw := resp.Body defer raw.Close() diff --git a/pkg/model/account.go b/pkg/model/account.go index 72de0cf..5560043 100644 --- a/pkg/model/account.go +++ b/pkg/model/account.go @@ -19,7 +19,7 @@ func (a *Account) GetPassword() (string, error) { return a.Password, nil } if a.EncryptedPassword == "" { - return "", errors.New("no password stored") + return "", errors.New("未储存密码") } result, err := utils.Decrypt(a.EncryptedPassword, []byte(a.Secret)) if err != nil { diff --git a/pkg/utils/encrypt.go b/pkg/utils/encrypt.go index 91bdb28..633fec0 100644 --- a/pkg/utils/encrypt.go +++ b/pkg/utils/encrypt.go @@ -27,7 +27,7 @@ func DESEncrypt(source []byte, secret []byte) ([]byte, error) { func DESDecrypt(encrypted []byte, secret []byte) (result []byte, err error) { defer func() { if e := recover(); e != nil { - err = errors.New("wrong secret") + err = errors.New("密保问题错误") } }() key := sha(secret) diff --git a/pkg/utils/file.go b/pkg/utils/file.go index 9947343..73f44f2 100644 --- a/pkg/utils/file.go +++ b/pkg/utils/file.go @@ -39,7 +39,7 @@ func homeUnix() (string, error) { result := strings.TrimSpace(stdout.String()) if result == "" { - return "", errors.New("blank output when reading home directory") + return "", errors.New("读取主目录时输出为空") } return result, nil @@ -53,7 +53,7 @@ func homeWindows() (string, error) { home = os.Getenv("USERPROFILE") } if home == "" { - return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank") + return "", errors.New("HOMEDRIVE, HOMEPATH, 和 USERPROFILE 为空") } return home, nil @@ -74,7 +74,7 @@ func IsFileExist(path string) bool { func GetExecutablePathAndDir() (path, dir string, err error) { p, err := os.Executable() if err != nil { - return "", "", fmt.Errorf("fail to get executable path: %v", err) + return "", "", fmt.Errorf("无法获取可执行路径: %v", err) } path, _ = filepath.Abs(p) dir = filepath.Dir(path) diff --git a/pkg/utils/string.go b/pkg/utils/string.go index aa35f82..7d2db18 100644 --- a/pkg/utils/string.go +++ b/pkg/utils/string.go @@ -7,7 +7,7 @@ import ( "regexp" ) -var errorNoMatched = errors.New("no matched") +var errorNoMatched = errors.New("未匹配到") func MatchMultiple(re *regexp.Regexp, content string) ([][]string, error) { matched := re.FindAllStringSubmatch(content, -1) diff --git a/scripts/release.sh b/scripts/release.sh index f85167d..ddbd69c 100644 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -4,15 +4,15 @@ name=$1 targets_dir="$PWD/$2" release_dir="$PWD/$3" -echo "start: zip all targets in $targets_dir to $release_dir." +echo "start: 解压 $targets_dir 到 $release_dir." mkdir -p "$release_dir" cd "$targets_dir" || exit targets=$(ls "$targets_dir") for target in $targets do - echo "zipping $target..." + echo "解压中 $target..." cd "$target" && zip -q "$name-$target.zip" ./* && mv "$name-$target.zip" "$release_dir" && cd .. done -echo "done." \ No newline at end of file +echo "解压完成。" \ No newline at end of file