diff options
author | Unknwon <u@gogs.io> | 2017-04-05 09:05:40 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-04-05 09:05:40 -0400 |
commit | 6fbb984ebf4f0d6804f0f83e6edb12ef0bb9a570 (patch) | |
tree | 81f08210cb3553370795ec11c731d37bb3590122 /routers | |
parent | ba151eda0a8b6eec2cb45f01fcbc8aef7ad5a06f (diff) |
Refactoring: rename pkg/base -> pkg/tool
Diffstat (limited to 'routers')
30 files changed, 165 insertions, 166 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go index cd1f438e..91b562ad 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -15,7 +15,7 @@ import ( "gopkg.in/macaron.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/cron" "github.com/gogits/gogs/pkg/mailer" @@ -24,9 +24,9 @@ import ( ) const ( - DASHBOARD base.TplName = "admin/dashboard" - CONFIG base.TplName = "admin/config" - MONITOR base.TplName = "admin/monitor" + DASHBOARD tool.TplName = "admin/dashboard" + CONFIG tool.TplName = "admin/config" + MONITOR tool.TplName = "admin/monitor" ) var ( @@ -75,37 +75,37 @@ var sysStatus struct { } func updateSystemStatus() { - sysStatus.Uptime = base.TimeSincePro(startTime) + sysStatus.Uptime = tool.TimeSincePro(startTime) m := new(runtime.MemStats) runtime.ReadMemStats(m) sysStatus.NumGoroutine = runtime.NumGoroutine() - sysStatus.MemAllocated = base.FileSize(int64(m.Alloc)) - sysStatus.MemTotal = base.FileSize(int64(m.TotalAlloc)) - sysStatus.MemSys = base.FileSize(int64(m.Sys)) + sysStatus.MemAllocated = tool.FileSize(int64(m.Alloc)) + sysStatus.MemTotal = tool.FileSize(int64(m.TotalAlloc)) + sysStatus.MemSys = tool.FileSize(int64(m.Sys)) sysStatus.Lookups = m.Lookups sysStatus.MemMallocs = m.Mallocs sysStatus.MemFrees = m.Frees - sysStatus.HeapAlloc = base.FileSize(int64(m.HeapAlloc)) - sysStatus.HeapSys = base.FileSize(int64(m.HeapSys)) - sysStatus.HeapIdle = base.FileSize(int64(m.HeapIdle)) - sysStatus.HeapInuse = base.FileSize(int64(m.HeapInuse)) - sysStatus.HeapReleased = base.FileSize(int64(m.HeapReleased)) + sysStatus.HeapAlloc = tool.FileSize(int64(m.HeapAlloc)) + sysStatus.HeapSys = tool.FileSize(int64(m.HeapSys)) + sysStatus.HeapIdle = tool.FileSize(int64(m.HeapIdle)) + sysStatus.HeapInuse = tool.FileSize(int64(m.HeapInuse)) + sysStatus.HeapReleased = tool.FileSize(int64(m.HeapReleased)) sysStatus.HeapObjects = m.HeapObjects - sysStatus.StackInuse = base.FileSize(int64(m.StackInuse)) - sysStatus.StackSys = base.FileSize(int64(m.StackSys)) - sysStatus.MSpanInuse = base.FileSize(int64(m.MSpanInuse)) - sysStatus.MSpanSys = base.FileSize(int64(m.MSpanSys)) - sysStatus.MCacheInuse = base.FileSize(int64(m.MCacheInuse)) - sysStatus.MCacheSys = base.FileSize(int64(m.MCacheSys)) - sysStatus.BuckHashSys = base.FileSize(int64(m.BuckHashSys)) - sysStatus.GCSys = base.FileSize(int64(m.GCSys)) - sysStatus.OtherSys = base.FileSize(int64(m.OtherSys)) - - sysStatus.NextGC = base.FileSize(int64(m.NextGC)) + sysStatus.StackInuse = tool.FileSize(int64(m.StackInuse)) + sysStatus.StackSys = tool.FileSize(int64(m.StackSys)) + sysStatus.MSpanInuse = tool.FileSize(int64(m.MSpanInuse)) + sysStatus.MSpanSys = tool.FileSize(int64(m.MSpanSys)) + sysStatus.MCacheInuse = tool.FileSize(int64(m.MCacheInuse)) + sysStatus.MCacheSys = tool.FileSize(int64(m.MCacheSys)) + sysStatus.BuckHashSys = tool.FileSize(int64(m.BuckHashSys)) + sysStatus.GCSys = tool.FileSize(int64(m.GCSys)) + sysStatus.OtherSys = tool.FileSize(int64(m.OtherSys)) + + sysStatus.NextGC = tool.FileSize(int64(m.NextGC)) sysStatus.LastGC = fmt.Sprintf("%.1fs", float64(time.Now().UnixNano()-int64(m.LastGC))/1000/1000/1000) sysStatus.PauseTotalNs = fmt.Sprintf("%.1fs", float64(m.PauseTotalNs)/1000/1000/1000) sysStatus.PauseNs = fmt.Sprintf("%.3fs", float64(m.PauseNs[(m.NumGC+255)%256])/1000/1000/1000) diff --git a/routers/admin/auths.go b/routers/admin/auths.go index 255c13b1..1aba22a2 100644 --- a/routers/admin/auths.go +++ b/routers/admin/auths.go @@ -13,16 +13,16 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/pkg/auth/ldap" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" ) const ( - AUTHS base.TplName = "admin/auth/list" - AUTH_NEW base.TplName = "admin/auth/new" - AUTH_EDIT base.TplName = "admin/auth/edit" + AUTHS tool.TplName = "admin/auth/list" + AUTH_NEW tool.TplName = "admin/auth/new" + AUTH_EDIT tool.TplName = "admin/auth/edit" ) func Authentications(ctx *context.Context) { diff --git a/routers/admin/notice.go b/routers/admin/notice.go index 2fb04ffc..47ca135d 100644 --- a/routers/admin/notice.go +++ b/routers/admin/notice.go @@ -10,13 +10,13 @@ import ( log "gopkg.in/clog.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) const ( - NOTICES base.TplName = "admin/notice" + NOTICES tool.TplName = "admin/notice" ) func Notices(ctx *context.Context) { diff --git a/routers/admin/orgs.go b/routers/admin/orgs.go index 0150f33c..62c03d9a 100644 --- a/routers/admin/orgs.go +++ b/routers/admin/orgs.go @@ -6,14 +6,14 @@ package admin import ( "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/routers" ) const ( - ORGS base.TplName = "admin/org/list" + ORGS tool.TplName = "admin/org/list" ) func Organizations(ctx *context.Context) { diff --git a/routers/admin/repos.go b/routers/admin/repos.go index 0eefbade..7b4a9c6f 100644 --- a/routers/admin/repos.go +++ b/routers/admin/repos.go @@ -9,13 +9,13 @@ import ( log "gopkg.in/clog.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) const ( - REPOS base.TplName = "admin/repo/list" + REPOS tool.TplName = "admin/repo/list" ) func Repos(ctx *context.Context) { diff --git a/routers/admin/users.go b/routers/admin/users.go index 0cb72000..5bcca776 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -11,7 +11,7 @@ import ( log "gopkg.in/clog.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/mailer" @@ -20,9 +20,9 @@ import ( ) const ( - USERS base.TplName = "admin/user/list" - USER_NEW base.TplName = "admin/user/new" - USER_EDIT base.TplName = "admin/user/edit" + USERS tool.TplName = "admin/user/list" + USER_NEW tool.TplName = "admin/user/new" + USER_EDIT tool.TplName = "admin/user/edit" ) func Users(ctx *context.Context) { diff --git a/routers/dev/template.go b/routers/dev/template.go index 081ab4a0..bc2bb8d2 100644 --- a/routers/dev/template.go +++ b/routers/dev/template.go @@ -6,7 +6,7 @@ package dev import ( "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) @@ -21,5 +21,5 @@ func TemplatePreview(ctx *context.Context) { ctx.Data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60 ctx.Data["CurDbValue"] = "" - ctx.HTML(200, base.TplName(ctx.Params("*"))) + ctx.HTML(200, tool.TplName(ctx.Params("*"))) } diff --git a/routers/home.go b/routers/home.go index cb59850a..cbd0070a 100644 --- a/routers/home.go +++ b/routers/home.go @@ -8,17 +8,17 @@ import ( "github.com/Unknwon/paginater" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/routers/user" ) const ( - HOME base.TplName = "home" - EXPLORE_REPOS base.TplName = "explore/repos" - EXPLORE_USERS base.TplName = "explore/users" - EXPLORE_ORGANIZATIONS base.TplName = "explore/organizations" + HOME tool.TplName = "home" + EXPLORE_REPOS tool.TplName = "explore/repos" + EXPLORE_USERS tool.TplName = "explore/users" + EXPLORE_ORGANIZATIONS tool.TplName = "explore/organizations" ) func Home(ctx *context.Context) { @@ -84,7 +84,7 @@ type UserSearchOptions struct { Ranger func(int, int) ([]*models.User, error) PageSize int OrderBy string - TplName base.TplName + TplName tool.TplName } func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { diff --git a/routers/install.go b/routers/install.go index eb17f900..9e2bf784 100644 --- a/routers/install.go +++ b/routers/install.go @@ -21,7 +21,7 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/cron" "github.com/gogits/gogs/pkg/form" @@ -34,7 +34,7 @@ import ( ) const ( - INSTALL base.TplName = "install" + INSTALL tool.TplName = "install" ) func checkRunMode() { @@ -344,7 +344,7 @@ func InstallPost(ctx *context.Context, f form.Install) { cfg.Section("log").Key("ROOT_PATH").SetValue(f.LogRootPath) cfg.Section("security").Key("INSTALL_LOCK").SetValue("true") - secretKey, err := base.GetRandomString(15) + secretKey, err := tool.GetRandomString(15) if err != nil { ctx.RenderWithErr(ctx.Tr("install.secret_key_failed", err), INSTALL, &f) return diff --git a/routers/org/members.go b/routers/org/members.go index edc0c76c..87686231 100644 --- a/routers/org/members.go +++ b/routers/org/members.go @@ -10,14 +10,14 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) const ( - MEMBERS base.TplName = "org/member/members" - MEMBER_INVITE base.TplName = "org/member/invite" + MEMBERS tool.TplName = "org/member/members" + MEMBER_INVITE tool.TplName = "org/member/invite" ) func Members(ctx *context.Context) { diff --git a/routers/org/org.go b/routers/org/org.go index 07249db5..bedb3839 100644 --- a/routers/org/org.go +++ b/routers/org/org.go @@ -9,13 +9,13 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/pkg/form" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) const ( - CREATE base.TplName = "org/create" + CREATE tool.TplName = "org/create" ) func Create(ctx *context.Context) { diff --git a/routers/org/setting.go b/routers/org/setting.go index 9a5331f4..966d5afe 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -11,7 +11,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" @@ -19,9 +19,9 @@ import ( ) const ( - SETTINGS_OPTIONS base.TplName = "org/settings/options" - SETTINGS_DELETE base.TplName = "org/settings/delete" - SETTINGS_WEBHOOKS base.TplName = "org/settings/webhooks" + SETTINGS_OPTIONS tool.TplName = "org/settings/options" + SETTINGS_DELETE tool.TplName = "org/settings/delete" + SETTINGS_WEBHOOKS tool.TplName = "org/settings/webhooks" ) func Settings(ctx *context.Context) { diff --git a/routers/org/teams.go b/routers/org/teams.go index ba40c6d4..54e2fe72 100644 --- a/routers/org/teams.go +++ b/routers/org/teams.go @@ -12,16 +12,16 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" ) const ( - TEAMS base.TplName = "org/team/teams" - TEAM_NEW base.TplName = "org/team/new" - TEAM_MEMBERS base.TplName = "org/team/members" - TEAM_REPOSITORIES base.TplName = "org/team/repositories" + TEAMS tool.TplName = "org/team/teams" + TEAM_NEW tool.TplName = "org/team/new" + TEAM_MEMBERS tool.TplName = "org/team/members" + TEAM_REPOSITORIES tool.TplName = "org/team/repositories" ) func Teams(ctx *context.Context) { diff --git a/routers/repo/branch.go b/routers/repo/branch.go index 786dc068..12b62507 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -12,13 +12,13 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" ) const ( - BRANCHES_OVERVIEW base.TplName = "repo/branches/overview" - BRANCHES_ALL base.TplName = "repo/branches/all" + BRANCHES_OVERVIEW tool.TplName = "repo/branches/overview" + BRANCHES_ALL tool.TplName = "repo/branches/all" ) type Branch struct { diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 2b5fc86f..e51e81c8 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -11,14 +11,14 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) const ( - COMMITS base.TplName = "repo/commits" - DIFF base.TplName = "repo/diff/page" + COMMITS tool.TplName = "repo/commits" + DIFF tool.TplName = "repo/diff/page" ) func RefCommits(ctx *context.Context) { @@ -165,7 +165,7 @@ func Diff(ctx *context.Context) { ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["IsImageFile"] = commit.IsImageFile - ctx.Data["Title"] = commit.Summary() + " · " + base.ShortSha(commitID) + ctx.Data["Title"] = commit.Summary() + " · " + tool.ShortSha(commitID) ctx.Data["Commit"] = commit ctx.Data["Author"] = models.ValidateCommitWithEmail(commit) ctx.Data["Diff"] = diff @@ -228,7 +228,7 @@ func CompareDiff(ctx *context.Context) { ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["IsImageFile"] = commit.IsImageFile - ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + "..." + base.ShortSha(afterCommitID) + " · " + userName + "/" + repoName + ctx.Data["Title"] = "Comparing " + tool.ShortSha(beforeCommitID) + "..." + tool.ShortSha(afterCommitID) + " · " + userName + "/" + repoName ctx.Data["Commit"] = commit ctx.Data["Diff"] = diff ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 diff --git a/routers/repo/download.go b/routers/repo/download.go index 95a0224e..a1ad3eff 100644 --- a/routers/repo/download.go +++ b/routers/repo/download.go @@ -10,7 +10,7 @@ import ( "github.com/gogits/git-module" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) @@ -22,8 +22,8 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error { buf = buf[:n] } - if !base.IsTextFile(buf) { - if !base.IsImageFile(buf) { + if !tool.IsTextFile(buf) { + if !tool.IsImageFile(buf) { ctx.Resp.Header().Set("Content-Disposition", "attachment; filename=\""+name+"\"") ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary") } diff --git a/routers/repo/editor.go b/routers/repo/editor.go index 9bbee51c..710e70df 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -15,7 +15,7 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" @@ -23,10 +23,10 @@ import ( ) const ( - EDIT_FILE base.TplName = "repo/editor/edit" - EDIT_DIFF_PREVIEW base.TplName = "repo/editor/diff_preview" - DELETE_FILE base.TplName = "repo/editor/delete" - UPLOAD_FILE base.TplName = "repo/editor/upload" + EDIT_FILE tool.TplName = "repo/editor/edit" + EDIT_DIFF_PREVIEW tool.TplName = "repo/editor/diff_preview" + DELETE_FILE tool.TplName = "repo/editor/delete" + UPLOAD_FILE tool.TplName = "repo/editor/upload" ) // getParentTreeFields returns list of parent tree names and corresponding tree paths @@ -80,7 +80,7 @@ func editFile(ctx *context.Context, isNewFile bool) { buf = buf[:n] // Only text file are editable online. - if !base.IsTextFile(buf) { + if !tool.IsTextFile(buf) { ctx.Handle(404, "", nil) return } diff --git a/routers/repo/http.go b/routers/repo/http.go index b3b6aa1a..f90d1ce0 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -23,7 +23,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) @@ -106,7 +106,7 @@ func HTTPContexter() macaron.Handler { askCredentials(c, http.StatusUnauthorized, "") return } - authUsername, authPassword, err := base.BasicAuthDecode(auths[1]) + authUsername, authPassword, err := tool.BasicAuthDecode(auths[1]) if err != nil { askCredentials(c, http.StatusUnauthorized, "") return @@ -229,7 +229,7 @@ func ComposeHookEnvs(opts ComposeHookEnvsOptions) []string { ENV_AUTH_USER_NAME + "=" + opts.AuthUser.Name, ENV_AUTH_USER_EMAIL + "=" + opts.AuthUser.Email, ENV_REPO_OWNER_NAME + "=" + opts.OwnerName, - ENV_REPO_OWNER_SALT_MD5 + "=" + base.EncodeMD5(opts.OwnerSalt), + ENV_REPO_OWNER_SALT_MD5 + "=" + tool.EncodeMD5(opts.OwnerSalt), ENV_REPO_ID + "=" + com.ToStr(opts.RepoID), ENV_REPO_NAME + "=" + opts.RepoName, ENV_REPO_CUSTOM_HOOKS_PATH + "=" + path.Join(opts.RepoPath, "custom_hooks"), diff --git a/routers/repo/issue.go b/routers/repo/issue.go index f7dc4b1b..74501477 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -19,7 +19,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/markup" @@ -27,15 +27,15 @@ import ( ) const ( - ISSUES base.TplName = "repo/issue/list" - ISSUE_NEW base.TplName = "repo/issue/new" - ISSUE_VIEW base.TplName = "repo/issue/view" + ISSUES tool.TplName = "repo/issue/list" + ISSUE_NEW tool.TplName = "repo/issue/new" + ISSUE_VIEW tool.TplName = "repo/issue/view" - LABELS base.TplName = "repo/issue/labels" + LABELS tool.TplName = "repo/issue/labels" - MILESTONE base.TplName = "repo/issue/milestones" - MILESTONE_NEW base.TplName = "repo/issue/milestone_new" - MILESTONE_EDIT base.TplName = "repo/issue/milestone_edit" + MILESTONE tool.TplName = "repo/issue/milestones" + MILESTONE_NEW tool.TplName = "repo/issue/milestone_new" + MILESTONE_EDIT tool.TplName = "repo/issue/milestone_edit" ISSUE_TEMPLATE_KEY = "IssueTemplate" ) @@ -371,8 +371,8 @@ func ValidateRepoMetas(ctx *context.Context, f form.NewIssue) ([]int64, int64, i } // Check labels. - labelIDs := base.StringsToInt64s(strings.Split(f.LabelIDs, ",")) - labelIDMark := base.Int64sToMap(labelIDs) + labelIDs := tool.StringsToInt64s(strings.Split(f.LabelIDs, ",")) + labelIDMark := tool.Int64sToMap(labelIDs) hasSelected := false for i := range labels { if labelIDMark[labels[i].ID] { diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 987e703c..fc1a3817 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -16,17 +16,17 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" ) const ( - FORK base.TplName = "repo/pulls/fork" - COMPARE_PULL base.TplName = "repo/pulls/compare" - PULL_COMMITS base.TplName = "repo/pulls/commits" - PULL_FILES base.TplName = "repo/pulls/files" + FORK tool.TplName = "repo/pulls/fork" + COMPARE_PULL tool.TplName = "repo/pulls/compare" + PULL_COMMITS tool.TplName = "repo/pulls/commits" + PULL_FILES tool.TplName = "repo/pulls/files" PULL_REQUEST_TEMPLATE_KEY = "PullRequestTemplate" ) @@ -738,7 +738,7 @@ func TriggerTask(ctx *context.Context) { if ctx.Written() { return } - if secret != base.EncodeMD5(owner.Salt) { + if secret != tool.EncodeMD5(owner.Salt) { ctx.Error(404) log.Trace("TriggerTask [%s/%s]: invalid secret", owner.Name, repo.Name) return diff --git a/routers/repo/release.go b/routers/repo/release.go index 692d7b2f..b9fe3ada 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -11,7 +11,7 @@ import ( log "gopkg.in/clog.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/markup" @@ -19,8 +19,8 @@ import ( ) const ( - RELEASES base.TplName = "repo/release/list" - RELEASE_NEW base.TplName = "repo/release/new" + RELEASES tool.TplName = "repo/release/list" + RELEASE_NEW tool.TplName = "repo/release/new" ) // calReleaseNumCommitsBehind calculates given release has how many commits behind release target. diff --git a/routers/repo/repo.go b/routers/repo/repo.go index a3e5291d..2e00a80e 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -17,15 +17,15 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" ) const ( - CREATE base.TplName = "repo/create" - MIGRATE base.TplName = "repo/migrate" + CREATE tool.TplName = "repo/create" + MIGRATE tool.TplName = "repo/migrate" ) func MustBeNotBare(ctx *context.Context) { @@ -85,7 +85,7 @@ func Create(ctx *context.Context) { ctx.HTML(200, CREATE) } -func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) { +func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl tool.TplName, form interface{}) { switch { case models.IsErrReachLimitOfRepo(err): ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.RepoCreationNum()), tpl, form) @@ -323,7 +323,7 @@ func Download(ctx *context.Context) { return } - archivePath = path.Join(archivePath, base.ShortSha(commit.ID.String())+ext) + archivePath = path.Join(archivePath, tool.ShortSha(commit.ID.String())+ext) if !com.IsFile(archivePath) { if err := commit.CreateArchive(archivePath, archiveType); err != nil { ctx.Handle(500, "Download -> CreateArchive "+archivePath, err) diff --git a/routers/repo/setting.go b/routers/repo/setting.go index de255334..70533118 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -15,7 +15,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/mailer" @@ -23,13 +23,13 @@ import ( ) const ( - SETTINGS_OPTIONS base.TplName = "repo/settings/options" - SETTINGS_COLLABORATION base.TplName = "repo/settings/collaboration" - SETTINGS_BRANCHES base.TplName = "repo/settings/branches" - SETTINGS_PROTECTED_BRANCH base.TplName = "repo/settings/protected_branch" - SETTINGS_GITHOOKS base.TplName = "repo/settings/githooks" - SETTINGS_GITHOOK_EDIT base.TplName = "repo/settings/githook_edit" - SETTINGS_DEPLOY_KEYS base.TplName = "repo/settings/deploy_keys" + SETTINGS_OPTIONS tool.TplName = "repo/settings/options" + SETTINGS_COLLABORATION tool.TplName = "repo/settings/collaboration" + SETTINGS_BRANCHES tool.TplName = "repo/settings/branches" + SETTINGS_PROTECTED_BRANCH tool.TplName = "repo/settings/protected_branch" + SETTINGS_GITHOOKS tool.TplName = "repo/settings/githooks" + SETTINGS_GITHOOK_EDIT tool.TplName = "repo/settings/githook_edit" + SETTINGS_DEPLOY_KEYS tool.TplName = "repo/settings/deploy_keys" ) func Settings(ctx *context.Context) { diff --git a/routers/repo/view.go b/routers/repo/view.go index abfe9333..1559b984 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -18,7 +18,7 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/markup" "github.com/gogits/gogs/pkg/setting" @@ -27,10 +27,10 @@ import ( ) const ( - BARE base.TplName = "repo/bare" - HOME base.TplName = "repo/home" - WATCHERS base.TplName = "repo/watchers" - FORKS base.TplName = "repo/forks" + BARE tool.TplName = "repo/bare" + HOME tool.TplName = "repo/home" + WATCHERS tool.TplName = "repo/watchers" + FORKS tool.TplName = "repo/forks" ) func renderDirectory(ctx *context.Context, treeLink string) { @@ -79,7 +79,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { n, _ := dataRc.Read(buf) buf = buf[:n] - isTextFile := base.IsTextFile(buf) + isTextFile := tool.IsTextFile(buf) ctx.Data["IsTextFile"] = isTextFile ctx.Data["FileName"] = readmeFile.Name() if isTextFile { @@ -134,7 +134,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st n, _ := dataRc.Read(buf) buf = buf[:n] - isTextFile := base.IsTextFile(buf) + isTextFile := tool.IsTextFile(buf) ctx.Data["IsTextFile"] = isTextFile // Assume file is not editable first. @@ -196,11 +196,11 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit") } - case base.IsPDFFile(buf): + case tool.IsPDFFile(buf): ctx.Data["IsPDFFile"] = true - case base.IsVideoFile(buf): + case tool.IsVideoFile(buf): ctx.Data["IsVideoFile"] = true - case base.IsImageFile(buf): + case tool.IsImageFile(buf): ctx.Data["IsImageFile"] = true } @@ -304,7 +304,7 @@ func Home(ctx *context.Context) { ctx.HTML(200, HOME) } -func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]*models.User, error), tpl base.TplName) { +func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]*models.User, error), tpl tool.TplName) { page := ctx.QueryInt("page") if page <= 0 { page = 1 diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go index aa76de2d..d41ffa09 100644 --- a/routers/repo/webhook.go +++ b/routers/repo/webhook.go @@ -16,16 +16,16 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" ) const ( - WEBHOOKS base.TplName = "repo/settings/webhook/base" - WEBHOOK_NEW base.TplName = "repo/settings/webhook/new" - ORG_WEBHOOK_NEW base.TplName = "org/settings/webhook_new" + WEBHOOKS tool.TplName = "repo/settings/webhook/base" + WEBHOOK_NEW tool.TplName = "repo/settings/webhook/new" + ORG_WEBHOOK_NEW tool.TplName = "org/settings/webhook_new" ) func Webhooks(ctx *context.Context) { @@ -49,7 +49,7 @@ type OrgRepoCtx struct { OrgID int64 RepoID int64 Link string - NewTemplate base.TplName + NewTemplate tool.TplName } // getOrgRepoCtx determines whether this is a repo context or organization context. diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index 643ad7b5..fbaccfe5 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -12,17 +12,17 @@ import ( "github.com/gogits/git-module" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/markup" ) const ( - WIKI_START base.TplName = "repo/wiki/start" - WIKI_VIEW base.TplName = "repo/wiki/view" - WIKI_NEW base.TplName = "repo/wiki/new" - WIKI_PAGES base.TplName = "repo/wiki/pages" + WIKI_START tool.TplName = "repo/wiki/start" + WIKI_VIEW tool.TplName = "repo/wiki/view" + WIKI_NEW tool.TplName = "repo/wiki/new" + WIKI_PAGES tool.TplName = "repo/wiki/pages" ) func MustEnableWiki(ctx *context.Context) { diff --git a/routers/user/auth.go b/routers/user/auth.go index 35e73742..7290da75 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -13,7 +13,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/mailer" @@ -21,11 +21,11 @@ import ( ) const ( - SIGNIN base.TplName = "user/auth/signin" - SIGNUP base.TplName = "user/auth/signup" - ACTIVATE base.TplName = "user/auth/activate" - FORGOT_PASSWORD base.TplName = "user/auth/forgot_passwd" - RESET_PASSWORD base.TplName = "user/auth/reset_passwd" + SIGNIN tool.TplName = "user/auth/signin" + SIGNUP tool.TplName = "user/auth/signup" + ACTIVATE tool.TplName = "user/auth/activate" + FORGOT_PASSWORD tool.TplName = "user/auth/forgot_passwd" + RESET_PASSWORD tool.TplName = "user/auth/reset_passwd" ) // AutoSignIn reads cookie and try to auto-login. diff --git a/routers/user/home.go b/routers/user/home.go index b85d3064..728ff5bd 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -13,17 +13,17 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" ) const ( - DASHBOARD base.TplName = "user/dashboard/dashboard" - NEWS_FEED base.TplName = "user/dashboard/feeds" - ISSUES base.TplName = "user/dashboard/issues" - PROFILE base.TplName = "user/profile" - ORG_HOME base.TplName = "org/home" + DASHBOARD tool.TplName = "user/dashboard/dashboard" + NEWS_FEED tool.TplName = "user/dashboard/feeds" + ISSUES tool.TplName = "user/dashboard/issues" + PROFILE tool.TplName = "user/profile" + ORG_HOME tool.TplName = "org/home" ) // getDashboardContextUser finds out dashboard is viewing as which context user. diff --git a/routers/user/profile.go b/routers/user/profile.go index 10c48878..6e118d03 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -13,15 +13,15 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/routers/repo" ) const ( - FOLLOWERS base.TplName = "user/meta/followers" - STARS base.TplName = "user/meta/stars" + FOLLOWERS tool.TplName = "user/meta/followers" + STARS tool.TplName = "user/meta/stars" ) func GetUserByName(ctx *context.Context, name string) *models.User { diff --git a/routers/user/setting.go b/routers/user/setting.go index 777a812e..cb427dd6 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -14,7 +14,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/context" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/mailer" @@ -22,18 +22,17 @@ import ( ) const ( - SETTINGS_PROFILE base.TplName = "user/settings/profile" - SETTINGS_AVATAR base.TplName = "user/settings/avatar" - SETTINGS_PASSWORD base.TplName = "user/settings/password" - SETTINGS_EMAILS base.TplName = "user/settings/email" - SETTINGS_SSH_KEYS base.TplName = "user/settings/sshkeys" - SETTINGS_SOCIAL base.TplName = "user/settings/social" - SETTINGS_APPLICATIONS base.TplName = "user/settings/applications" - SETTINGS_ORGANIZATIONS base.TplName = "user/settings/organizations" - SETTINGS_REPOSITORIES base.TplName = "user/settings/repositories" - SETTINGS_DELETE base.TplName = "user/settings/delete" - NOTIFICATION base.TplName = "user/notification" - SECURITY base.TplName = "user/security" + SETTINGS_PROFILE tool.TplName = "user/settings/profile" + SETTINGS_AVATAR tool.TplName = "user/settings/avatar" + SETTINGS_PASSWORD tool.TplName = "user/settings/password" + SETTINGS_EMAILS tool.TplName = "user/settings/email" + SETTINGS_SSH_KEYS tool.TplName = "user/settings/sshkeys" + SETTINGS_SECURITY tool.TplName = "user/settings/security" + SETTINGS_REPOSITORIES tool.TplName = "user/settings/repositories" + SETTINGS_ORGANIZATIONS tool.TplName = "user/settings/organizations" + SETTINGS_APPLICATIONS tool.TplName = "user/settings/applications" + SETTINGS_DELETE tool.TplName = "user/settings/delete" + NOTIFICATION tool.TplName = "user/notification" ) func Settings(c *context.Context) { @@ -116,7 +115,7 @@ func SettingsPost(ctx *context.Context, f form.UpdateProfile) { func UpdateAvatarSetting(ctx *context.Context, f form.Avatar, ctxUser *models.User) error { ctxUser.UseCustomAvatar = f.Source == form.AVATAR_LOCAL if len(f.Gravatar) > 0 { - ctxUser.Avatar = base.EncodeMD5(f.Gravatar) + ctxUser.Avatar = tool.EncodeMD5(f.Gravatar) ctxUser.AvatarEmail = f.Gravatar } @@ -131,7 +130,7 @@ func UpdateAvatarSetting(ctx *context.Context, f form.Avatar, ctxUser *models.Us if err != nil { return fmt.Errorf("ioutil.ReadAll: %v", err) } - if !base.IsImageFile(data) { + if !tool.IsImageFile(data) { return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image")) } if err = ctxUser.UploadAvatar(data); err != nil { |