From 6fbb984ebf4f0d6804f0f83e6edb12ef0bb9a570 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 5 Apr 2017 09:05:40 -0400 Subject: [PATCH] Refactoring: rename pkg/base -> pkg/tool --- models/action.go | 10 +++---- models/admin.go | 4 +-- models/git_diff.go | 4 +-- models/issue.go | 4 +-- models/issue_label.go | 6 ++-- models/migrations/migrations.go | 6 ++-- models/repo_branch.go | 14 ++++----- models/ssh_key.go | 4 +-- models/token.go | 4 +-- models/user.go | 32 ++++++++++---------- pkg/auth/auth.go | 4 +-- pkg/context/api.go | 4 +-- pkg/context/context.go | 10 +++---- pkg/mailer/mail.go | 20 ++++++------- pkg/markup/markdown.go | 4 +-- pkg/markup/markup.go | 4 +-- pkg/template/template.go | 30 +++++++++---------- pkg/{base => tool}/base.go | 2 +- pkg/{base => tool}/file.go | 2 +- pkg/{base => tool}/tool.go | 2 +- routers/admin/admin.go | 46 ++++++++++++++--------------- routers/admin/auths.go | 8 ++--- routers/admin/notice.go | 4 +-- routers/admin/orgs.go | 4 +-- routers/admin/repos.go | 4 +-- routers/admin/users.go | 8 ++--- routers/dev/template.go | 4 +-- routers/home.go | 12 ++++---- routers/install.go | 6 ++-- routers/org/members.go | 6 ++-- routers/org/org.go | 4 +-- routers/org/setting.go | 8 ++--- routers/org/teams.go | 10 +++---- routers/repo/branch.go | 6 ++-- routers/repo/commit.go | 10 +++---- routers/repo/download.go | 6 ++-- routers/repo/editor.go | 12 ++++---- routers/repo/http.go | 6 ++-- routers/repo/issue.go | 20 ++++++------- routers/repo/pull.go | 12 ++++---- routers/repo/release.go | 6 ++-- routers/repo/repo.go | 10 +++---- routers/repo/setting.go | 16 +++++----- routers/repo/view.go | 22 +++++++------- routers/repo/webhook.go | 10 +++---- routers/repo/wiki.go | 10 +++---- routers/user/auth.go | 12 ++++---- routers/user/home.go | 12 ++++---- routers/user/profile.go | 6 ++-- routers/user/setting.go | 29 +++++++++--------- templates/user/settings/navbar.tmpl | 8 ++--- 51 files changed, 253 insertions(+), 254 deletions(-) rename pkg/{base => tool}/base.go (95%) rename pkg/{base => tool}/file.go (99%) rename pkg/{base => tool}/tool.go (99%) diff --git a/models/action.go b/models/action.go index e1378e99..0ad5f287 100644 --- a/models/action.go +++ b/models/action.go @@ -21,7 +21,7 @@ import ( api "github.com/gogits/go-gogs-client" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/setting" ) @@ -108,7 +108,7 @@ func (a *Action) GetActUserName() string { } func (a *Action) ShortActUserName() string { - return base.EllipsisString(a.ActUserName, 20) + return tool.EllipsisString(a.ActUserName, 20) } func (a *Action) GetRepoUserName() string { @@ -116,7 +116,7 @@ func (a *Action) GetRepoUserName() string { } func (a *Action) ShortRepoUserName() string { - return base.EllipsisString(a.RepoUserName, 20) + return tool.EllipsisString(a.RepoUserName, 20) } func (a *Action) GetRepoName() string { @@ -124,7 +124,7 @@ func (a *Action) GetRepoName() string { } func (a *Action) ShortRepoName() string { - return base.EllipsisString(a.RepoName, 33) + return tool.EllipsisString(a.RepoName, 33) } func (a *Action) GetRepoPath() string { @@ -305,7 +305,7 @@ func (push *PushCommits) AvatarLink(email string) string { if !ok { u, err := GetUserByEmail(email) if err != nil { - push.avatars[email] = base.AvatarLink(email) + push.avatars[email] = tool.AvatarLink(email) if !errors.IsUserNotExist(err) { log.Error(4, "GetUserByEmail: %v", err) } diff --git a/models/admin.go b/models/admin.go index bad7a3bf..8816786d 100644 --- a/models/admin.go +++ b/models/admin.go @@ -15,7 +15,7 @@ import ( "github.com/go-xorm/xorm" log "gopkg.in/clog.v1" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/setting" ) @@ -128,6 +128,6 @@ func DeleteNoticesByIDs(ids []int64) error { if len(ids) == 0 { return nil } - _, err := x.Where("id IN (" + strings.Join(base.Int64sToStrings(ids), ",") + ")").Delete(new(Notice)) + _, err := x.Where("id IN (" + strings.Join(tool.Int64sToStrings(ids), ",") + ")").Delete(new(Notice)) return err } diff --git a/models/git_diff.go b/models/git_diff.go index f8282940..3a47533f 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/git-module" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/pkg/template/highlight" ) @@ -145,7 +145,7 @@ func NewDiff(gitDiff *git.Diff) *Diff { } } - charsetLabel, err := base.DetectEncoding(buf.Bytes()) + charsetLabel, err := tool.DetectEncoding(buf.Bytes()) if charsetLabel != "UTF-8" && err == nil { encoding, _ := charset.Lookup(charsetLabel) if encoding != nil { diff --git a/models/issue.go b/models/issue.go index 789165c4..cf49f173 100644 --- a/models/issue.go +++ b/models/issue.go @@ -16,7 +16,7 @@ import ( api "github.com/gogits/go-gogs-client" "github.com/gogits/gogs/models/errors" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/setting" ) @@ -1213,7 +1213,7 @@ func GetIssueStats(opts *IssueStatsOptions) *IssueStats { sess := x.Where("issue.repo_id = ?", opts.RepoID).And("is_pull = ?", opts.IsPull) if len(opts.Labels) > 0 && opts.Labels != "0" { - labelIDs := base.StringsToInt64s(strings.Split(opts.Labels, ",")) + labelIDs := tool.StringsToInt64s(strings.Split(opts.Labels, ",")) if len(labelIDs) > 0 { sess.Join("INNER", "issue_label", "issue.id = issue_id").In("label_id", labelIDs) } diff --git a/models/issue_label.go b/models/issue_label.go index 096bba25..1ce5df07 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -15,7 +15,7 @@ import ( api "github.com/gogits/go-gogs-client" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" ) var labelColorPattern = regexp.MustCompile("#([a-fA-F0-9]{6})") @@ -138,7 +138,7 @@ func GetLabelOfRepoByID(repoID, labelID int64) (*Label, error) { // it silently ignores label IDs that are not belong to the repository. func GetLabelsInRepoByIDs(repoID int64, labelIDs []int64) ([]*Label, error) { labels := make([]*Label, 0, len(labelIDs)) - return labels, x.Where("repo_id = ?", repoID).In("id", base.Int64sToStrings(labelIDs)).Asc("name").Find(&labels) + return labels, x.Where("repo_id = ?", repoID).In("id", tool.Int64sToStrings(labelIDs)).Asc("name").Find(&labels) } // GetLabelsByRepoID returns all labels that belong to given repository by ID. @@ -161,7 +161,7 @@ func getLabelsByIssueID(e Engine, issueID int64) ([]*Label, error) { } labels := make([]*Label, 0, len(labelIDs)) - return labels, e.Where("id > 0").In("id", base.Int64sToStrings(labelIDs)).Asc("name").Find(&labels) + return labels, e.Where("id > 0").In("id", tool.Int64sToStrings(labelIDs)).Asc("name").Find(&labels) } // GetLabelsByIssueID returns all labels that belong to given issue by ID. diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 2f6f828f..30733423 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -13,7 +13,7 @@ import ( "github.com/go-xorm/xorm" log "gopkg.in/clog.v1" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" ) const _MIN_DB_VER = 10 @@ -159,10 +159,10 @@ func generateOrgRandsAndSalt(x *xorm.Engine) (err error) { } for _, org := range orgs { - if org.Rands, err = base.GetRandomString(10); err != nil { + if org.Rands, err = tool.GetRandomString(10); err != nil { return err } - if org.Salt, err = base.GetRandomString(10); err != nil { + if org.Salt, err = tool.GetRandomString(10); err != nil { return err } if _, err = sess.Id(org.ID).Update(org); err != nil { diff --git a/models/repo_branch.go b/models/repo_branch.go index b0c7d55d..8c2bbd33 100644 --- a/models/repo_branch.go +++ b/models/repo_branch.go @@ -11,7 +11,7 @@ import ( "github.com/Unknwon/com" "github.com/gogits/git-module" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" ) type Branch struct { @@ -149,10 +149,10 @@ func UpdateOrgProtectBranch(repo *Repository, protectBranch *ProtectBranch, whit } hasUsersChanged := false - validUserIDs := base.StringsToInt64s(strings.Split(protectBranch.WhitelistUserIDs, ",")) + validUserIDs := tool.StringsToInt64s(strings.Split(protectBranch.WhitelistUserIDs, ",")) if protectBranch.WhitelistUserIDs != whitelistUserIDs { hasUsersChanged = true - userIDs := base.StringsToInt64s(strings.Split(whitelistUserIDs, ",")) + userIDs := tool.StringsToInt64s(strings.Split(whitelistUserIDs, ",")) validUserIDs = make([]int64, 0, len(userIDs)) for _, userID := range userIDs { has, err := HasAccess(userID, repo, ACCESS_MODE_WRITE) @@ -165,14 +165,14 @@ func UpdateOrgProtectBranch(repo *Repository, protectBranch *ProtectBranch, whit validUserIDs = append(validUserIDs, userID) } - protectBranch.WhitelistUserIDs = strings.Join(base.Int64sToStrings(validUserIDs), ",") + protectBranch.WhitelistUserIDs = strings.Join(tool.Int64sToStrings(validUserIDs), ",") } hasTeamsChanged := false - validTeamIDs := base.StringsToInt64s(strings.Split(protectBranch.WhitelistTeamIDs, ",")) + validTeamIDs := tool.StringsToInt64s(strings.Split(protectBranch.WhitelistTeamIDs, ",")) if protectBranch.WhitelistTeamIDs != whitelistTeamIDs { hasTeamsChanged = true - teamIDs := base.StringsToInt64s(strings.Split(whitelistTeamIDs, ",")) + teamIDs := tool.StringsToInt64s(strings.Split(whitelistTeamIDs, ",")) teams, err := GetTeamsHaveAccessToRepo(repo.OwnerID, repo.ID, ACCESS_MODE_WRITE) if err != nil { return fmt.Errorf("GetTeamsHaveAccessToRepo [org_id: %d, repo_id: %d]: %v", repo.OwnerID, repo.ID, err) @@ -184,7 +184,7 @@ func UpdateOrgProtectBranch(repo *Repository, protectBranch *ProtectBranch, whit } } - protectBranch.WhitelistTeamIDs = strings.Join(base.Int64sToStrings(validTeamIDs), ",") + protectBranch.WhitelistTeamIDs = strings.Join(tool.Int64sToStrings(validTeamIDs), ",") } // Make sure protectBranch.ID is not 0 for whitelists diff --git a/models/ssh_key.go b/models/ssh_key.go index b8a5095b..7fa5c908 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -23,7 +23,7 @@ import ( "golang.org/x/crypto/ssh" log "gopkg.in/clog.v1" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/process" "github.com/gogits/gogs/pkg/setting" ) @@ -484,7 +484,7 @@ func deletePublicKeys(e *xorm.Session, keyIDs ...int64) error { return nil } - _, err := e.In("id", strings.Join(base.Int64sToStrings(keyIDs), ",")).Delete(new(PublicKey)) + _, err := e.In("id", strings.Join(tool.Int64sToStrings(keyIDs), ",")).Delete(new(PublicKey)) return err } diff --git a/models/token.go b/models/token.go index c18a6616..6824e43c 100644 --- a/models/token.go +++ b/models/token.go @@ -10,7 +10,7 @@ import ( "github.com/go-xorm/xorm" gouuid "github.com/satori/go.uuid" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" ) // AccessToken represents a personal access token. @@ -49,7 +49,7 @@ func (t *AccessToken) AfterSet(colName string, _ xorm.Cell) { // NewAccessToken creates new access token. func NewAccessToken(t *AccessToken) error { - t.Sha1 = base.EncodeSha1(gouuid.NewV4().String()) + t.Sha1 = tool.EncodeSha1(gouuid.NewV4().String()) _, err := x.Insert(t) return err } diff --git a/models/user.go b/models/user.go index 13f37f6b..1c733d6e 100644 --- a/models/user.go +++ b/models/user.go @@ -31,7 +31,7 @@ import ( "github.com/gogits/gogs/models/errors" "github.com/gogits/gogs/pkg/avatar" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/setting" ) @@ -191,7 +191,7 @@ func (u *User) HTMLURL() string { // GenerateEmailActivateCode generates an activate code based on user information and given e-mail. func (u *User) GenerateEmailActivateCode(email string) string { - code := base.CreateTimeLimitCode( + code := tool.CreateTimeLimitCode( com.ToStr(u.ID)+email+u.LowerName+u.Passwd+u.Rands, setting.Service.ActiveCodeLives, nil) @@ -262,7 +262,7 @@ func (u *User) RelAvatarLink() string { return setting.AppSubUrl + "/avatars/" + com.ToStr(u.ID) } - return base.AvatarLink(u.AvatarEmail) + return tool.AvatarLink(u.AvatarEmail) } // AvatarLink returns user avatar absolute link. @@ -462,7 +462,7 @@ func (u *User) DisplayName() string { } func (u *User) ShortName(length int) string { - return base.EllipsisString(u.Name, length) + return tool.EllipsisString(u.Name, length) } // IsMailable checks if a user is elegible @@ -484,7 +484,7 @@ func IsUserExist(uid int64, name string) (bool, error) { // GetUserSalt returns a ramdom user salt token. func GetUserSalt() (string, error) { - return base.GetRandomString(10) + return tool.GetRandomString(10) } // NewGhostUser creates and returns a fake user for someone has deleted his/her account. @@ -553,7 +553,7 @@ func CreateUser(u *User) (err error) { u.LowerName = strings.ToLower(u.Name) u.AvatarEmail = u.Email - u.Avatar = base.HashEmail(u.AvatarEmail) + u.Avatar = tool.HashEmail(u.AvatarEmail) if u.Rands, err = GetUserSalt(); err != nil { return err } @@ -596,12 +596,12 @@ func Users(page, pageSize int) ([]*User, error) { // get user by erify code func getVerifyUser(code string) (user *User) { - if len(code) <= base.TimeLimitCodeLength { + if len(code) <= tool.TimeLimitCodeLength { return nil } // use tail hex username query user - hexStr := code[base.TimeLimitCodeLength:] + hexStr := code[tool.TimeLimitCodeLength:] if b, err := hex.DecodeString(hexStr); err == nil { if user, err = GetUserByName(string(b)); user != nil { return user @@ -618,10 +618,10 @@ func VerifyUserActiveCode(code string) (user *User) { if user = getVerifyUser(code); user != nil { // time limit code - prefix := code[:base.TimeLimitCodeLength] + prefix := code[:tool.TimeLimitCodeLength] data := com.ToStr(user.ID) + user.Email + user.LowerName + user.Passwd + user.Rands - if base.VerifyTimeLimitCode(data, minutes, prefix) { + if tool.VerifyTimeLimitCode(data, minutes, prefix) { return user } } @@ -634,10 +634,10 @@ func VerifyActiveEmailCode(code, email string) *EmailAddress { if user := getVerifyUser(code); user != nil { // time limit code - prefix := code[:base.TimeLimitCodeLength] + prefix := code[:tool.TimeLimitCodeLength] data := com.ToStr(user.ID) + email + user.LowerName + user.Passwd + user.Rands - if base.VerifyTimeLimitCode(data, minutes, prefix) { + if tool.VerifyTimeLimitCode(data, minutes, prefix) { emailAddress := &EmailAddress{Email: email} if has, _ := x.Get(emailAddress); has { return emailAddress @@ -696,13 +696,13 @@ func updateUser(e Engine, u *User) error { if len(u.AvatarEmail) == 0 { u.AvatarEmail = u.Email } - u.Avatar = base.HashEmail(u.AvatarEmail) + u.Avatar = tool.HashEmail(u.AvatarEmail) } u.LowerName = strings.ToLower(u.Name) - u.Location = base.TruncateString(u.Location, 255) - u.Website = base.TruncateString(u.Website, 255) - u.Description = base.TruncateString(u.Description, 255) + u.Location = tool.TruncateString(u.Location, 255) + u.Website = tool.TruncateString(u.Website, 255) + u.Description = tool.TruncateString(u.Description, 255) _, err := e.Id(u.ID).AllCols().Update(u) return err diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index fd4d71c9..a52ef958 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.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/setting" ) @@ -122,7 +122,7 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (*models.User, bool) if len(baHead) > 0 { auths := strings.Fields(baHead) if len(auths) == 2 && auths[0] == "Basic" { - uname, passwd, _ := base.BasicAuthDecode(auths[1]) + uname, passwd, _ := tool.BasicAuthDecode(auths[1]) u, err := models.UserSignIn(uname, passwd) if err != nil { diff --git a/pkg/context/api.go b/pkg/context/api.go index a1c80bd1..5e29a73f 100644 --- a/pkg/context/api.go +++ b/pkg/context/api.go @@ -12,7 +12,7 @@ import ( log "gopkg.in/clog.v1" "gopkg.in/macaron.v1" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/setting" ) @@ -37,7 +37,7 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) { ctx.JSON(status, map[string]string{ "message": message, - "url": base.DOC_URL, + "url": tool.DOC_URL, }) } diff --git a/pkg/context/context.go b/pkg/context/context.go index b3377833..89783007 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -21,7 +21,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/pkg/auth" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/form" "github.com/gogits/gogs/pkg/setting" ) @@ -80,18 +80,18 @@ func (ctx *Context) HasValue(name string) bool { } // HTML responses template with given status. -func (ctx *Context) HTML(status int, name base.TplName) { +func (ctx *Context) HTML(status int, name tool.TplName) { log.Trace("Template: %s", name) ctx.Context.HTML(status, string(name)) } // Success responses template with status http.StatusOK. -func (c *Context) Success(name base.TplName) { +func (c *Context) Success(name tool.TplName) { c.HTML(http.StatusOK, name) } // RenderWithErr used for page has form validation but need to prompt error to users. -func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, f interface{}) { +func (ctx *Context) RenderWithErr(msg string, tpl tool.TplName, f interface{}) { if f != nil { form.Assign(f, ctx.Data) } @@ -112,7 +112,7 @@ func (ctx *Context) Handle(status int, title string, err error) { ctx.Data["ErrorMsg"] = err } } - ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status))) + ctx.HTML(status, tool.TplName(fmt.Sprintf("status/%d", status))) } // NotFound renders the 404 page. diff --git a/pkg/mailer/mail.go b/pkg/mailer/mail.go index 20e2b309..09405a2d 100644 --- a/pkg/mailer/mail.go +++ b/pkg/mailer/mail.go @@ -12,21 +12,21 @@ import ( "gopkg.in/gomail.v2" "gopkg.in/macaron.v1" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/markup" "github.com/gogits/gogs/pkg/setting" ) const ( - MAIL_AUTH_ACTIVATE base.TplName = "auth/activate" - MAIL_AUTH_ACTIVATE_EMAIL base.TplName = "auth/activate_email" - MAIL_AUTH_RESET_PASSWORD base.TplName = "auth/reset_passwd" - MAIL_AUTH_REGISTER_NOTIFY base.TplName = "auth/register_notify" + MAIL_AUTH_ACTIVATE tool.TplName = "auth/activate" + MAIL_AUTH_ACTIVATE_EMAIL tool.TplName = "auth/activate_email" + MAIL_AUTH_RESET_PASSWORD tool.TplName = "auth/reset_passwd" + MAIL_AUTH_REGISTER_NOTIFY tool.TplName = "auth/register_notify" - MAIL_ISSUE_COMMENT base.TplName = "issue/comment" - MAIL_ISSUE_MENTION base.TplName = "issue/mention" + MAIL_ISSUE_COMMENT tool.TplName = "issue/comment" + MAIL_ISSUE_MENTION tool.TplName = "issue/mention" - MAIL_NOTIFY_COLLABORATOR base.TplName = "notify/collaborator" + MAIL_NOTIFY_COLLABORATOR tool.TplName = "notify/collaborator" ) type MailRender interface { @@ -79,7 +79,7 @@ type Issue interface { HTMLURL() string } -func SendUserMail(c *macaron.Context, u User, tpl base.TplName, code, subject, info string) { +func SendUserMail(c *macaron.Context, u User, tpl tool.TplName, code, subject, info string) { data := map[string]interface{}{ "Username": u.DisplayName(), "ActiveCodeLives": setting.Service.ActiveCodeLives / 60, @@ -172,7 +172,7 @@ func composeTplData(subject, body, link string) map[string]interface{} { return data } -func composeIssueMessage(issue Issue, repo Repository, doer User, tplName base.TplName, tos []string, info string) *Message { +func composeIssueMessage(issue Issue, repo Repository, doer User, tplName tool.TplName, tos []string, info string) *Message { subject := issue.MailSubject() body := string(markup.RenderSpecialLink([]byte(issue.Content()), repo.HTMLURL(), repo.ComposeMetas())) data := composeTplData(subject, body, issue.HTMLURL()) diff --git a/pkg/markup/markdown.go b/pkg/markup/markdown.go index 3414a58c..fc2f54c6 100644 --- a/pkg/markup/markdown.go +++ b/pkg/markup/markdown.go @@ -14,7 +14,7 @@ import ( "github.com/russross/blackfriday" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/setting" ) @@ -72,7 +72,7 @@ func (r *MarkdownRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) { if j == -1 { j = len(m) } - out.WriteString(fmt.Sprintf(` %s`, m, base.ShortSha(string(m[i+7:j])))) + out.WriteString(fmt.Sprintf(` %s`, m, tool.ShortSha(string(m[i+7:j])))) return } diff --git a/pkg/markup/markup.go b/pkg/markup/markup.go index 5c92b74a..98742540 100644 --- a/pkg/markup/markup.go +++ b/pkg/markup/markup.go @@ -14,7 +14,7 @@ import ( "github.com/Unknwon/com" "golang.org/x/net/html" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/setting" ) @@ -140,7 +140,7 @@ func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte { if com.StrTo(m).MustInt() > 0 { return m } - return fmt.Sprintf(`%s`, urlPrefix, m, base.ShortSha(string(m))) + return fmt.Sprintf(`%s`, urlPrefix, m, tool.ShortSha(string(m))) })) } diff --git a/pkg/template/template.go b/pkg/template/template.go index 61c47b8c..55bc8764 100644 --- a/pkg/template/template.go +++ b/pkg/template/template.go @@ -22,7 +22,7 @@ import ( "gopkg.in/editorconfig/editorconfig-core-go.v1" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/pkg/base" + "github.com/gogits/gogs/pkg/tool" "github.com/gogits/gogs/pkg/markup" "github.com/gogits/gogs/pkg/setting" ) @@ -59,14 +59,14 @@ func NewFuncMap() []template.FuncMap { "LoadTimes": func(startTime time.Time) string { return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" }, - "AvatarLink": base.AvatarLink, + "AvatarLink": tool.AvatarLink, "Safe": Safe, "Sanitize": bluemonday.UGCPolicy().Sanitize, "Str2html": Str2html, - "TimeSince": base.TimeSince, - "RawTimeSince": base.RawTimeSince, - "FileSize": base.FileSize, - "Subtract": base.Subtract, + "TimeSince": tool.TimeSince, + "RawTimeSince": tool.RawTimeSince, + "FileSize": tool.FileSize, + "Subtract": tool.Subtract, "Add": func(a, b int) int { return a + b }, @@ -91,13 +91,13 @@ func NewFuncMap() []template.FuncMap { } return str[start:end] }, - "Join": strings.Join, - "EllipsisString": base.EllipsisString, - "DiffTypeToStr": DiffTypeToStr, - "DiffLineTypeToStr": DiffLineTypeToStr, - "Sha1": Sha1, - "ShortSha": base.ShortSha, - "MD5": base.EncodeMD5, + "Join": strings.Join, + "EllipsisString": tool.EllipsisString, + "DiffTypeToStr": DiffTypeToStr, + "DiffLineTypeToStr": DiffLineTypeToStr, + "Sha1": Sha1, + "ShortSha": tool.ShortSha, + "MD5": tool.EncodeMD5, "ActionContent2Commits": ActionContent2Commits, "EscapePound": EscapePound, "RenderCommitMessage": RenderCommitMessage, @@ -142,11 +142,11 @@ func List(l *list.List) chan interface{} { } func Sha1(str string) string { - return base.EncodeSha1(str) + return tool.EncodeSha1(str) } func ToUTF8WithErr(content []byte) (error, string) { - charsetLabel, err := base.DetectEncoding(content) + charsetLabel, err := tool.DetectEncoding(content) if err != nil { return err, "" } else if charsetLabel == "UTF-8" { diff --git a/pkg/base/base.go b/pkg/tool/base.go similarity index 95% rename from pkg/base/base.go rename to pkg/tool/base.go index 8ba211aa..6ad1a99b 100644 --- a/pkg/base/base.go +++ b/pkg/tool/base.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package base +package tool const DOC_URL = "https://github.com/gogits/go-gogs-client/wiki" diff --git a/pkg/base/file.go b/pkg/tool/file.go similarity index 99% rename from pkg/base/file.go rename to pkg/tool/file.go index 1c39e726..6ca4136a 100644 --- a/pkg/base/file.go +++ b/pkg/tool/file.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package base +package tool import ( "fmt" diff --git a/pkg/base/tool.go b/pkg/tool/tool.go similarity index 99% rename from pkg/base/tool.go rename to pkg/tool/tool.go index 800be844..ceb276e5 100644 --- a/pkg/base/tool.go +++ b/pkg/tool/tool.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package base +package tool import ( "crypto/md5" 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.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 = base.FileSize(int64(m.NextGC)) + 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 { diff --git a/templates/user/settings/navbar.tmpl b/templates/user/settings/navbar.tmpl index 250bf77c..2d4ff8dd 100644 --- a/templates/user/settings/navbar.tmpl +++ b/templates/user/settings/navbar.tmpl @@ -16,14 +16,14 @@ {{.i18n.Tr "settings.ssh_keys"}} - - {{.i18n.Tr "settings.applications"}} + + {{.i18n.Tr "settings.repos"}} {{.i18n.Tr "settings.orgs"}} - - {{.i18n.Tr "settings.repos"}} + + {{.i18n.Tr "settings.applications"}} {{.i18n.Tr "settings.delete"}}