浏览代码

Update GRC #100 in pkg

Yoginth 7 年之前
父节点
当前提交
b45ec4664e
共有 56 个文件被更改,包括 346 次插入157 次删除
  1. 7 7
      cmd/web.go
  2. 2 1
      models/errors/errors.go
  3. 4 0
      models/errors/issue.go
  4. 8 0
      models/errors/login_source.go
  5. 2 0
      models/errors/org.go
  6. 12 0
      models/errors/repo.go
  7. 4 0
      models/errors/two_factor.go
  8. 6 0
      models/errors/user.go
  9. 4 0
      models/errors/user_mail.go
  10. 4 0
      models/errors/webhook.go
  11. 6 6
      models/login_source.go
  12. 2 2
      models/repo.go
  13. 5 5
      models/user.go
  14. 2 2
      pkg/auth/auth.go
  15. 1 0
      pkg/auth/github/github.go
  16. 8 7
      pkg/auth/ldap/ldap.go
  17. 2 1
      pkg/auth/pam/pam.go
  18. 2 1
      pkg/auth/pam/pam_stub.go
  19. 4 3
      pkg/avatar/avatar.go
  20. 5 2
      pkg/context/api.go
  21. 1 0
      pkg/context/api_org.go
  22. 3 1
      pkg/context/auth.go
  23. 9 2
      pkg/context/context.go
  24. 3 0
      pkg/context/org.go
  25. 5 1
      pkg/context/repo.go
  26. 1 0
      pkg/cron/cron.go
  27. 6 2
      pkg/form/admin.go
  28. 2 0
      pkg/form/auth.go
  29. 6 3
      pkg/form/form.go
  30. 6 0
      pkg/form/org.go
  31. 55 8
      pkg/form/repo.go
  32. 23 3
      pkg/form/user.go
  33. 17 14
      pkg/httplib/httplib.go
  34. 25 21
      pkg/mailer/mail.go
  35. 4 1
      pkg/mailer/mailer.go
  36. 1 1
      pkg/markup/markdown.go
  37. 10 10
      pkg/markup/markup.go
  38. 1 1
      pkg/markup/orgmode.go
  39. 8 4
      pkg/process/manager.go
  40. 28 12
      pkg/setting/setting.go
  41. 1 0
      pkg/template/highlight/highlight.go
  42. 4 0
      pkg/tool/file.go
  43. 0 1
      pkg/tool/path.go
  44. 6 5
      pkg/tool/tool.go
  45. 1 0
      pkg/user/user.go
  46. 5 5
      routes/admin/auths.go
  47. 1 1
      routes/admin/users.go
  48. 1 1
      routes/api/v1/misc/markdown.go
  49. 2 2
      routes/api/v1/repo/repo.go
  50. 5 5
      routes/install.go
  51. 1 1
      routes/org/setting.go
  52. 6 6
      routes/repo/editor.go
  53. 1 1
      routes/repo/repo.go
  54. 1 1
      routes/repo/setting.go
  55. 6 6
      routes/repo/view.go
  56. 1 1
      routes/user/setting.go

+ 7 - 7
cmd/web.go

@@ -70,7 +70,7 @@ func newMacaron() *macaron.Macaron {
 	if setting.EnableGzip {
 		m.Use(gzip.Gziper())
 	}
-	if setting.Protocol == setting.SCHEME_FCGI {
+	if setting.Protocol == setting.SchemeFCGI {
 		m.SetURLPrefix(setting.AppSubURL)
 	}
 	m.Use(macaron.Static(
@@ -272,7 +272,7 @@ func runWeb(c *cli.Context) error {
 		
 		m.Group("/users", func() {
 			m.Get("", admin.Users)
-			m.Combo("/new").Get(admin.NewUser).Post(bindIgnErr(form.AdminCrateUser{}), admin.NewUserPost)
+			m.Combo("/new").Get(admin.NewUser).Post(bindIgnErr(form.AdminCreateUser{}), admin.NewUserPost)
 			m.Combo("/:userid").Get(admin.EditUser).Post(bindIgnErr(form.AdminEditUser{}), admin.EditUserPost)
 			m.Post("/:userid/delete", admin.DeleteUser)
 		})
@@ -708,7 +708,7 @@ func runWeb(c *cli.Context) error {
 	}
 
 	var listenAddr string
-	if setting.Protocol == setting.SCHEME_UNIX_SOCKET {
+	if setting.Protocol == setting.SchemeUnixSocket {
 		listenAddr = fmt.Sprintf("%s", setting.HTTPAddr)
 	} else {
 		listenAddr = fmt.Sprintf("%s:%s", setting.HTTPAddr, setting.HTTPPort)
@@ -717,9 +717,9 @@ func runWeb(c *cli.Context) error {
 
 	var err error
 	switch setting.Protocol {
-	case setting.SCHEME_HTTP:
+	case setting.SchemeHTTP:
 		err = http.ListenAndServe(listenAddr, m)
-	case setting.SCHEME_HTTPS:
+	case setting.SchemeHTTPS:
 		var tlsMinVersion uint16
 		switch setting.TLSMinVersion {
 		case "SSL30":
@@ -745,9 +745,9 @@ func runWeb(c *cli.Context) error {
 			},
 		}, Handler: m}
 		err = server.ListenAndServeTLS(setting.CertFile, setting.KeyFile)
-	case setting.SCHEME_FCGI:
+	case setting.SchemeFCGI:
 		err = fcgi.Serve(nil, m)
-	case setting.SCHEME_UNIX_SOCKET:
+	case setting.SchemeUnixSocket:
 		os.Remove(listenAddr)
 
 		var listener *net.UnixListener

+ 2 - 1
models/errors/errors.go

@@ -8,7 +8,8 @@ package errors
 
 import "errors"
 
-var InternalServerError = errors.New("internal server error")
+// ErrInternalServer stores default error
+var ErrInternalServer = errors.New("internal server error")
 
 // New is a wrapper of real errors.New function.
 func New(text string) error {

+ 4 - 0
models/errors/issue.go

@@ -8,12 +8,14 @@ package errors
 
 import "fmt"
 
+// IssueNotExist represents issue not exist
 type IssueNotExist struct {
 	ID     int64
 	RepoID int64
 	Index  int64
 }
 
+// IsIssueNotExist returns true if issue not exist
 func IsIssueNotExist(err error) bool {
 	_, ok := err.(IssueNotExist)
 	return ok
@@ -23,10 +25,12 @@ func (err IssueNotExist) Error() string {
 	return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
 }
 
+// InvalidIssueReference represents invalid issue reference
 type InvalidIssueReference struct {
 	Ref string
 }
 
+// IsInvalidIssueReference returns true if invalid issue reference
 func IsInvalidIssueReference(err error) bool {
 	_, ok := err.(InvalidIssueReference)
 	return ok

+ 8 - 0
models/errors/login_source.go

@@ -8,10 +8,12 @@ package errors
 
 import "fmt"
 
+// LoginSourceNotExist represents a "LoginSourceNotExist" kind of error
 type LoginSourceNotExist struct {
 	ID int64
 }
 
+// IsLoginSourceNotExist checks if an error is a LoginSourceNotExist
 func IsLoginSourceNotExist(err error) bool {
 	_, ok := err.(LoginSourceNotExist)
 	return ok
@@ -21,10 +23,12 @@ func (err LoginSourceNotExist) Error() string {
 	return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
 }
 
+// LoginSourceNotActivated represents a "LoginSourceNotActivated" kind of error
 type LoginSourceNotActivated struct {
 	SourceID int64
 }
 
+// IsLoginSourceNotActivated checks if an error is a LoginSourceNotActivated
 func IsLoginSourceNotActivated(err error) bool {
 	_, ok := err.(LoginSourceNotActivated)
 	return ok
@@ -34,10 +38,12 @@ func (err LoginSourceNotActivated) Error() string {
 	return fmt.Sprintf("login source is not activated [source_id: %d]", err.SourceID)
 }
 
+// InvalidLoginSourceType represents a "InvalidLoginSourceType" kind of error
 type InvalidLoginSourceType struct {
 	Type interface{}
 }
 
+// IsInvalidLoginSourceType checks if an error is a InvalidLoginSourceType
 func IsInvalidLoginSourceType(err error) bool {
 	_, ok := err.(InvalidLoginSourceType)
 	return ok
@@ -47,11 +53,13 @@ func (err InvalidLoginSourceType) Error() string {
 	return fmt.Sprintf("invalid login source type [type: %v]", err.Type)
 }
 
+// LoginSourceMismatch represents a "LoginSourceMismatch" kind of error
 type LoginSourceMismatch struct {
 	Expect int64
 	Actual int64
 }
 
+// IsLoginSourceMismatch checks if an error is a LoginSourceMismatch
 func IsLoginSourceMismatch(err error) bool {
 	_, ok := err.(LoginSourceMismatch)
 	return ok

+ 2 - 0
models/errors/org.go

@@ -8,11 +8,13 @@ package errors
 
 import "fmt"
 
+// TeamNotExist represents a "TeamNotExist" kind of error
 type TeamNotExist struct {
 	TeamID int64
 	Name   string
 }
 
+// IsTeamNotExist checks if an error is a TeamNotExist
 func IsTeamNotExist(err error) bool {
 	_, ok := err.(TeamNotExist)
 	return ok

+ 12 - 0
models/errors/repo.go

@@ -8,12 +8,14 @@ package errors
 
 import "fmt"
 
+// RepoNotExist represents a "RepoNotExist" kind of error
 type RepoNotExist struct {
 	ID     int64
 	UserID int64
 	Name   string
 }
 
+// IsRepoNotExist checks if an error is a RepoNotExist
 func IsRepoNotExist(err error) bool {
 	_, ok := err.(RepoNotExist)
 	return ok
@@ -23,10 +25,12 @@ func (err RepoNotExist) Error() string {
 	return fmt.Sprintf("repository does not exist [id: %d, user_id: %d, name: %s]", err.ID, err.UserID, err.Name)
 }
 
+// ReachLimitOfRepo represents a "ReachLimitOfRepo" kind of error
 type ReachLimitOfRepo struct {
 	Limit int
 }
 
+// IsReachLimitOfRepo checks if an error is a ReachLimitOfRepo
 func IsReachLimitOfRepo(err error) bool {
 	_, ok := err.(ReachLimitOfRepo)
 	return ok
@@ -36,10 +40,12 @@ func (err ReachLimitOfRepo) Error() string {
 	return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
 }
 
+// InvalidRepoReference represents a "InvalidRepoReference" kind of error
 type InvalidRepoReference struct {
 	Ref string
 }
 
+// IsInvalidRepoReference checks if an error is a InvalidRepoReference
 func IsInvalidRepoReference(err error) bool {
 	_, ok := err.(InvalidRepoReference)
 	return ok
@@ -49,10 +55,12 @@ func (err InvalidRepoReference) Error() string {
 	return fmt.Sprintf("invalid repository reference [ref: %s]", err.Ref)
 }
 
+// MirrorNotExist represents a "MirrorNotExist" kind of error
 type MirrorNotExist struct {
 	RepoID int64
 }
 
+// IsMirrorNotExist checks if an error is a MirrorNotExist
 func IsMirrorNotExist(err error) bool {
 	_, ok := err.(MirrorNotExist)
 	return ok
@@ -62,10 +70,12 @@ func (err MirrorNotExist) Error() string {
 	return fmt.Sprintf("mirror does not exist [repo_id: %d]", err.RepoID)
 }
 
+// BranchAlreadyExists represents a "BranchAlreadyExists" kind of error
 type BranchAlreadyExists struct {
 	Name string
 }
 
+// IsBranchAlreadyExists checks if an error is a BranchAlreadyExists
 func IsBranchAlreadyExists(err error) bool {
 	_, ok := err.(BranchAlreadyExists)
 	return ok
@@ -75,10 +85,12 @@ func (err BranchAlreadyExists) Error() string {
 	return fmt.Sprintf("branch already exists [name: %s]", err.Name)
 }
 
+// ErrBranchNotExist represents a "ErrBranchNotExist" kind of error
 type ErrBranchNotExist struct {
 	Name string
 }
 
+// IsErrBranchNotExist checks if an error is a ErrBranchNotExist
 func IsErrBranchNotExist(err error) bool {
 	_, ok := err.(ErrBranchNotExist)
 	return ok

+ 4 - 0
models/errors/two_factor.go

@@ -8,10 +8,12 @@ package errors
 
 import "fmt"
 
+// TwoFactorNotFound represents a "TwoFactorNotFound" kind of error
 type TwoFactorNotFound struct {
 	UserID int64
 }
 
+// IsTwoFactorNotFound checks if an error is a TwoFactorNotFound
 func IsTwoFactorNotFound(err error) bool {
 	_, ok := err.(TwoFactorNotFound)
 	return ok
@@ -21,10 +23,12 @@ func (err TwoFactorNotFound) Error() string {
 	return fmt.Sprintf("two-factor authentication does not found [user_id: %d]", err.UserID)
 }
 
+// TwoFactorRecoveryCodeNotFound represents a "TwoFactorRecoveryCodeNotFound" kind of error
 type TwoFactorRecoveryCodeNotFound struct {
 	Code string
 }
 
+// IsTwoFactorRecoveryCodeNotFound checks if an error is a TwoFactorRecoveryCodeNotFound
 func IsTwoFactorRecoveryCodeNotFound(err error) bool {
 	_, ok := err.(TwoFactorRecoveryCodeNotFound)
 	return ok

+ 6 - 0
models/errors/user.go

@@ -8,8 +8,10 @@ package errors
 
 import "fmt"
 
+// EmptyName represents a "RepoNotExist" kind of error
 type EmptyName struct{}
 
+// IsEmptyName checks if an error is a EmptyName
 func IsEmptyName(err error) bool {
 	_, ok := err.(EmptyName)
 	return ok
@@ -19,11 +21,13 @@ func (err EmptyName) Error() string {
 	return "empty name"
 }
 
+// UserNotExist represents a "UserNotExist" kind of error
 type UserNotExist struct {
 	UserID int64
 	Name   string
 }
 
+// IsUserNotExist checks if an error is a UserNotExist
 func IsUserNotExist(err error) bool {
 	_, ok := err.(UserNotExist)
 	return ok
@@ -33,10 +37,12 @@ func (err UserNotExist) Error() string {
 	return fmt.Sprintf("user does not exist [user_id: %d, name: %s]", err.UserID, err.Name)
 }
 
+// UserNotKeyOwner represents a "UserNotKeyOwner" kind of error
 type UserNotKeyOwner struct {
 	KeyID int64
 }
 
+// IsUserNotKeyOwner checks if an error is a UserNotKeyOwner
 func IsUserNotKeyOwner(err error) bool {
 	_, ok := err.(UserNotKeyOwner)
 	return ok

+ 4 - 0
models/errors/user_mail.go

@@ -8,10 +8,12 @@ package errors
 
 import "fmt"
 
+// EmailNotFound represents a "EmailNotFound" kind of error
 type EmailNotFound struct {
 	Email string
 }
 
+// IsEmailNotFound checks if an error is a EmailNotFound
 func IsEmailNotFound(err error) bool {
 	_, ok := err.(EmailNotFound)
 	return ok
@@ -21,10 +23,12 @@ func (err EmailNotFound) Error() string {
 	return fmt.Sprintf("email is not found [email: %s]", err.Email)
 }
 
+// EmailNotVerified represents a "EmailNotVerified" kind of error
 type EmailNotVerified struct {
 	Email string
 }
 
+// IsEmailNotVerified checks if an error is a EmailNotVerified
 func IsEmailNotVerified(err error) bool {
 	_, ok := err.(EmailNotVerified)
 	return ok

+ 4 - 0
models/errors/webhook.go

@@ -8,10 +8,12 @@ package errors
 
 import "fmt"
 
+// WebhookNotExist represents a "WebhookNotExist" kind of error
 type WebhookNotExist struct {
 	ID int64
 }
 
+// IsWebhookNotExist checks if an error is a WebhookNotExist
 func IsWebhookNotExist(err error) bool {
 	_, ok := err.(WebhookNotExist)
 	return ok
@@ -21,11 +23,13 @@ func (err WebhookNotExist) Error() string {
 	return fmt.Sprintf("webhook does not exist [id: %d]", err.ID)
 }
 
+// HookTaskNotExist represents a "HookTaskNotExist" kind of error
 type HookTaskNotExist struct {
 	HookID int64
 	UUID   string
 }
 
+// IsHookTaskNotExist checks if an error is a HookTaskNotExist
 func IsHookTaskNotExist(err error) bool {
 	_, ok := err.(HookTaskNotExist)
 	return ok

+ 6 - 6
models/login_source.go

@@ -57,9 +57,9 @@ var LoginNames = map[LoginType]string{
 
 // SecurityProtocolNames contains the name of SecurityProtocol values.
 var SecurityProtocolNames = map[ldap.SecurityProtocol]string{
-	ldap.SECURITY_PROTOCOL_UNENCRYPTED: "Unencrypted",
-	ldap.SECURITY_PROTOCOL_LDAPS:       "LDAPS",
-	ldap.SECURITY_PROTOCOL_START_TLS:   "StartTLS",
+	ldap.SecurityProtocolUnencrypted: "Unencrypted",
+	ldap.SecurityProtocolLDAPS:       "LDAPS",
+	ldap.SecurityProtocolStartTLS:    "StartTLS",
 }
 
 // Ensure structs implemented interface.
@@ -263,7 +263,7 @@ func (s *LoginSource) IsGitHub() bool {
 // HasTLS returns true of this source supports TLS.
 func (s *LoginSource) HasTLS() bool {
 	return ((s.IsLDAP() || s.IsDLDAP()) &&
-		s.LDAP().SecurityProtocol > ldap.SECURITY_PROTOCOL_UNENCRYPTED) ||
+		s.LDAP().SecurityProtocol > ldap.SecurityProtocolUnencrypted) ||
 		s.IsSMTP()
 }
 
@@ -271,7 +271,7 @@ func (s *LoginSource) HasTLS() bool {
 func (s *LoginSource) UseTLS() bool {
 	switch s.Type {
 	case LoginLDAP, LoginDLDAP:
-		return s.LDAP().SecurityProtocol != ldap.SECURITY_PROTOCOL_UNENCRYPTED
+		return s.LDAP().SecurityProtocol != ldap.SecurityProtocolUnencrypted
 	case LoginSMTP:
 		return s.SMTP().TLS
 	}
@@ -757,7 +757,7 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC
 // LoginViaPAM queries if login/password is valid against the PAM,
 // and create a local user if success when enabled.
 func LoginViaPAM(user *User, login, password string, sourceID int64, cfg *PAMConfig, autoRegister bool) (*User, error) {
-	if err := pam.PAMAuth(cfg.ServiceName, login, password); err != nil {
+	if err := pam.Auth(cfg.ServiceName, login, password); err != nil {
 		if strings.Contains(err.Error(), "Authentication failure") {
 			return nil, errors.UserNotExist{0, login}
 		}

+ 2 - 2
models/repo.go

@@ -17,7 +17,7 @@ import (
 	"gitote/gitote/pkg/setting"
 	"gitote/gitote/pkg/sync"
 	"image"
-	
+
 	// Package jpeg implements a JPEG image decoder and encoder.
 	_ "image/jpeg"
 	"image/png"
@@ -368,7 +368,7 @@ func (repo *Repository) UploadAvatar(data []byte) error {
 	}
 	defer fw.Close()
 
-	m := resize.Resize(avatar.AVATAR_SIZE, avatar.AVATAR_SIZE, img, resize.NearestNeighbor)
+	m := resize.Resize(avatar.AvatarSize, avatar.AvatarSize, img, resize.NearestNeighbor)
 	if err = png.Encode(fw, m); err != nil {
 		return fmt.Errorf("encode image: %v", err)
 	}

+ 5 - 5
models/user.go

@@ -410,7 +410,7 @@ func (u *User) UploadAvatar(data []byte) error {
 	}
 	defer fw.Close()
 
-	m := resize.Resize(avatar.AVATAR_SIZE, avatar.AVATAR_SIZE, img, resize.NearestNeighbor)
+	m := resize.Resize(avatar.AvatarSize, avatar.AvatarSize, img, resize.NearestNeighbor)
 	if err = png.Encode(fw, m); err != nil {
 		return fmt.Errorf("encode image: %v", err)
 	}
@@ -664,12 +664,12 @@ func Users(page, pageSize int) ([]*User, error) {
 // parseUserFromCode returns user by username encoded in code.
 // It returns nil if code or username is invalid.
 func parseUserFromCode(code string) (user *User) {
-	if len(code) <= tool.TIME_LIMIT_CODE_LENGTH {
+	if len(code) <= tool.TimeLimitCodeLength {
 		return nil
 	}
 
 	// Use tail hex username to query user
-	hexStr := code[tool.TIME_LIMIT_CODE_LENGTH:]
+	hexStr := code[tool.TimeLimitCodeLength:]
 	if b, err := hex.DecodeString(hexStr); err == nil {
 		if user, err = GetUserByName(string(b)); user != nil {
 			return user
@@ -688,7 +688,7 @@ func VerifyUserActiveCode(code string) (user *User) {
 
 	if user = parseUserFromCode(code); user != nil {
 		// time limit code
-		prefix := code[:tool.TIME_LIMIT_CODE_LENGTH]
+		prefix := code[:tool.TimeLimitCodeLength]
 		data := com.ToStr(user.ID) + user.Email + user.LowerName + user.Passwd + user.Rands
 
 		if tool.VerifyTimeLimitCode(data, minutes, prefix) {
@@ -704,7 +704,7 @@ func VerifyActiveEmailCode(code, email string) *EmailAddress {
 
 	if user := parseUserFromCode(code); user != nil {
 		// time limit code
-		prefix := code[:tool.TIME_LIMIT_CODE_LENGTH]
+		prefix := code[:tool.TimeLimitCodeLength]
 		data := com.ToStr(user.ID) + email + user.LowerName + user.Passwd + user.Rands
 
 		if tool.VerifyTimeLimitCode(data, minutes, prefix) {

+ 2 - 2
pkg/auth/auth.go

@@ -21,6 +21,7 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
+// IsAPIPath if URL is an api path
 func IsAPIPath(url string) bool {
 	return strings.HasPrefix(url, "/api/")
 }
@@ -120,9 +121,8 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (_ *models.User, isB
 							raven.CaptureErrorAndWait(err, nil)
 							log.Error(2, "CreateUser: %v", err)
 							return nil, false, false
-						} else {
-							return u, false, false
 						}
+						return u, false, false
 					}
 				}
 				return u, false, false

+ 1 - 0
pkg/auth/github/github.go

@@ -16,6 +16,7 @@ import (
 	"github.com/google/go-github/github"
 )
 
+// Authenticate auth via GitHub
 func Authenticate(apiEndpoint, login, passwd string) (name string, email string, website string, location string, _ error) {
 	tp := github.BasicAuthTransport{
 		Username: strings.TrimSpace(login),

+ 8 - 7
pkg/auth/ldap/ldap.go

@@ -18,16 +18,17 @@ import (
 	"gopkg.in/ldap.v2"
 )
 
+// SecurityProtocol protocol type
 type SecurityProtocol int
 
 // Note: new type must be added at the end of list to maintain compatibility.
 const (
-	SECURITY_PROTOCOL_UNENCRYPTED SecurityProtocol = iota
-	SECURITY_PROTOCOL_LDAPS
-	SECURITY_PROTOCOL_START_TLS
+	SecurityProtocolUnencrypted SecurityProtocol = iota
+	SecurityProtocolLDAPS
+	SecurityProtocolStartTLS
 )
 
-// Basic LDAP authentication service
+// Source Basic LDAP authentication service
 type Source struct {
 	Host              string // LDAP host
 	Port              int    // port number
@@ -148,7 +149,7 @@ func dial(ls *Source) (*ldap.Conn, error) {
 		ServerName:         ls.Host,
 		InsecureSkipVerify: ls.SkipVerify,
 	}
-	if ls.SecurityProtocol == SECURITY_PROTOCOL_LDAPS {
+	if ls.SecurityProtocol == SecurityProtocolLDAPS {
 		return ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ls.Host, ls.Port), tlsCfg)
 	}
 
@@ -157,7 +158,7 @@ func dial(ls *Source) (*ldap.Conn, error) {
 		return nil, fmt.Errorf("Dial: %v", err)
 	}
 
-	if ls.SecurityProtocol == SECURITY_PROTOCOL_START_TLS {
+	if ls.SecurityProtocol == SecurityProtocolStartTLS {
 		if err = conn.StartTLS(tlsCfg); err != nil {
 			conn.Close()
 			return nil, fmt.Errorf("StartTLS: %v", err)
@@ -178,7 +179,7 @@ func bindUser(l *ldap.Conn, userDN, passwd string) error {
 	return err
 }
 
-// searchEntry : search an LDAP source if an entry (name, passwd) is valid and in the specific filter
+// SearchEntry search an LDAP source if an entry (name, passwd) is valid and in the specific filter
 func (ls *Source) SearchEntry(name, passwd string, directBind bool) (string, string, string, string, bool, bool) {
 	// See https://tools.ietf.org/search/rfc4513#section-5.1.2
 	if len(passwd) == 0 {

+ 2 - 1
pkg/auth/pam/pam.go

@@ -14,7 +14,8 @@ import (
 	"github.com/msteinert/pam"
 )
 
-func PAMAuth(serviceName, userName, passwd string) error {
+// Auth pam auth service
+func Auth(serviceName, userName, passwd string) error {
 	t, err := pam.StartFunc(serviceName, userName, func(s pam.Style, msg string) (string, error) {
 		switch s {
 		case pam.PromptEchoOff:

+ 2 - 1
pkg/auth/pam/pam_stub.go

@@ -12,6 +12,7 @@ import (
 	"errors"
 )
 
-func PAMAuth(serviceName, userName, passwd string) error {
+// Auth not supported lack of pam tag
+func Auth(serviceName, userName, passwd string) error {
 	return errors.New("PAM not supported")
 }

+ 4 - 3
pkg/avatar/avatar.go

@@ -16,9 +16,10 @@ import (
 	"github.com/issue9/identicon"
 )
 
-const AVATAR_SIZE = 290
+// AvatarSize returns avatar's size
+const AvatarSize = 290
 
-// RandomImage generates and returns a random avatar image unique to input data
+// RandomImageSize generates and returns a random avatar image unique to input data
 // in custom size (height and width).
 func RandomImageSize(size int, data []byte) (image.Image, error) {
 	randExtent := len(palette.WebSafe) - 32
@@ -41,5 +42,5 @@ func RandomImageSize(size int, data []byte) (image.Image, error) {
 // RandomImage generates and returns a random avatar image unique to input data
 // in default size (height and width).
 func RandomImage(data []byte) (image.Image, error) {
-	return RandomImageSize(AVATAR_SIZE, data)
+	return RandomImageSize(AvatarSize, data)
 }

+ 5 - 2
pkg/context/api.go

@@ -17,6 +17,7 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
+// APIContext is a specific macaron context for API service
 type APIContext struct {
 	*Context // TODO: Reduce to only needed fields instead of full shadow
 
@@ -25,7 +26,8 @@ type APIContext struct {
 	Org     *APIOrganization
 }
 
-const DOC_URL = "https://api.gitote.in"
+// DocURL api doc url
+const DocURL = "https://dev.gitote.in"
 
 // Error responses error message to client with given message.
 // If status is 500, also it prints error to log.
@@ -43,7 +45,7 @@ func (c *APIContext) Error(status int, title string, obj interface{}) {
 
 	c.JSON(status, map[string]string{
 		"message": message,
-		"url":     DOC_URL,
+		"url":     DocURL,
 	})
 }
 
@@ -90,6 +92,7 @@ func (c *APIContext) SetLinkHeader(total, pageSize int) {
 	}
 }
 
+// APIContexter returns apicontext as macaron middleware
 func APIContexter() macaron.Handler {
 	return func(ctx *Context) {
 		c := &APIContext{

+ 1 - 0
pkg/context/api_org.go

@@ -10,6 +10,7 @@ import (
 	"gitote/gitote/models"
 )
 
+// APIOrganization contains organization and team
 type APIOrganization struct {
 	Organization *models.User
 	Team         *models.Team

+ 3 - 1
pkg/context/auth.go

@@ -18,6 +18,7 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
+// ToggleOptions contains required or check options
 type ToggleOptions struct {
 	SignInRequired  bool
 	SignOutRequired bool
@@ -25,6 +26,7 @@ type ToggleOptions struct {
 	DisableCSRF     bool
 }
 
+// Toggle returns toggle options as middleware
 func Toggle(options *ToggleOptions) macaron.Handler {
 	return func(c *Context) {
 		// Cannot view any page before installation.
@@ -42,7 +44,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {
 		}
 
 		// Check non-logged users landing page.
-		if !c.IsLogged && c.Req.RequestURI == "/" && setting.LandingPageURL != setting.LANDING_PAGE_HOME {
+		if !c.IsLogged && c.Req.RequestURI == "/" && setting.LandingPageURL != setting.LandingPageHome {
 			c.Redirect(setting.AppSubURL + string(setting.LandingPageURL))
 			return
 		}

+ 9 - 2
pkg/context/context.go

@@ -63,18 +63,22 @@ func (c *Context) Require(name string) {
 	c.Data["Require"+name] = true
 }
 
+// RequireHighlightJS requires HighlightJS
 func (c *Context) RequireHighlightJS() {
 	c.Require("HighlightJS")
 }
 
+// RequireSimpleMDE requires SimpleMDE
 func (c *Context) RequireSimpleMDE() {
 	c.Require("SimpleMDE")
 }
 
+// RequireAutosize requires Autosize
 func (c *Context) RequireAutosize() {
 	c.Require("Autosize")
 }
 
+// RequireDropzone requires Dropzone
 func (c *Context) RequireDropzone() {
 	c.Require("Dropzone")
 }
@@ -95,8 +99,8 @@ func (c *Context) UserID() int64 {
 	return c.User.ID
 }
 
-// HasError returns true if error occurs in form validation.
-func (c *Context) HasApiError() bool {
+// HasAPIError returns true if error occurs in form validation.
+func (c *Context) HasAPIError() bool {
 	hasErr, ok := c.Data["HasError"]
 	if !ok {
 		return false
@@ -104,6 +108,7 @@ func (c *Context) HasApiError() bool {
 	return hasErr.(bool)
 }
 
+// GetErrMsg returns error message
 func (c *Context) GetErrMsg() string {
 	return c.Data["ErrorMsg"].(string)
 }
@@ -205,10 +210,12 @@ func (c *Context) NotFoundOrServerError(title string, errck func(error) bool, er
 	c.ServerError(title, err)
 }
 
+// HandleText handles HTTP status code
 func (c *Context) HandleText(status int, title string) {
 	c.PlainText(status, []byte(title))
 }
 
+// ServeContent serves content to http request
 func (c *Context) ServeContent(name string, r io.ReadSeeker, params ...interface{}) {
 	modtime := time.Now()
 	for _, p := range params {

+ 3 - 0
pkg/context/org.go

@@ -15,6 +15,7 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
+// Organization contains organization context
 type Organization struct {
 	IsOwner      bool
 	IsMember     bool
@@ -26,6 +27,7 @@ type Organization struct {
 	Team *models.Team
 }
 
+// HandleOrgAssignment handles organization assignment
 func HandleOrgAssignment(c *Context, args ...bool) {
 	var (
 		requireMember     bool
@@ -144,6 +146,7 @@ func HandleOrgAssignment(c *Context, args ...bool) {
 	}
 }
 
+// OrgAssignment returns a macaron middleware to handle organization assignment
 func OrgAssignment(args ...bool) macaron.Handler {
 	return func(c *Context) {
 		HandleOrgAssignment(c, args...)

+ 5 - 1
pkg/context/repo.go

@@ -19,6 +19,7 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
+// PullRequest contains informations to make a pull request
 type PullRequest struct {
 	BaseRepo *models.Repository
 	Allowed  bool
@@ -26,6 +27,7 @@ type PullRequest struct {
 	HeadInfo string // [<user>:]<branch>
 }
 
+// Repository contains information to operate a repository
 type Repository struct {
 	AccessMode   models.AccessMode
 	IsWatching   bool
@@ -106,7 +108,7 @@ func (r *Repository) PullRequestURL(baseBranch, headBranch string) string {
 	return fmt.Sprintf("%s/compare/%s...%s:%s", repoLink, baseBranch, r.Owner.Name, headBranch)
 }
 
-// [0]: issues, [1]: wiki
+// RepoAssignment returns a macaron to handle repository assignment
 func RepoAssignment(pages ...bool) macaron.Handler {
 	return func(c *Context) {
 		var (
@@ -408,6 +410,7 @@ func RepoRef() macaron.Handler {
 	}
 }
 
+// RequireRepoAdmin returns a macaron middleware for requiring repository admin permission
 func RequireRepoAdmin() macaron.Handler {
 	return func(c *Context) {
 		if !c.IsLogged || (!c.Repo.IsAdmin() && !c.User.IsAdmin) {
@@ -417,6 +420,7 @@ func RequireRepoAdmin() macaron.Handler {
 	}
 }
 
+// RequireRepoWriter returns a macaron middleware for requiring repository write to the specify unitType
 func RequireRepoWriter() macaron.Handler {
 	return func(c *Context) {
 		if !c.IsLogged || (!c.Repo.IsWriter() && !c.User.IsAdmin) {

+ 1 - 0
pkg/cron/cron.go

@@ -18,6 +18,7 @@ import (
 
 var c = cron.New()
 
+// NewContext begins cron tasks
 func NewContext() {
 	var (
 		entry *cron.Entry

+ 6 - 2
pkg/form/admin.go

@@ -11,7 +11,8 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
-type AdminCrateUser struct {
+// AdminCreateUser form for admin to create user
+type AdminCreateUser struct {
 	LoginType  string `binding:"Required"`
 	LoginName  string
 	UserName   string `binding:"Required;AlphaDashDot;MaxSize(35)"`
@@ -20,10 +21,12 @@ type AdminCrateUser struct {
 	SendNotify bool
 }
 
-func (f *AdminCrateUser) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
+// Validate validates form fields
+func (f *AdminCreateUser) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// AdminEditUser form for admin to create user
 type AdminEditUser struct {
 	LoginType        string `binding:"Required"`
 	LoginName        string
@@ -64,6 +67,7 @@ type AdminEditUser struct {
 	IsIntern         bool
 }
 
+// Validate validates form fields
 func (f *AdminEditUser) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }

+ 2 - 0
pkg/form/auth.go

@@ -11,6 +11,7 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
+// Authentication form for authentication
 type Authentication struct {
 	ID                int64
 	Type              int    `binding:"Range(2,5)"`
@@ -46,6 +47,7 @@ type Authentication struct {
 	GitHubAPIEndpoint string `form:"github_api_endpoint" binding:"Url"`
 }
 
+// Validate validates fields
 func (f *Authentication) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }

+ 6 - 3
pkg/form/form.go

@@ -17,8 +17,10 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
-const ERR_ALPHA_DASH_DOT_SLASH = "AlphaDashDotSlashError"
+// ErrAlphaDashDotSlash holds AlphaDashDotSlashError
+const ErrAlphaDashDotSlash = "AlphaDashDotSlashError"
 
+// AlphaDashDotSlashPattern holds AlphaDashDotSlashPattern
 var AlphaDashDotSlashPattern = regexp.MustCompile("[^\\d\\w-_\\./]")
 
 func init() {
@@ -29,7 +31,7 @@ func init() {
 		},
 		IsValid: func(errs binding.Errors, name string, v interface{}) (bool, binding.Errors) {
 			if AlphaDashDotSlashPattern.MatchString(fmt.Sprintf("%v", v)) {
-				errs.Add([]string{name}, ERR_ALPHA_DASH_DOT_SLASH, "AlphaDashDotSlash")
+				errs.Add([]string{name}, ErrAlphaDashDotSlash, "AlphaDashDotSlash")
 				return false, errs
 			}
 			return true, errs
@@ -37,6 +39,7 @@ func init() {
 	})
 }
 
+// Form form binding interface
 type Form interface {
 	binding.Validator
 }
@@ -133,7 +136,7 @@ func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaro
 				data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_error")
 			case binding.ERR_ALPHA_DASH_DOT:
 				data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_error")
-			case ERR_ALPHA_DASH_DOT_SLASH:
+			case ErrAlphaDashDotSlash:
 				data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_slash_error")
 			case binding.ERR_SIZE:
 				data["ErrorMsg"] = trName + l.Tr("form.size_error", getSize(field))

+ 6 - 0
pkg/form/org.go

@@ -11,14 +11,17 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
+// CreateOrg represents CreateOrg
 type CreateOrg struct {
 	OrgName string `binding:"Required;AlphaDashDot;MaxSize(35)" locale:"org.org_name_holder"`
 }
 
+// Validate validates fields
 func (f *CreateOrg) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// UpdateOrgSetting holds org settings
 type UpdateOrgSetting struct {
 	Name            string `binding:"Required;AlphaDashDot;MaxSize(35)" locale:"org.org_name_holder"`
 	FullName        string `binding:"MaxSize(100)"`
@@ -29,16 +32,19 @@ type UpdateOrgSetting struct {
 	MaxRepoCreation int
 }
 
+// Validate validates fields
 func (f *UpdateOrgSetting) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// CreateTeam represents CreateTeam
 type CreateTeam struct {
 	TeamName    string `binding:"Required;AlphaDashDot;MaxSize(30)"`
 	Description string `binding:"MaxSize(255)"`
 	Permission  string
 }
 
+// Validate validates fields
 func (f *CreateTeam) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }

+ 55 - 8
pkg/form/repo.go

@@ -16,6 +16,7 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
+// CreateRepo holds CreateRepo
 type CreateRepo struct {
 	UserID      int64  `binding:"Required"`
 	RepoName    string `binding:"Required;AlphaDashDot;MaxSize(100)"`
@@ -27,21 +28,24 @@ type CreateRepo struct {
 	Readme      string
 }
 
+// Validate validates fields
 func (f *CreateRepo) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// MigrateRepo holds MigrateRepo
 type MigrateRepo struct {
 	CloneAddr    string `json:"clone_addr" binding:"Required"`
 	AuthUsername string `json:"auth_username"`
 	AuthPassword string `json:"auth_password"`
-	Uid          int64  `json:"uid" binding:"Required"`
+	UID          int64  `json:"uid" binding:"Required"`
 	RepoName     string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
 	Mirror       bool   `json:"mirror"`
 	Private      bool   `json:"private"`
 	Description  string `json:"description" binding:"MaxSize(512)"`
 }
 
+// Validate validates fields
 func (f *MigrateRepo) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
@@ -74,6 +78,7 @@ func (f MigrateRepo) ParseRemoteAddr(user *models.User) (string, error) {
 	return remoteAddr, nil
 }
 
+// RepoSetting holds RepoSetting
 type RepoSetting struct {
 	RepoName      string `binding:"Required;AlphaDashDot;MaxSize(100)"`
 	Description   string `binding:"MaxSize(512)"`
@@ -103,10 +108,12 @@ type RepoSetting struct {
 	PullsAllowRebase      bool
 }
 
+// Validate validates fields
 func (f *RepoSetting) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// ProtectBranch holds ProtectBranch
 type ProtectBranch struct {
 	Protected          bool
 	RequirePullRequest bool
@@ -115,10 +122,12 @@ type ProtectBranch struct {
 	WhitelistTeams     string
 }
 
+// Validate validates fields
 func (f *ProtectBranch) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// Webhook holds Webhook
 type Webhook struct {
 	Events       string
 	Create       bool
@@ -132,18 +141,22 @@ type Webhook struct {
 	Active       bool
 }
 
+// PushOnly returns push_only
 func (f Webhook) PushOnly() bool {
 	return f.Events == "push_only"
 }
 
+// SendEverything returns send_everything
 func (f Webhook) SendEverything() bool {
 	return f.Events == "send_everything"
 }
 
+// ChooseEvents returns choose_events
 func (f Webhook) ChooseEvents() bool {
 	return f.Events == "choose_events"
 }
 
+// NewWebhook holds NewWebhook
 type NewWebhook struct {
 	PayloadURL  string `binding:"Required;Url"`
 	ContentType int    `binding:"Required"`
@@ -151,10 +164,12 @@ type NewWebhook struct {
 	Webhook
 }
 
+// Validate validates fields
 func (f *NewWebhook) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// NewSlackHook holds NewSlackHook
 type NewSlackHook struct {
 	PayloadURL string `binding:"Required;Url"`
 	Channel    string `binding:"Required"`
@@ -164,10 +179,12 @@ type NewSlackHook struct {
 	Webhook
 }
 
+// Validate validates fields
 func (f *NewSlackHook) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// NewDiscordHook holds NewDiscordHook
 type NewDiscordHook struct {
 	PayloadURL string `binding:"Required;Url"`
 	Username   string
@@ -176,10 +193,12 @@ type NewDiscordHook struct {
 	Webhook
 }
 
+// Validate validates fields
 func (f *NewDiscordHook) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// NewIssue holds NewIssue
 type NewIssue struct {
 	Title       string `binding:"Required;MaxSize(255)"`
 	LabelIDs    string `form:"label_ids"`
@@ -189,48 +208,58 @@ type NewIssue struct {
 	Files       []string
 }
 
+// Validate validates fields
 func (f *NewIssue) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// CreateComment holds CreateComment
 type CreateComment struct {
 	Content string
 	Status  string `binding:"OmitEmpty;In(reopen,close)"`
 	Files   []string
 }
 
+// Validate validates fields
 func (f *CreateComment) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// CreateMilestone holds CreateMilestone
 type CreateMilestone struct {
 	Title    string `binding:"Required;MaxSize(50)"`
 	Content  string
 	Deadline string
 }
 
+// Validate validates fields
 func (f *CreateMilestone) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// CreateLabel holds CreateLabel
 type CreateLabel struct {
 	ID    int64
 	Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
 	Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
 }
 
+// Validate validates fields
 func (f *CreateLabel) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// InitializeLabels holds InitializeLabels
 type InitializeLabels struct {
 	TemplateName string `binding:"Required"`
 }
 
+// Validate validates fields
 func (f *InitializeLabels) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// NewRelease holds NewRelease
 type NewRelease struct {
 	TagName    string `binding:"Required"`
 	Target     string `form:"tag_target" binding:"Required"`
@@ -241,10 +270,12 @@ type NewRelease struct {
 	Files      []string
 }
 
+// Validate validates fields
 func (f *NewRelease) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// EditRelease holds EditRelease
 type EditRelease struct {
 	Title      string `binding:"Required"`
 	Content    string
@@ -253,10 +284,12 @@ type EditRelease struct {
 	Files      []string
 }
 
+// Validate validates fields
 func (f *EditRelease) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// NewWiki holds NewWiki
 type NewWiki struct {
 	OldTitle string
 	Title    string `binding:"Required"`
@@ -264,73 +297,87 @@ type NewWiki struct {
 	Message  string
 }
 
+// Validate validates fields
 // FIXME: use code generation to generate this method.
 func (f *NewWiki) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// EditRepoFile holds EditRepoFile
 type EditRepoFile struct {
 	TreePath      string `binding:"Required;MaxSize(500)"`
 	Content       string `binding:"Required"`
-	CommitSummary string `binding:"MaxSize(100)`
+	CommitSummary string `binding:"MaxSize(100)"`
 	CommitMessage string
 	CommitChoice  string `binding:"Required;MaxSize(50)"`
 	NewBranchName string `binding:"AlphaDashDotSlash;MaxSize(100)"`
 	LastCommit    string
 }
 
+// Validate validates fields
 func (f *EditRepoFile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
-func (f *EditRepoFile) IsNewBrnach() bool {
+// IsNewBranch returns commit-to-new-branch
+func (f *EditRepoFile) IsNewBranch() bool {
 	return f.CommitChoice == "commit-to-new-branch"
 }
 
+// EditPreviewDiff holds EditPreviewDiff
 type EditPreviewDiff struct {
 	Content string
 }
 
+// Validate validates fields
 func (f *EditPreviewDiff) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// UploadRepoFile holds UploadRepoFile
 type UploadRepoFile struct {
-	TreePath      string `binding:MaxSize(500)"`
-	CommitSummary string `binding:"MaxSize(100)`
+	TreePath      string `binding:"MaxSize(500)"`
+	CommitSummary string `binding:"MaxSize(100)"`
 	CommitMessage string
 	CommitChoice  string `binding:"Required;MaxSize(50)"`
 	NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
 	Files         []string
 }
 
+// Validate validates fields
 func (f *UploadRepoFile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
-func (f *UploadRepoFile) IsNewBrnach() bool {
+// IsNewBranch returns commit-to-new-branch
+func (f *UploadRepoFile) IsNewBranch() bool {
 	return f.CommitChoice == "commit-to-new-branch"
 }
 
+// RemoveUploadFile holds RemoveUploadFile
 type RemoveUploadFile struct {
 	File string `binding:"Required;MaxSize(50)"`
 }
 
+// Validate validates fields
 func (f *RemoveUploadFile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// DeleteRepoFile holds DeleteRepoFile
 type DeleteRepoFile struct {
-	CommitSummary string `binding:"MaxSize(100)`
+	CommitSummary string `binding:"MaxSize(100)"`
 	CommitMessage string
 	CommitChoice  string `binding:"Required;MaxSize(50)"`
 	NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
 }
 
+// Validate validates fields
 func (f *DeleteRepoFile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
-func (f *DeleteRepoFile) IsNewBrnach() bool {
+// IsNewBranch returns commit-to-new-branch
+func (f *DeleteRepoFile) IsNewBranch() bool {
 	return f.CommitChoice == "commit-to-new-branch"
 }

+ 23 - 3
pkg/form/user.go

@@ -13,6 +13,7 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
+// Install form for installation page
 type Install struct {
 	DbType   string `binding:"Required"`
 	DbHost   string
@@ -28,7 +29,7 @@ type Install struct {
 	SSHPort             int
 	UseBuiltinSSHServer bool
 	HTTPPort            string `binding:"Required"`
-	AppUrl              string `binding:"Required"`
+	AppURL              string `binding:"Required"`
 	LogRootPath         string `binding:"Required"`
 	EnableConsoleMode   bool
 
@@ -52,10 +53,12 @@ type Install struct {
 	AdminEmail         string `binding:"OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
 }
 
+// Validate validates fields
 func (f *Install) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// Register form for registering
 type Register struct {
 	UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
 	Email    string `binding:"Required;Email;MaxSize(254)"`
@@ -63,10 +66,12 @@ type Register struct {
 	Retype   string
 }
 
+// Validate validates fields
 func (f *Register) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// SignIn form for signing in with user/password
 type SignIn struct {
 	UserName    string `binding:"Required;MaxSize(254)"`
 	Password    string `binding:"Required;MaxSize(255)"`
@@ -74,10 +79,12 @@ type SignIn struct {
 	Remember    bool
 }
 
+// Validate validates fields
 func (f *SignIn) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// UpdateProfile form for updating profile
 type UpdateProfile struct {
 	Name           string `binding:"Required;AlphaDashDot;MaxSize(35)"`
 	FullName       string `binding:"MaxSize(100)"`
@@ -94,6 +101,7 @@ type UpdateProfile struct {
 	PrivateProfile bool
 }
 
+// UpdateSocial form for updating social
 type UpdateSocial struct {
 	Twitter       string `binding:"MaxSize(50)"`
 	Linkedin      string `binding:"MaxSize(50)"`
@@ -106,15 +114,18 @@ type UpdateSocial struct {
 	Gitlab        string `binding:"MaxSize(50)"`
 }
 
+// Validate validates fields
 func (f *UpdateProfile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// Avatar types
 const (
-	AVATAR_LOCAL  string = "local"
-	AVATAR_BYMAIL string = "bymail"
+	AvatarLocal  string = "local"
+	AvatarByMail string = "bymail"
 )
 
+// Avatar form for changing avatar
 type Avatar struct {
 	Source      string
 	Avatar      *multipart.FileHeader
@@ -122,41 +133,50 @@ type Avatar struct {
 	Federavatar bool
 }
 
+// Validate validates fields
 func (f *Avatar) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// AddEmail form for adding new email
 type AddEmail struct {
 	Email string `binding:"Required;Email;MaxSize(254)"`
 }
 
+// Validate validates fields
 func (f *AddEmail) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// ChangePassword form for changing password
 type ChangePassword struct {
 	OldPassword string `binding:"Required;MinSize(1);MaxSize(255)"`
 	Password    string `binding:"Required;MaxSize(255)"`
 	Retype      string
 }
 
+// Validate validates fields
 func (f *ChangePassword) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// AddSSHKey form for adding SSH key
 type AddSSHKey struct {
 	Title   string `binding:"Required;MaxSize(50)"`
 	Content string `binding:"Required"`
 }
 
+// Validate validates fields
 func (f *AddSSHKey) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }
 
+// NewAccessToken form for creating access token
 type NewAccessToken struct {
 	Name string `binding:"Required"`
 }
 
+// Validate validates fields
 func (f *NewAccessToken) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
 	return validate(errs, ctx.Data, f, ctx.Locale)
 }

+ 17 - 14
pkg/httplib/httplib.go

@@ -39,7 +39,7 @@ func createDefaultCookie() {
 	defaultCookieJar, _ = cookiejar.New(nil)
 }
 
-// Overwrite default settings
+// SetDefaultSetting Overwrite default settings
 func SetDefaultSetting(setting Settings) {
 	settingMutex.Lock()
 	defer settingMutex.Unlock()
@@ -90,18 +90,19 @@ func Head(url string) *Request {
 	return newRequest(url, "HEAD")
 }
 
+// Settings is the default settings for http client
 type Settings struct {
 	ShowDebug        bool
 	UserAgent        string
 	ConnectTimeout   time.Duration
 	ReadWriteTimeout time.Duration
-	TlsClientConfig  *tls.Config
+	TLSClientConfig  *tls.Config
 	Proxy            func(*http.Request) (*url.URL, error)
 	Transport        http.RoundTripper
 	EnableCookie     bool
 }
 
-// HttpRequest provides more useful methods for requesting one url than http.Request.
+// Request provides more useful methods for requesting one url than http.Request.
 type Request struct {
 	url     string
 	req     *http.Request
@@ -112,7 +113,7 @@ type Request struct {
 	body    []byte
 }
 
-// Change request settings
+// Setting change request settings
 func (r *Request) Setting(setting Settings) *Request {
 	r.setting = setting
 	return r
@@ -151,7 +152,7 @@ func (r *Request) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *Re
 
 // SetTLSClientConfig sets tls connection configurations if visiting https url.
 func (r *Request) SetTLSClientConfig(config *tls.Config) *Request {
-	r.setting.TlsClientConfig = config
+	r.setting.TLSClientConfig = config
 	return r
 }
 
@@ -161,11 +162,12 @@ func (r *Request) Header(key, value string) *Request {
 	return r
 }
 
+// Headers returns headers in request.
 func (r *Request) Headers() http.Header {
 	return r.req.Header
 }
 
-// Set the protocol version for incoming requests.
+// SetProtocolVersion set the protocol version for incoming requests.
 // Client requests always use HTTP/1.1.
 func (r *Request) SetProtocolVersion(vers string) *Request {
 	if len(vers) == 0 {
@@ -188,13 +190,13 @@ func (r *Request) SetCookie(cookie *http.Cookie) *Request {
 	return r
 }
 
-// Set transport to
+// SetTransport sets transport to
 func (r *Request) SetTransport(transport http.RoundTripper) *Request {
 	r.setting.Transport = transport
 	return r
 }
 
-// Set http proxy
+// SetProxy sets http proxy
 // example:
 //
 //	func(req *http.Request) (*url.URL, error) {
@@ -213,6 +215,7 @@ func (r *Request) Param(key, value string) *Request {
 	return r
 }
 
+// PostFile uploads file via http
 func (r *Request) PostFile(formname, filename string) *Request {
 	r.files[formname] = filename
 	return r
@@ -307,7 +310,7 @@ func (r *Request) getResponse() (*http.Response, error) {
 	if trans == nil {
 		// create default transport
 		trans = &http.Transport{
-			TLSClientConfig: r.setting.TlsClientConfig,
+			TLSClientConfig: r.setting.TLSClientConfig,
 			Proxy:           r.setting.Proxy,
 			Dial:            TimeoutDialer(r.setting.ConnectTimeout, r.setting.ReadWriteTimeout),
 		}
@@ -315,7 +318,7 @@ func (r *Request) getResponse() (*http.Response, error) {
 		// if r.transport is *http.Transport then set the settings.
 		if t, ok := trans.(*http.Transport); ok {
 			if t.TLSClientConfig == nil {
-				t.TLSClientConfig = r.setting.TlsClientConfig
+				t.TLSClientConfig = r.setting.TLSClientConfig
 			}
 			if t.Proxy == nil {
 				t.Proxy = r.setting.Proxy
@@ -415,9 +418,9 @@ func (r *Request) ToFile(filename string) error {
 	return err
 }
 
-// ToJson returns the map that marshals from the body bytes as json in response .
+// ToJSON returns the map that marshals from the body bytes as json in response .
 // it calls Response inner.
-func (r *Request) ToJson(v interface{}) error {
+func (r *Request) ToJSON(v interface{}) error {
 	data, err := r.Bytes()
 	if err != nil {
 		return err
@@ -425,9 +428,9 @@ func (r *Request) ToJson(v interface{}) error {
 	return jsoniter.Unmarshal(data, v)
 }
 
-// ToXml returns the map that marshals from the body bytes as xml in response .
+// ToXML returns the map that marshals from the body bytes as xml in response .
 // it calls Response inner.
-func (r *Request) ToXml(v interface{}) error {
+func (r *Request) ToXML(v interface{}) error {
 	data, err := r.Bytes()
 	if err != nil {
 		return err

+ 25 - 21
pkg/mailer/mail.go

@@ -18,24 +18,25 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
+// Stores mail templates
 const (
-	MAIL_AUTH_ACTIVATE        = "auth/activate"
-	MAIL_AUTH_ACTIVATE_EMAIL  = "auth/activate_email"
-	MAIL_AUTH_RESET_PASSWORD  = "auth/reset_passwd"
-	MAIL_AUTH_REGISTER_NOTIFY = "auth/register_notify"
-
-	MAIL_ISSUE_COMMENT = "issue/comment"
-	MAIL_ISSUE_MENTION = "issue/mention"
-
-	MAIL_NOTIFY_COLLABORATOR = "notify/collaborator"
+	MailAuthActivate       = "auth/activate"
+	MailAuthActivateEmail  = "auth/activate_email"
+	MailAuthResetPassword  = "auth/reset_passwd"
+	MailAuthRegisterNotify = "auth/register_notify"
+	MailIssueComment       = "issue/comment"
+	MailIssueMention       = "issue/mention"
+	MailNotifyCollaborator = "notify/collaborator"
 )
 
+// MailRender holds MailRender
 type MailRender interface {
 	HTMLString(string, interface{}, ...macaron.HTMLOptions) (string, error)
 }
 
 var mailRender MailRender
 
+// InitMailRender initializes the macaron mail renderer
 func InitMailRender(dir, appendDir string, funcMap []template.FuncMap) {
 	opt := &macaron.RenderOptions{
 		Directory:         dir,
@@ -52,14 +53,12 @@ func InitMailRender(dir, appendDir string, funcMap []template.FuncMap) {
 	}
 }
 
+// SendTestMail sends a test mail
 func SendTestMail(email string) error {
 	return gomail.Send(&Sender{}, NewMessage([]string{email}, "Gitote Test Email!", "Gitote Test Email!").Message)
 }
 
-/*
-	Setup interfaces of used methods in mail to avoid cycle import.
-*/
-
+// User holds user details
 type User interface {
 	ID() int64
 	DisplayName() string
@@ -68,18 +67,21 @@ type User interface {
 	GenerateEmailActivateCode(string) string
 }
 
+// Repository holds repository details
 type Repository interface {
 	FullName() string
 	HTMLURL() string
 	ComposeMetas() map[string]string
 }
 
+// Issue holds issue details
 type Issue interface {
 	MailSubject() string
 	Content() string
 	HTMLURL() string
 }
 
+// SendUserMail sends a mail to the user
 func SendUserMail(c *macaron.Context, u User, tpl, code, subject, info string) {
 	data := map[string]interface{}{
 		"Username":          u.DisplayName(),
@@ -100,15 +102,17 @@ func SendUserMail(c *macaron.Context, u User, tpl, code, subject, info string) {
 	Send(msg)
 }
 
+// SendActivateAccountMail sends an activation mail to the user (new user registration)
 func SendActivateAccountMail(c *macaron.Context, u User) {
-	SendUserMail(c, u, MAIL_AUTH_ACTIVATE, u.GenerateActivateCode(), c.Tr("mail.activate_account"), "activate account")
+	SendUserMail(c, u, MailAuthActivate, u.GenerateActivateCode(), c.Tr("mail.activate_account"), "activate account")
 }
 
+// SendResetPasswordMail sends a password reset mail to the user
 func SendResetPasswordMail(c *macaron.Context, u User) {
-	SendUserMail(c, u, MAIL_AUTH_RESET_PASSWORD, u.GenerateActivateCode(), c.Tr("mail.reset_password"), "reset password")
+	SendUserMail(c, u, MailAuthResetPassword, u.GenerateActivateCode(), c.Tr("mail.reset_password"), "reset password")
 }
 
-// SendActivateAccountMail sends confirmation email.
+// SendActivateEmailMail sends confirmation email.
 func SendActivateEmailMail(c *macaron.Context, u User, email string) {
 	data := map[string]interface{}{
 		"Username":        u.DisplayName(),
@@ -116,7 +120,7 @@ func SendActivateEmailMail(c *macaron.Context, u User, email string) {
 		"Code":            u.GenerateEmailActivateCode(email),
 		"Email":           email,
 	}
-	body, err := mailRender.HTMLString(string(MAIL_AUTH_ACTIVATE_EMAIL), data)
+	body, err := mailRender.HTMLString(string(MailAuthActivateEmail), data)
 	if err != nil {
 		raven.CaptureErrorAndWait(err, nil)
 		log.Error(3, "HTMLString: %v", err)
@@ -134,7 +138,7 @@ func SendRegisterNotifyMail(c *macaron.Context, u User) {
 	data := map[string]interface{}{
 		"Username": u.DisplayName(),
 	}
-	body, err := mailRender.HTMLString(string(MAIL_AUTH_REGISTER_NOTIFY), data)
+	body, err := mailRender.HTMLString(string(MailAuthRegisterNotify), data)
 	if err != nil {
 		raven.CaptureErrorAndWait(err, nil)
 		log.Error(3, "HTMLString: %v", err)
@@ -156,7 +160,7 @@ func SendCollaboratorMail(u, doer User, repo Repository) {
 		"RepoName": repo.FullName(),
 		"Link":     repo.HTMLURL(),
 	}
-	body, err := mailRender.HTMLString(string(MAIL_NOTIFY_COLLABORATOR), data)
+	body, err := mailRender.HTMLString(string(MailNotifyCollaborator), data)
 	if err != nil {
 		raven.CaptureErrorAndWait(err, nil)
 		log.Error(3, "HTMLString: %v", err)
@@ -199,7 +203,7 @@ func SendIssueCommentMail(issue Issue, repo Repository, doer User, tos []string)
 		return
 	}
 
-	Send(composeIssueMessage(issue, repo, doer, MAIL_ISSUE_COMMENT, tos, "issue comment"))
+	Send(composeIssueMessage(issue, repo, doer, MailIssueComment, tos, "issue comment"))
 }
 
 // SendIssueMentionMail composes and sends issue mention emails to target receivers.
@@ -207,5 +211,5 @@ func SendIssueMentionMail(issue Issue, repo Repository, doer User, tos []string)
 	if len(tos) == 0 {
 		return
 	}
-	Send(composeIssueMessage(issue, repo, doer, MAIL_ISSUE_MENTION, tos, "issue mention"))
+	Send(composeIssueMessage(issue, repo, doer, MailIssueMention, tos, "issue mention"))
 }

+ 4 - 1
pkg/mailer/mailer.go

@@ -23,6 +23,7 @@ import (
 	"gopkg.in/gomail.v2"
 )
 
+// Message holds message
 type Message struct {
 	Info string // Message information for log purpose.
 	*gomail.Message
@@ -75,7 +76,7 @@ type loginAuth struct {
 	username, password string
 }
 
-// SMTP AUTH LOGIN Auth Handler
+// LoginAuth SMTP AUTH LOGIN Auth Handler
 func LoginAuth(username, password string) smtp.Auth {
 	return &loginAuth{username, password}
 }
@@ -98,9 +99,11 @@ func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
 	return nil, nil
 }
 
+// Sender holds sender
 type Sender struct {
 }
 
+// Send sends the email
 func (s *Sender) Send(from string, to []string, msg io.WriterTo) error {
 	opts := setting.MailService
 

+ 1 - 1
pkg/markup/markdown.go

@@ -164,5 +164,5 @@ func RawMarkdown(body []byte, urlPrefix string) []byte {
 
 // Markdown takes a string or []byte and renders to HTML in Markdown syntax with special links.
 func Markdown(input interface{}, urlPrefix string, metas map[string]string) []byte {
-	return Render(MARKDOWN, input, urlPrefix, metas)
+	return Render(MarkdownMP, input, urlPrefix, metas)
 }

+ 10 - 10
pkg/markup/markup.go

@@ -312,23 +312,23 @@ type Type string
 
 // Markup
 const (
-	UNRECOGNIZED     Type = "unrecognized"
-	MARKDOWN         Type = "markdown"
-	ORG_MODE         Type = "orgmode"
-	IPYTHON_NOTEBOOK Type = "ipynb"
+	UnrecognizedMP    Type = "unrecognized"
+	MarkdownMP        Type = "markdown"
+	OrgModeMP         Type = "orgmode"
+	IPythonNotebookMP Type = "ipynb"
 )
 
 // Detect returns best guess of a markup type based on file name.
 func Detect(filename string) Type {
 	switch {
 	case IsMarkdownFile(filename):
-		return MARKDOWN
+		return MarkdownMP
 	case IsOrgModeFile(filename):
-		return ORG_MODE
+		return OrgModeMP
 	case IsIPythonNotebook(filename):
-		return IPYTHON_NOTEBOOK
+		return IPythonNotebookMP
 	default:
-		return UNRECOGNIZED
+		return UnrecognizedMP
 	}
 }
 
@@ -347,9 +347,9 @@ func Render(typ Type, input interface{}, urlPrefix string, metas map[string]stri
 	urlPrefix = strings.TrimRight(strings.Replace(urlPrefix, " ", "%20", -1), "/")
 	var rawHTML []byte
 	switch typ {
-	case MARKDOWN:
+	case MarkdownMP:
 		rawHTML = RawMarkdown(rawBytes, urlPrefix)
-	case ORG_MODE:
+	case OrgModeMP:
 		rawHTML = RawOrgMode(rawBytes, urlPrefix)
 	default:
 		return rawBytes // Do nothing if syntax type is not recognized

+ 1 - 1
pkg/markup/orgmode.go

@@ -41,5 +41,5 @@ func RawOrgMode(body []byte, urlPrefix string) (result []byte) {
 
 // OrgMode takes a string or []byte and renders to HTML in Org-mode syntax with special links.
 func OrgMode(input interface{}, urlPrefix string, metas map[string]string) []byte {
-	return Render(ORG_MODE, input, urlPrefix, metas)
+	return Render(OrgModeMP, input, urlPrefix, metas)
 }

+ 8 - 4
pkg/process/manager.go

@@ -19,10 +19,12 @@ import (
 )
 
 var (
+	// ErrExecTimeout represent a timeout error
 	ErrExecTimeout = errors.New("Process execution timeout")
 )
 
-const DEFAULT_TIMEOUT = 60 * time.Second
+// DefaultTimeout is 60 * time.Second
+const DefaultTimeout = 60 * time.Second
 
 // Process represents a running process calls shell command.
 type Process struct {
@@ -45,6 +47,8 @@ func (c *pidCounter) PID() int64 {
 }
 
 var counter = new(pidCounter)
+
+// Processes list
 var Processes []*Process
 
 // Add adds a process to global list and returns its PID.
@@ -77,10 +81,10 @@ func Remove(pid int64) bool {
 	return false
 }
 
-// Exec starts executing a shell command in given path, it tracks corresponding process and timeout.
+// ExecDir starts executing a shell command in given path, it tracks corresponding process and timeout.
 func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (string, string, error) {
 	if timeout == -1 {
-		timeout = DEFAULT_TIMEOUT
+		timeout = DefaultTimeout
 	}
 
 	bufOut := new(bytes.Buffer)
@@ -116,7 +120,7 @@ func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (
 	return bufOut.String(), bufErr.String(), err
 }
 
-// Exec starts executing a shell command, it tracks corresponding process and timeout.
+// ExecTimeout starts executing a shell command, it tracks corresponding process and timeout.
 func ExecTimeout(timeout time.Duration, desc, cmdName string, args ...string) (string, string, error) {
 	return ExecDir(timeout, "", desc, cmdName, args...)
 }

+ 28 - 12
pkg/setting/setting.go

@@ -22,9 +22,16 @@ import (
 	"time"
 
 	raven "github.com/getsentry/raven-go"
+
+	// memcache plugin for cache
 	_ "github.com/go-macaron/cache/memcache"
+
+	// redis plugin for cache
 	_ "github.com/go-macaron/cache/redis"
+
 	"github.com/go-macaron/session"
+
+	// redis plugin for store session
 	_ "github.com/go-macaron/session/redis"
 	"github.com/mcuadros/go-version"
 	"gitlab.com/gitote/com"
@@ -33,22 +40,27 @@ import (
 	"gopkg.in/ini.v1"
 )
 
+// Scheme describes protocol types
 type Scheme string
 
+// enumerates all the scheme types
 const (
-	SCHEME_HTTP        Scheme = "http"
-	SCHEME_HTTPS       Scheme = "https"
-	SCHEME_FCGI        Scheme = "fcgi"
-	SCHEME_UNIX_SOCKET Scheme = "unix"
+	SchemeHTTP       Scheme = "http"
+	SchemeHTTPS      Scheme = "https"
+	SchemeFCGI       Scheme = "fcgi"
+	SchemeUnixSocket Scheme = "unix"
 )
 
+// LandingPage describes the default page
 type LandingPage string
 
+// enumerates all the landing page types
 const (
-	LANDING_PAGE_HOME    LandingPage = "/"
-	LANDING_PAGE_EXPLORE LandingPage = "/explore"
+	LandingPageHome    LandingPage = "/"
+	LandingPageExplore LandingPage = "/explore"
 )
 
+// Holds all platform settings
 var (
 	// Build information should only be set by -ldflags.
 	BuildTime    string
@@ -469,16 +481,16 @@ func NewContext() {
 	AppSubURLDepth = strings.Count(AppSubURL, "/")
 	HostAddress = url.Host
 
-	Protocol = SCHEME_HTTP
+	Protocol = SchemeHTTP
 	if sec.Key("PROTOCOL").String() == "https" {
-		Protocol = SCHEME_HTTPS
+		Protocol = SchemeHTTPS
 		CertFile = sec.Key("CERT_FILE").String()
 		KeyFile = sec.Key("KEY_FILE").String()
 		TLSMinVersion = sec.Key("TLS_MIN_VERSION").String()
 	} else if sec.Key("PROTOCOL").String() == "fcgi" {
-		Protocol = SCHEME_FCGI
+		Protocol = SchemeFCGI
 	} else if sec.Key("PROTOCOL").String() == "unix" {
-		Protocol = SCHEME_UNIX_SOCKET
+		Protocol = SchemeUnixSocket
 		UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666")
 		UnixSocketPermissionParsed, err := strconv.ParseUint(UnixSocketPermissionRaw, 8, 32)
 		if err != nil || UnixSocketPermissionParsed > 0777 {
@@ -499,9 +511,9 @@ func NewContext() {
 
 	switch sec.Key("LANDING_PAGE").MustString("home") {
 	case "explore":
-		LandingPageURL = LANDING_PAGE_EXPLORE
+		LandingPageURL = LandingPageExplore
 	default:
-		LandingPageURL = LANDING_PAGE_HOME
+		LandingPageURL = LandingPageHome
 	}
 
 	SSH.RootPath = path.Join(homeDir, ".ssh")
@@ -721,6 +733,7 @@ func NewContext() {
 	HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))
 }
 
+// Service settings
 var Service struct {
 	ActiveCodeLives                int
 	ResetPwdCodeLives              int
@@ -886,6 +899,7 @@ type Mailer struct {
 }
 
 var (
+	// MailService the global mailer
 	MailService *Mailer
 )
 
@@ -957,10 +971,12 @@ func newNotifyMailService() {
 	log.Info("Notify Mail Service Enabled")
 }
 
+// NewService initializes the newService
 func NewService() {
 	newService()
 }
 
+// NewServices initializes the services
 func NewServices() {
 	newService()
 	newLogService()

+ 1 - 0
pkg/template/highlight/highlight.go

@@ -68,6 +68,7 @@ var (
 	}
 )
 
+// NewContext for highlight.mapping
 func NewContext() {
 	keys := setting.Cfg.Section("highlight.mapping").Keys()
 	for i := range keys {

+ 4 - 0
pkg/tool/file.go

@@ -21,18 +21,22 @@ func IsTextFile(data []byte) bool {
 	return strings.Contains(http.DetectContentType(data), "text/")
 }
 
+// IsImageFile detects if data is an image format
 func IsImageFile(data []byte) bool {
 	return strings.Contains(http.DetectContentType(data), "image/")
 }
 
+// IsPDFFile detects if data is a pdf format
 func IsPDFFile(data []byte) bool {
 	return strings.Contains(http.DetectContentType(data), "application/pdf")
 }
 
+// IsVideoFile detects if data is an video format
 func IsVideoFile(data []byte) bool {
 	return strings.Contains(http.DetectContentType(data), "video/")
 }
 
+// hold memory types
 const (
 	Byte  = 1
 	KByte = Byte * 1024

+ 0 - 1
pkg/tool/path.go

@@ -14,7 +14,6 @@ import (
 // IsSameSiteURLPath returns true if the URL path belongs to the same site, false otherwise.
 // False: //url, http://url, /\url
 // True: /url
-
 func IsSameSiteURLPath(url string) bool {
 	return len(url) >= 2 && url[0] == '/' && url[1] != '/' && url[1] != '\\'
 }

+ 6 - 5
pkg/tool/tool.go

@@ -126,7 +126,7 @@ func randomInt(max *big.Int) (int, error) {
 	return int(rand.Int64()), nil
 }
 
-// verify time limit code
+// VerifyTimeLimitCode verify time limit code
 func VerifyTimeLimitCode(data string, minutes int, code string) bool {
 	if len(code) <= 18 {
 		return false
@@ -153,7 +153,8 @@ func VerifyTimeLimitCode(data string, minutes int, code string) bool {
 	return false
 }
 
-const TIME_LIMIT_CODE_LENGTH = 12 + 6 + 40
+// TimeLimitCodeLength default value for time limit code
+const TimeLimitCodeLength = 12 + 6 + 40
 
 // CreateTimeLimitCode generates a time limit code based on given input data.
 // Format: 12 length date time string + 6 minutes string + 40 sha1 encoded string
@@ -363,6 +364,7 @@ func timeSince(then time.Time, lang string) string {
 	}
 }
 
+// RawTimeSince retrieves i18n key of time since t
 func RawTimeSince(t time.Time, lang string) string {
 	return timeSince(t, lang)
 }
@@ -376,7 +378,7 @@ func TimeSince(t time.Time, lang string) template.HTML {
 func Subtract(left interface{}, right interface{}) interface{} {
 	var rleft, rright int64
 	var fleft, fright float64
-	var isInt bool = true
+	var isInt = true
 	switch left.(type) {
 	case int:
 		rleft = int64(left.(int))
@@ -417,9 +419,8 @@ func Subtract(left interface{}, right interface{}) interface{} {
 
 	if isInt {
 		return rleft - rright
-	} else {
-		return fleft + float64(rleft) - (fright + float64(rright))
 	}
+	return fleft + float64(rleft) - (fright + float64(rright))
 }
 
 // EllipsisString returns a truncated short string,

+ 1 - 0
pkg/user/user.go

@@ -10,6 +10,7 @@ import (
 	"os"
 )
 
+// CurrentUsername gets user username
 func CurrentUsername() string {
 	curUserName := os.Getenv("USER")
 	if len(curUserName) > 0 {

+ 5 - 5
routes/admin/auths.go

@@ -63,9 +63,9 @@ var (
 		{models.LoginNames[models.LoginGitHub], models.LoginGitHub},
 	}
 	securityProtocols = []dropdownItem{
-		{models.SecurityProtocolNames[ldap.SECURITY_PROTOCOL_UNENCRYPTED], ldap.SECURITY_PROTOCOL_UNENCRYPTED},
-		{models.SecurityProtocolNames[ldap.SECURITY_PROTOCOL_LDAPS], ldap.SECURITY_PROTOCOL_LDAPS},
-		{models.SecurityProtocolNames[ldap.SECURITY_PROTOCOL_START_TLS], ldap.SECURITY_PROTOCOL_START_TLS},
+		{models.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted], ldap.SecurityProtocolUnencrypted},
+		{models.SecurityProtocolNames[ldap.SecurityProtocolLDAPS], ldap.SecurityProtocolLDAPS},
+		{models.SecurityProtocolNames[ldap.SecurityProtocolStartTLS], ldap.SecurityProtocolStartTLS},
 	}
 )
 
@@ -77,7 +77,7 @@ func NewAuthSource(c *context.Context) {
 
 	c.Data["type"] = models.LoginLDAP
 	c.Data["CurrentTypeName"] = models.LoginNames[models.LoginLDAP]
-	c.Data["CurrentSecurityProtocol"] = models.SecurityProtocolNames[ldap.SECURITY_PROTOCOL_UNENCRYPTED]
+	c.Data["CurrentSecurityProtocol"] = models.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted]
 	c.Data["smtp_auth"] = "PLAIN"
 	c.Data["is_active"] = true
 	c.Data["is_default"] = true
@@ -142,7 +142,7 @@ func NewAuthSourcePost(c *context.Context, f form.Authentication) {
 	switch models.LoginType(f.Type) {
 	case models.LoginLDAP, models.LoginDLDAP:
 		config = parseLDAPConfig(f)
-		hasTLS = ldap.SecurityProtocol(f.SecurityProtocol) > ldap.SECURITY_PROTOCOL_UNENCRYPTED
+		hasTLS = ldap.SecurityProtocol(f.SecurityProtocol) > ldap.SecurityProtocolUnencrypted
 	case models.LoginSMTP:
 		config = parseSMTPConfig(f)
 		hasTLS = true

+ 1 - 1
routes/admin/users.go

@@ -66,7 +66,7 @@ func NewUser(c *context.Context) {
 }
 
 // NewUserPost creates a new user
-func NewUserPost(c *context.Context, f form.AdminCrateUser) {
+func NewUserPost(c *context.Context, f form.AdminCreateUser) {
 	c.Data["Title"] = "Create New Account"
 	c.Data["PageIsAdmin"] = true
 	c.Data["PageIsAdminUsers"] = true

+ 1 - 1
routes/api/v1/misc/markdown.go

@@ -15,7 +15,7 @@ import (
 
 // Markdown render markdown document to HTML
 func Markdown(c *context.APIContext, form api.MarkdownOption) {
-	if c.HasApiError() {
+	if c.HasAPIError() {
 		c.Error(422, "", c.GetErrMsg())
 		return
 	}

+ 2 - 2
routes/api/v1/repo/repo.go

@@ -223,8 +223,8 @@ func Migrate(c *context.APIContext, f form.MigrateRepo) {
 	ctxUser := c.User
 	// Not equal means context user is an organization,
 	// or is another user/organization if current user is admin.
-	if f.Uid != ctxUser.ID {
-		org, err := models.GetUserByID(f.Uid)
+	if f.UID != ctxUser.ID {
+		org, err := models.GetUserByID(f.UID)
 		if err != nil {
 			if errors.IsUserNotExist(err) {
 				c.Error(422, "", err)

+ 5 - 5
routes/install.go

@@ -161,7 +161,7 @@ func Install(c *context.Context) {
 	f.SSHPort = setting.SSH.Port
 	f.UseBuiltinSSHServer = setting.SSH.StartBuiltinServer
 	f.HTTPPort = setting.HTTPPort
-	f.AppUrl = setting.AppURL
+	f.AppURL = setting.AppURL
 	f.LogRootPath = setting.LogRootPath
 
 	// E-mail service settings
@@ -297,8 +297,8 @@ func InstallPost(c *context.Context, f form.Install) {
 		return
 	}
 
-	if f.AppUrl[len(f.AppUrl)-1] != '/' {
-		f.AppUrl += "/"
+	if f.AppURL[len(f.AppURL)-1] != '/' {
+		f.AppURL += "/"
 	}
 
 	// Save settings.
@@ -322,7 +322,7 @@ func InstallPost(c *context.Context, f form.Install) {
 	cfg.Section("").Key("RUN_USER").SetValue(f.RunUser)
 	cfg.Section("server").Key("DOMAIN").SetValue(f.Domain)
 	cfg.Section("server").Key("HTTP_PORT").SetValue(f.HTTPPort)
-	cfg.Section("server").Key("ROOT_URL").SetValue(f.AppUrl)
+	cfg.Section("server").Key("ROOT_URL").SetValue(f.AppURL)
 
 	if f.SSHPort == 0 {
 		cfg.Section("server").Key("DISABLE_SSH").SetValue("true")
@@ -406,5 +406,5 @@ func InstallPost(c *context.Context, f form.Install) {
 
 	log.Info("First-time run install finished!")
 	c.Flash.Success(c.Tr("install.install_success"))
-	c.Redirect(f.AppUrl + "login")
+	c.Redirect(f.AppURL + "login")
 }

+ 1 - 1
routes/org/setting.go

@@ -100,7 +100,7 @@ func SettingsPost(c *context.Context, f form.UpdateOrgSetting) {
 
 // SettingsAvatar updates organization avatar
 func SettingsAvatar(c *context.Context, f form.Avatar) {
-	f.Source = form.AVATAR_LOCAL
+	f.Source = form.AvatarLocal
 
 	// Update avatar
 	if err := user.UpdateAvatarSetting(c, f, c.Org.Organization); err != nil {

+ 6 - 6
routes/repo/editor.go

@@ -149,7 +149,7 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
 	lastCommit := f.LastCommit
 	f.LastCommit = c.Repo.Commit.ID.String()
 
-	if f.IsNewBrnach() {
+	if f.IsNewBranch() {
 		branchName = f.NewBranchName
 	}
 
@@ -294,7 +294,7 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
 		return
 	}
 
-	if f.IsNewBrnach() && c.Repo.PullRequest.Allowed {
+	if f.IsNewBranch() && c.Repo.PullRequest.Allowed {
 		c.Redirect(c.Repo.PullRequestURL(oldBranchName, f.NewBranchName))
 	} else {
 		c.Redirect(c.Repo.RepoLink + "/src/" + branchName + "/" + f.TreePath)
@@ -360,7 +360,7 @@ func DeleteFilePost(c *context.Context, f form.DeleteRepoFile) {
 	oldBranchName := c.Repo.BranchName
 	branchName := oldBranchName
 
-	if f.IsNewBrnach() {
+	if f.IsNewBranch() {
 		branchName = f.NewBranchName
 	}
 	c.Data["commit_summary"] = f.CommitSummary
@@ -402,7 +402,7 @@ func DeleteFilePost(c *context.Context, f form.DeleteRepoFile) {
 		return
 	}
 
-	if f.IsNewBrnach() && c.Repo.PullRequest.Allowed {
+	if f.IsNewBranch() && c.Repo.PullRequest.Allowed {
 		c.Redirect(c.Repo.PullRequestURL(oldBranchName, f.NewBranchName))
 	} else {
 		c.Flash.Success(c.Tr("repo.editor.file_delete_success", c.Repo.TreePath))
@@ -446,7 +446,7 @@ func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
 	oldBranchName := c.Repo.BranchName
 	branchName := oldBranchName
 
-	if f.IsNewBrnach() {
+	if f.IsNewBranch() {
 		branchName = f.NewBranchName
 	}
 
@@ -524,7 +524,7 @@ func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
 		return
 	}
 
-	if f.IsNewBrnach() && c.Repo.PullRequest.Allowed {
+	if f.IsNewBranch() && c.Repo.PullRequest.Allowed {
 		c.Redirect(c.Repo.PullRequestURL(oldBranchName, f.NewBranchName))
 	} else {
 		c.Redirect(c.Repo.RepoLink + "/src/" + branchName + "/" + f.TreePath)

+ 1 - 1
routes/repo/repo.go

@@ -174,7 +174,7 @@ func Migrate(c *context.Context) {
 func MigratePost(c *context.Context, f form.MigrateRepo) {
 	c.Data["Title"] = c.Tr("new_migrate")
 
-	ctxUser := checkContextUser(c, f.Uid)
+	ctxUser := checkContextUser(c, f.UID)
 	if c.Written() {
 		return
 	}

+ 1 - 1
routes/repo/setting.go

@@ -329,7 +329,7 @@ func SettingsAvatar(c *context.Context) {
 
 // SettingsAvatarPost updates avatar settings
 func SettingsAvatarPost(c *context.Context, f form.Avatar) {
-	f.Source = form.AVATAR_LOCAL
+	f.Source = form.AvatarLocal
 	if err := UpdateAvatarSetting(c, f, c.Repo.Repository); err != nil {
 		c.Flash.Error(err.Error())
 	} else {

+ 6 - 6
routes/repo/view.go

@@ -95,13 +95,13 @@ func renderDirectory(c *context.Context, treeLink string) {
 			buf = append(buf, d...)
 
 			switch markup.Detect(readmeFile.Name()) {
-			case markup.MARKDOWN:
+			case markup.MarkdownMP:
 				c.Data["IsMarkdown"] = true
 				buf = markup.Markdown(buf, treeLink, c.Repo.Repository.ComposeMetas())
-			case markup.ORG_MODE:
+			case markup.OrgModeMP:
 				c.Data["IsMarkdown"] = true
 				buf = markup.OrgMode(buf, treeLink, c.Repo.Repository.ComposeMetas())
-			case markup.IPYTHON_NOTEBOOK:
+			case markup.IPythonNotebookMP:
 				c.Data["IsIPythonNotebook"] = true
 				c.Data["RawFileLink"] = c.Repo.RepoLink + "/raw/" + path.Join(c.Repo.BranchName, c.Repo.TreePath, readmeFile.Name())
 			default:
@@ -171,13 +171,13 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 		buf = append(buf, d...)
 
 		switch markup.Detect(blob.Name()) {
-		case markup.MARKDOWN:
+		case markup.MarkdownMP:
 			c.Data["IsMarkdown"] = true
 			c.Data["FileContent"] = string(markup.Markdown(buf, path.Dir(treeLink), c.Repo.Repository.ComposeMetas()))
-		case markup.ORG_MODE:
+		case markup.OrgModeMP:
 			c.Data["IsMarkdown"] = true
 			c.Data["FileContent"] = string(markup.OrgMode(buf, path.Dir(treeLink), c.Repo.Repository.ComposeMetas()))
-		case markup.IPYTHON_NOTEBOOK:
+		case markup.IPythonNotebookMP:
 			c.Data["IsIPythonNotebook"] = true
 		default:
 			// Building code view blocks with line number on server side.

+ 1 - 1
routes/user/setting.go

@@ -222,7 +222,7 @@ func SettingsSocialPost(c *context.Context, f form.UpdateSocial) {
 
 // UpdateAvatarSetting FIXME: limit upload size
 func UpdateAvatarSetting(c *context.Context, f form.Avatar, ctxUser *models.User) error {
-	ctxUser.UseCustomAvatar = f.Source == form.AVATAR_LOCAL
+	ctxUser.UseCustomAvatar = f.Source == form.AvatarLocal
 	if len(f.Gravatar) > 0 {
 		ctxUser.Avatar = tool.MD5(f.Gravatar)
 		ctxUser.AvatarEmail = f.Gravatar