Browse Source

Fmt; Disappeared % format; % format updates; Unkeyed things

Dashie der otter 1 week ago
parent
commit
d73871f155
Signed by: Dashie <dashie@sigpipe.me> GPG Key ID: C2D57B325840B755

+ 37
- 18
Makefile View File

@@ -16,14 +16,16 @@ BUILD_FLAGS:=-o $(EXECUTABLE) -v
16 16
 TAGS=sqlite
17 17
 NOW=$(shell date -u '+%Y%m%d%I%M%S')
18 18
 
19
-GOVET=go vet
20
-GOLINT=golint -set_exit_status
21 19
 GO ?= go
20
+GOVET=$(GO) vet
21
+GOLINT=golint -set_exit_status
22
+GOFMT ?= gofmt -s
22 23
 
23 24
 GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
24 25
 PACKAGES ?= $(filter-out dev.sigpipe.me/dashie/git.txt/integrations,$(shell go list ./... | grep -v /vendor/))
26
+PACKAGES_ALL ?= $(shell go list ./... | grep -v /vendor/)
27
+SOURCES ?= $(shell find . -name "*.go" -type f)
25 28
 XGO_DEPS = "--deps=https://s3.sigpipe.me/tarballs/1-mingw-libgnurx-2.5.1-src.tar.gz https://s3.sigpipe.me/tarballs/2-file-5.32.tar.gz"
26
-#XGO_DEPS += "--deps=https://github.com/libgit2/libgit2/archive/maint/v0.25.zip"
27 29
 
28 30
 ifneq ($(DRONE_TAG),)
29 31
 	VERSION ?= $(subst v,,$(DRONE_TAG))
@@ -35,44 +37,40 @@ else
35 37
 	endif
36 38
 endif
37 39
 
38
-### Targets
40
+### Targets build and checks
39 41
 
40 42
 .PHONY: build clean
41 43
 
42 44
 all: build
43 45
 
44
-check: test
45
-
46 46
 web: build
47 47
 	./$(EXECUTABLE) web
48 48
 
49 49
 vet:
50
-	$(GOVET) git.txt.go
50
+	$(GOVET) $(PACKAGES_ALL)
51 51
 
52 52
 lint:
53 53
 	@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
54 54
 		$(GO) get -u github.com/golang/lint/golint; \
55 55
 	fi
56
-	for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
56
+	for PKG in $(PACKAGES_ALL); do golint -set_exit_status $$PKG || exit 1; done;
57 57
 
58 58
 build:
59 59
 	$(GO) build $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -tags '$(TAGS)'
60 60
 
61
-build-dev: govet
62
-	$(GO) build $(BUILD_FLAGS) -tags '$(TAGS)'
61
+build-dev: vet
62
+	$(GO) build $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -tags '$(TAGS)'
63 63
 
64
-build-dev-race: govet
65
-	$(GO) build $(BUILD_FLAGS) -race -tags '$(TAGS)'
64
+build-dev-race: vet
65
+	$(GO) build $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -race -tags '$(TAGS)'
66 66
 
67
-clean:
67
+clean: clean-mac
68 68
 	$(GO) clean -i ./...
69
+	rm -f $(EXECUTABLE)
69 70
 
70
-clean-mac: clean
71
+clean-mac:
71 72
 	find . -name ".DS_Store" -delete
72 73
 
73
-test:
74
-	$(GO) test -cover -v $(PACKAGES)
75
-
76 74
 .PHONY: misspell-check
77 75
 misspell-check:
78 76
 	@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
@@ -87,8 +85,29 @@ misspell:
87 85
 	fi
88 86
 	misspell -w -i unknwon $(GOFILES)
89 87
 
88
+.PHONY: fmt
89
+fmt:
90
+	$(GOFMT) -w $(GOFILES)
91
+
92
+.PHONY: fmt-check
93
+fmt-check:
94
+	# get all go files and run go fmt on them
95
+	@diff=$$($(GOFMT) -d $(GOFILES)); \
96
+		if [ -n "$$diff" ]; then \
97
+			echo "Please run 'make fmt' and commit the result:"; \
98
+			echo "$${diff}"; \
99
+			exit 1; \
100
+		fi;
101
+
102
+### Targets for tests
103
+# Use PACKAGES instead of PACKAGES_ALL because the integrations tests are run separately
104
+
105
+test: fmt-check
106
+	$(GO) test -cover -v $(PACKAGES)
107
+
108
+### Targets for releases
90 109
 .PHONY: release
91
-release: release-dirs release-windows release-linux release-copy release-check
110
+release: release-dirs release-linux release-copy release-check
92 111
 
93 112
 .PHONY: release-dirs
94 113
 release-dirs:

+ 3
- 0
TODO.org View File

@@ -2,6 +2,9 @@
2 2
 
3 3
 * Ways of improvement
4 4
 ** TODO Merge AssignUser and AssignRepository ?
5
+** blackfriday dependency update to 2.x, breaking changes
6
+** xorm update, breaking changes
7
+*** migrate to gorm ?
5 8
 
6 9
 ** TODO Upgrade git2go to v26 (.3)
7 10
 *** Blocked by https://github.com/libgit2/git2go/issues/407

+ 1
- 1
cmd/cmd.go View File

@@ -34,4 +34,4 @@ func durationFlag(name string, value time.Duration, usage string) cli.DurationFl
34 34
 		Value: value,
35 35
 		Usage: usage,
36 36
 	}
37
-}
37
+}

+ 3
- 3
cmd/web.go View File

@@ -97,7 +97,7 @@ func newMacaron() *macaron.Macaron {
97 97
 
98 98
 	m.Use(toolbox.Toolboxer(m, toolbox.Options{
99 99
 		HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
100
-			&toolbox.HealthCheckFuncDesc{
100
+			{
101 101
 				Desc: "Database connection",
102 102
 				Func: models.Ping,
103 103
 			},
@@ -116,7 +116,7 @@ func runWeb(ctx *cli.Context) error {
116 116
 	}
117 117
 
118 118
 	setting.InitConfig()
119
-	markup.NewSanitizer()
119
+	//markup.NewSanitizer() // IDK what I wanted to do here
120 120
 	models.InitDb()
121 121
 	cron.NewContext()
122 122
 	mailer.NewContext()
@@ -233,7 +233,7 @@ func runWeb(ctx *cli.Context) error {
233 233
 		os.Remove(listenAddr)
234 234
 
235 235
 		var listener *net.UnixListener
236
-		listener, err = net.ListenUnix("unix", &net.UnixAddr{listenAddr, "unix"})
236
+		listener, err = net.ListenUnix("unix", &net.UnixAddr{Name: listenAddr, Net: "unix"})
237 237
 		if err != nil {
238 238
 			break // Handle error after switch
239 239
 		}

+ 6
- 6
context/auth.go View File

@@ -1,11 +1,11 @@
1 1
 package context
2 2
 
3 3
 import (
4
-	"gopkg.in/macaron.v1"
5 4
 	"dev.sigpipe.me/dashie/git.txt/setting"
6 5
 	"github.com/go-macaron/csrf"
7
-	"net/url"
8 6
 	log "gopkg.in/clog.v1"
7
+	"gopkg.in/macaron.v1"
8
+	"net/url"
9 9
 )
10 10
 
11 11
 // ToggleOptions struct
@@ -26,7 +26,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {
26 26
 			return
27 27
 		}
28 28
 
29
-		log.Trace("SignOutRequired: %s, DisableCSRF: %s, Req Method: %s", options.SignOutRequired, options.DisableCSRF, ctx.Req.Method)
29
+		log.Trace("SignOutRequired: %t, DisableCSRF: %t, Req Method: %s", options.SignOutRequired, options.DisableCSRF, ctx.Req.Method)
30 30
 		if !options.SignOutRequired && !options.DisableCSRF && ctx.Req.Method == "POST" {
31 31
 			log.Trace("Validating CSRF")
32 32
 			csrf.Validate(ctx.Context, ctx.csrf)
@@ -37,7 +37,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {
37 37
 
38 38
 		if options.SignInRequired {
39 39
 			if !ctx.IsLogged {
40
-				ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL + ctx.Req.RequestURI), 0, setting.AppSubURL)
40
+				ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
41 41
 				ctx.Redirect(setting.AppSubURL + "/user/login")
42 42
 				return
43 43
 			} else if !ctx.User.IsActive {
@@ -49,7 +49,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {
49 49
 
50 50
 		// Redirect to login page if auto-sign provided and not signed in
51 51
 		if !options.SignOutRequired && !ctx.IsLogged && len(ctx.GetCookie(setting.CookieUserName)) > 0 {
52
-			ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL + ctx.Req.RequestURI), 0, setting.AppSubURL)
52
+			ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
53 53
 			ctx.Redirect(setting.AppSubURL + "/user/login")
54 54
 			return
55 55
 		}
@@ -62,4 +62,4 @@ func Toggle(options *ToggleOptions) macaron.Handler {
62 62
 			ctx.Data["PageIsAdmin"] = true
63 63
 		}
64 64
 	}
65
-}
65
+}

+ 8
- 8
context/repo.go View File

@@ -1,21 +1,21 @@
1 1
 package context
2 2
 
3 3
 import (
4
-	"gopkg.in/macaron.v1"
5 4
 	"dev.sigpipe.me/dashie/git.txt/models"
6 5
 	"dev.sigpipe.me/dashie/git.txt/models/errors"
7
-	"strings"
8 6
 	"dev.sigpipe.me/dashie/git.txt/setting"
9
-	"time"
10 7
 	log "gopkg.in/clog.v1"
8
+	"gopkg.in/macaron.v1"
9
+	"strings"
10
+	"time"
11 11
 )
12 12
 
13 13
 // Gitxt struct
14 14
 type Gitxt struct {
15
-	User	*models.User
16
-	Gitxt	*models.Gitxt
17
-	Owner	bool		// Gitxt.Owner: "toto/repos" does "repos" belongs to "toto" ?
18
-	UserName	string
15
+	User     *models.User
16
+	Gitxt    *models.Gitxt
17
+	Owner    bool // Gitxt.Owner: "toto/repos" does "repos" belongs to "toto" ?
18
+	UserName string
19 19
 }
20 20
 
21 21
 // AssignRepository to context
@@ -64,4 +64,4 @@ func CheckRepoExpiry() macaron.Handler {
64 64
 			return
65 65
 		}
66 66
 	}
67
-}
67
+}

+ 2
- 2
context/user.go View File

@@ -1,9 +1,9 @@
1 1
 package context
2 2
 
3 3
 import (
4
-	"gopkg.in/macaron.v1"
5 4
 	"dev.sigpipe.me/dashie/git.txt/models"
6 5
 	"dev.sigpipe.me/dashie/git.txt/models/errors"
6
+	"gopkg.in/macaron.v1"
7 7
 )
8 8
 
9 9
 // AssignUser to context
@@ -31,4 +31,4 @@ func AssignUser() macaron.Handler {
31 31
 		ctx.Gitxt.User = user
32 32
 		ctx.RepoOwnerUsername = userName
33 33
 	}
34
-}
34
+}

+ 4
- 4
models/counter.go View File

@@ -6,9 +6,9 @@ import (
6 6
 
7 7
 // Counter struct
8 8
 type Counter struct {
9
-	ID		int64	`xorm:"pk autoincr"`
10
-	Name	string	`xorm:"UNIQUE NOT NULL"`
11
-	Count	int64
9
+	ID    int64  `xorm:"pk autoincr"`
10
+	Name  string `xorm:"UNIQUE NOT NULL"`
11
+	Count int64
12 12
 }
13 13
 
14 14
 // Don't change them !
@@ -111,4 +111,4 @@ func updateCounterGitxtsManaged(e Engine, count int64) error {
111 111
 // UpdateCounterGitxtsManaged with count
112 112
 func UpdateCounterGitxtsManaged(c int64) error {
113 113
 	return updateCounterGitxtsManaged(x, c)
114
-}
114
+}

+ 0
- 1
models/error.go View File

@@ -239,7 +239,6 @@ func (err ErrDeployKeyNameAlreadyUsed) Error() string {
239 239
 	return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
240 240
 }
241 241
 
242
-
243 242
 // ErrHashAlreadyExist struct
244 243
 type ErrHashAlreadyExist struct {
245 244
 	Hash string

+ 2
- 2
models/errors/repo.go View File

@@ -5,7 +5,7 @@ import "fmt"
5 5
 // RepoNotExist struct
6 6
 type RepoNotExist struct {
7 7
 	ID     int64
8
-	UserID   int64
8
+	UserID int64
9 9
 	Name   string
10 10
 }
11 11
 
@@ -18,4 +18,4 @@ func IsRepoNotExist(err error) bool {
18 18
 // Error func
19 19
 func (err RepoNotExist) Error() string {
20 20
 	return fmt.Sprintf("repository does not exist [id: %d, user_id: %d, name: %s]", err.ID, err.UserID, err.Name)
21
-}
21
+}

+ 21
- 21
models/gitxt.go View File

@@ -1,41 +1,41 @@
1 1
 package models
2 2
 
3 3
 import (
4
-	"time"
5 4
 	"dev.sigpipe.me/dashie/git.txt/models/errors"
6
-	"github.com/go-xorm/xorm"
7
-	"fmt"
8
-	"os"
5
+	"dev.sigpipe.me/dashie/git.txt/setting"
9 6
 	"dev.sigpipe.me/dashie/git.txt/stuff/repository"
10 7
 	"dev.sigpipe.me/dashie/git.txt/stuff/sync"
11
-	"dev.sigpipe.me/dashie/git.txt/setting"
8
+	"fmt"
9
+	"github.com/Unknwon/com"
10
+	"github.com/go-xorm/xorm"
12 11
 	log "gopkg.in/clog.v1"
12
+	"os"
13
+	"os/exec"
13 14
 	"path/filepath"
14
-	"github.com/Unknwon/com"
15 15
 	"strings"
16
-	"os/exec"
16
+	"time"
17 17
 )
18 18
 
19 19
 // Gitxt struct
20 20
 type Gitxt struct {
21
-	ID          int64        `xorm:"pk autoincr"`
22
-	Hash        string        `xorm:"UNIQUE NOT NULL"`
23
-	UserID      int64        `xorm:"INDEX"`
21
+	ID          int64  `xorm:"pk autoincr"`
22
+	Hash        string `xorm:"UNIQUE NOT NULL"`
23
+	UserID      int64  `xorm:"INDEX"`
24 24
 	Anonymous   bool
25
-	Description string        `xorm:"TEXT"`
25
+	Description string `xorm:"TEXT"`
26 26
 
27 27
 	// Chosen expiry in hours
28
-	ExpiryHours		int64  `xorm:"INDEX"`
28
+	ExpiryHours int64 `xorm:"INDEX"`
29 29
 	// Calculated expiry unix timestamp from the time of creation/update
30
-	ExpiryUnix	int64
31
-	Expiry		time.Time	`xorm:"-"`
30
+	ExpiryUnix int64
31
+	Expiry     time.Time `xorm:"-"`
32 32
 
33 33
 	// Permissions
34
-	IsPrivate bool        `xorm:"DEFAULT 0"`
34
+	IsPrivate bool `xorm:"DEFAULT 0"`
35 35
 
36
-	Created     time.Time        `xorm:"-"`
36
+	Created     time.Time `xorm:"-"`
37 37
 	CreatedUnix int64
38
-	Updated     time.Time        `xorm:"-"`
38
+	Updated     time.Time `xorm:"-"`
39 39
 	UpdatedUnix int64
40 40
 
41 41
 	// Relations
@@ -67,8 +67,8 @@ func (gitxt *Gitxt) AfterSet(colName string, _ xorm.Cell) {
67 67
 
68 68
 // GitxtWithUser struct
69 69
 type GitxtWithUser struct {
70
-	User        `xorm:"extends"`
71
-	Gitxt        `xorm:"extends"`
70
+	User  `xorm:"extends"`
71
+	Gitxt `xorm:"extends"`
72 72
 }
73 73
 
74 74
 // Preventing duplicate running tasks
@@ -131,7 +131,7 @@ func GetRepositoryByName(user string, name string) (*Gitxt, error) {
131 131
 	if err != nil {
132 132
 		return nil, err
133 133
 	} else if !has {
134
-		return nil, errors.RepoNotExist{0, repo.UserID, name}
134
+		return nil, errors.RepoNotExist{ID: 0, UserID: repo.UserID, Name: name}
135 135
 	}
136 136
 	return repo, nil
137 137
 }
@@ -317,7 +317,7 @@ func DeleteRepository(ownerID int64, repoID int64) error {
317 317
 	if err != nil {
318 318
 		return err
319 319
 	} else if !has {
320
-		return errors.RepoNotExist{repoID, ownerID, ""}
320
+		return errors.RepoNotExist{ID: repoID, UserID: ownerID, Name: ""}
321 321
 	}
322 322
 
323 323
 	// By defaults use anonymoyus

+ 8
- 8
models/models.go View File

@@ -5,19 +5,19 @@ import (
5 5
 	_ "github.com/denisenkom/go-mssqldb"
6 6
 	// mysql
7 7
 	_ "github.com/go-sql-driver/mysql"
8
-	// Postgresql
9
-	_ "github.com/lib/pq"
10
-	"github.com/go-xorm/xorm"
11 8
 	"database/sql"
9
+	"dev.sigpipe.me/dashie/git.txt/setting"
10
+	"errors"
12 11
 	"fmt"
13 12
 	"github.com/go-xorm/core"
14
-	"path"
15
-	"strings"
13
+	"github.com/go-xorm/xorm"
14
+	// Postgresql
15
+	_ "github.com/lib/pq"
16
+	log "gopkg.in/clog.v1"
16 17
 	"net/url"
17 18
 	"os"
18
-	"dev.sigpipe.me/dashie/git.txt/setting"
19
-	"errors"
20
-	log "gopkg.in/clog.v1"
19
+	"path"
20
+	"strings"
21 21
 )
22 22
 
23 23
 // Engine represents a XORM engine or session.

+ 1
- 1
models/models_sqlite.go View File

@@ -8,4 +8,4 @@ import (
8 8
 
9 9
 func init() {
10 10
 	EnableSQLite3 = true
11
-}
11
+}

+ 11
- 11
models/sshkey.go View File

@@ -6,19 +6,19 @@ import (
6 6
 
7 7
 // SSHKey struct
8 8
 type SSHKey struct {
9
-	ID		int64	`xorm:"pk autoincr"`
10
-	UserID		int64	`xorm:"INDEX NOT NULL"`
9
+	ID     int64 `xorm:"pk autoincr"`
10
+	UserID int64 `xorm:"INDEX NOT NULL"`
11 11
 
12
-	Name		string	`xorm:"NOT NULL"`
13
-	Fingerprint	string	`xorm:"NOT NULL"`
14
-	Content		string	`xorm:"TEXT NOT NULL"`
15
-	Mode		int	`xorm:"NOT NULL DEFAULT 2"`
16
-	Type		int	`xorm:"NOT NULL DEFAULT 1"`
12
+	Name        string `xorm:"NOT NULL"`
13
+	Fingerprint string `xorm:"NOT NULL"`
14
+	Content     string `xorm:"TEXT NOT NULL"`
15
+	Mode        int    `xorm:"NOT NULL DEFAULT 2"`
16
+	Type        int    `xorm:"NOT NULL DEFAULT 1"`
17 17
 
18
-	Created		time.Time	`xorm:"-"`
19
-	CreatedUnix	int64
20
-	Updated		time.Time	`xorm:"-"`
21
-	UpdatedUnix	int64
18
+	Created     time.Time `xorm:"-"`
19
+	CreatedUnix int64
20
+	Updated     time.Time `xorm:"-"`
21
+	UpdatedUnix int64
22 22
 
23 23
 	// Relations
24 24
 	// 	UserID

+ 32
- 32
models/user.go View File

@@ -1,43 +1,43 @@
1 1
 package models
2 2
 
3 3
 import (
4
-	"time"
5
-	"strings"
6
-	"unicode/utf8"
7
-	"dev.sigpipe.me/dashie/git.txt/models/errors"
8
-	"golang.org/x/crypto/pbkdf2"
9 4
 	"crypto/sha256"
10
-	"fmt"
11 5
 	"crypto/subtle"
12
-	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
13
-	"os"
14
-	"path/filepath"
6
+	"dev.sigpipe.me/dashie/git.txt/models/errors"
15 7
 	"dev.sigpipe.me/dashie/git.txt/setting"
8
+	"dev.sigpipe.me/dashie/git.txt/stuff/mailer"
9
+	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
16 10
 	"encoding/hex"
11
+	"fmt"
17 12
 	"github.com/Unknwon/com"
13
+	"golang.org/x/crypto/pbkdf2"
18 14
 	log "gopkg.in/clog.v1"
19
-	"dev.sigpipe.me/dashie/git.txt/stuff/mailer"
15
+	"os"
16
+	"path/filepath"
17
+	"strings"
18
+	"time"
19
+	"unicode/utf8"
20 20
 )
21 21
 
22 22
 // User struct
23 23
 type User struct {
24
-	ID		int64	`xorm:"pk autoincr"`
25
-	UserName	string	`xorm:"UNIQUE NOT NULL"`
26
-	LowerName	string	`xorm:"UNIQUE NOT NULL"`
27
-	Email		string	`xorm:"NOT NULL"`
24
+	ID        int64  `xorm:"pk autoincr"`
25
+	UserName  string `xorm:"UNIQUE NOT NULL"`
26
+	LowerName string `xorm:"UNIQUE NOT NULL"`
27
+	Email     string `xorm:"NOT NULL"`
28 28
 
29
-	Password	string	`xorm:"NOT NULL"`
30
-	Rands		string	`xorm:"VARCHAR(10)"`
31
-	Salt		string	`xorm:"VARCHAR(10)"`
29
+	Password string `xorm:"NOT NULL"`
30
+	Rands    string `xorm:"VARCHAR(10)"`
31
+	Salt     string `xorm:"VARCHAR(10)"`
32 32
 
33 33
 	// Permissions
34
-	IsAdmin		bool	`xorm:"DEFAULT 0"`
35
-	IsActive	bool	`xorm:"DEFAULT 0"`
34
+	IsAdmin  bool `xorm:"DEFAULT 0"`
35
+	IsActive bool `xorm:"DEFAULT 0"`
36 36
 
37
-	Created		time.Time	`xorm:"-"`
38
-	CreatedUnix	int64
39
-	Updated		time.Time	`xorm:"-"`
40
-	UpdatedUnix	int64
37
+	Created     time.Time `xorm:"-"`
38
+	CreatedUnix int64
39
+	Updated     time.Time `xorm:"-"`
40
+	UpdatedUnix int64
41 41
 
42 42
 	// Relations
43 43
 	// 	Gitxts
@@ -71,7 +71,7 @@ func getUserByID(e Engine, id int64) (*User, error) {
71 71
 	if err != nil {
72 72
 		return nil, err
73 73
 	} else if !has {
74
-		return nil, errors.UserNotExist{id, ""}
74
+		return nil, errors.UserNotExist{UserID: id, Name: ""}
75 75
 	}
76 76
 	return u, nil
77 77
 }
@@ -84,14 +84,14 @@ func GetUserByID(id int64) (*User, error) {
84 84
 // GetUserByName returns user by given name.
85 85
 func GetUserByName(name string) (*User, error) {
86 86
 	if len(name) == 0 {
87
-		return nil, errors.UserNotExist{0, name}
87
+		return nil, errors.UserNotExist{UserID: 0, Name: name}
88 88
 	}
89 89
 	u := &User{LowerName: strings.ToLower(name)}
90 90
 	has, err := x.Get(u)
91 91
 	if err != nil {
92 92
 		return nil, err
93 93
 	} else if !has {
94
-		return nil, errors.UserNotExist{0, name}
94
+		return nil, errors.UserNotExist{UserID: 0, Name: name}
95 95
 	}
96 96
 	return u, nil
97 97
 }
@@ -99,7 +99,7 @@ func GetUserByName(name string) (*User, error) {
99 99
 // GetUserByEmail returns the user object by given e-mail if exists.
100 100
 func GetUserByEmail(email string) (*User, error) {
101 101
 	if len(email) == 0 {
102
-		return nil, errors.UserNotExist{0, "email"}
102
+		return nil, errors.UserNotExist{UserID: 0, Name: "email"}
103 103
 	}
104 104
 
105 105
 	email = strings.ToLower(email)
@@ -112,7 +112,7 @@ func GetUserByEmail(email string) (*User, error) {
112 112
 		return user, nil
113 113
 	}
114 114
 
115
-	return nil, errors.UserNotExist{0, email}
115
+	return nil, errors.UserNotExist{UserID: 0, Name: email}
116 116
 }
117 117
 
118 118
 // IsUserExist checks if given user name exist,
@@ -255,10 +255,10 @@ func UserLogin(username, password string) (*User, error) {
255 255
 			return user, nil
256 256
 		}
257 257
 
258
-		return nil, errors.UserNotExist{user.ID, user.UserName}
258
+		return nil, errors.UserNotExist{UserID: user.ID, Name: user.UserName}
259 259
 	}
260 260
 
261
-	return nil, errors.UserNotExist{user.ID, user.UserName}
261
+	return nil, errors.UserNotExist{UserID: user.ID, Name: user.UserName}
262 262
 }
263 263
 
264 264
 // get user by verify code
@@ -300,7 +300,7 @@ func VerifyUserActiveCode(code string) (user *User) {
300 300
 // GenerateEmailActivateCode generates an activate code based on user information and given e-mail.
301 301
 func (user *User) GenerateEmailActivateCode(email string) string {
302 302
 	code := tool.CreateTimeLimitCode(
303
-		com.ToStr(user.ID)+email+user.LowerName+user.Password+user.Rands,180, nil)
303
+		com.ToStr(user.ID)+email+user.LowerName+user.Password+user.Rands, 180, nil)
304 304
 
305 305
 	// Add tail hex username
306 306
 	code += hex.EncodeToString([]byte(user.LowerName))
@@ -345,4 +345,4 @@ func (mUser mailerUser) GenerateEmailActivateCode(email string) string {
345 345
 // NewMailerUser mail user
346 346
 func NewMailerUser(u *User) mailer.User {
347 347
 	return mailerUser{u}
348
-}
348
+}

+ 4
- 4
routers/admin/admin.go View File

@@ -2,11 +2,11 @@ package admin
2 2
 
3 3
 import (
4 4
 	"dev.sigpipe.me/dashie/git.txt/context"
5
-	"time"
6
-	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
7 5
 	"dev.sigpipe.me/dashie/git.txt/stuff/cron"
8
-	"runtime"
6
+	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
9 7
 	"fmt"
8
+	"runtime"
9
+	"time"
10 10
 )
11 11
 
12 12
 const (
@@ -107,4 +107,4 @@ func Dashboard(ctx *context.Context) {
107 107
 	ctx.Data["SysStatus"] = sysStatus
108 108
 	ctx.Data["Entries"] = cron.ListTasks()
109 109
 	ctx.HTML(200, tmplDashboard)
110
-}
110
+}

+ 3
- 3
routers/gitxt/gitxt.go View File

@@ -14,7 +14,7 @@ import (
14 14
 	"fmt"
15 15
 	"github.com/Unknwon/paginater"
16 16
 	log "gopkg.in/clog.v1"
17
-	"gopkg.in/libgit2/git2go.v25"
17
+	"gopkg.in/libgit2/git2go.v26"
18 18
 	gotemplate "html/template"
19 19
 	"os"
20 20
 	"path/filepath"
@@ -244,7 +244,7 @@ func NewPost(ctx *context.Context, f form.Gitxt) {
244 244
 	models.UpdateCounterGitxtsManaged(counterManaged.Count + 1)
245 245
 
246 246
 	// 5. Return render to gitxt view page
247
-	log.Trace("Pushed repository %s to database as %i", repositoryName, u.ID)
247
+	log.Trace("Pushed repository %s to database as %d", repositoryName, u.ID)
248 248
 	ctx.Redirect(setting.AppSubURL + "/" + repositoryUser + "/" + repositoryName)
249 249
 }
250 250
 
@@ -753,7 +753,7 @@ func EditPost(ctx *context.Context, f form.GitxtEdit) {
753 753
 
754 754
 	// 5. Return render to gitxt view page
755 755
 
756
-	log.Trace("Edit Pushed repository %s - %i", ctx.Gitxt.Gitxt.Hash, ctx.Gitxt.Gitxt.ID)
756
+	log.Trace("Edit Pushed repository %s - %d", ctx.Gitxt.Gitxt.Hash, ctx.Gitxt.Gitxt.ID)
757 757
 	ctx.Redirect(setting.AppSubURL + "/" + repositoryUser + "/" + ctx.Gitxt.Gitxt.Hash)
758 758
 
759 759
 }

+ 1
- 1
routers/hub.go View File

@@ -6,4 +6,4 @@ import "dev.sigpipe.me/dashie/git.txt/context"
6 6
 func NotFound(ctx *context.Context) {
7 7
 	ctx.Title(ctx.Tr("error.page_not_found"))
8 8
 	ctx.Handle(404, "home.NotFound", nil)
9
-}
9
+}

+ 13
- 13
routers/repo/archive.go View File

@@ -5,23 +5,23 @@ import (
5 5
 	"dev.sigpipe.me/dashie/git.txt/stuff/repository"
6 6
 	log "gopkg.in/clog.v1"
7 7
 
8
-	"gopkg.in/libgit2/git2go.v25"
9
-	"strings"
10
-	"path"
8
+	"dev.sigpipe.me/dashie/git.txt/stuff/gite"
9
+	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
11 10
 	"github.com/Unknwon/com"
11
+	"gopkg.in/libgit2/git2go.v26"
12 12
 	"os"
13
-	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
14
-	"dev.sigpipe.me/dashie/git.txt/stuff/gite"
13
+	"path"
14
+	"strings"
15 15
 )
16 16
 
17 17
 // DownloadArchive of repository
18 18
 func DownloadArchive(ctx *context.Context) {
19 19
 	var (
20
-		uri			= ctx.Params("*")
21
-		refName			string
22
-		ext			string
23
-		archivePath		string
24
-		archiveType		string
20
+		uri         = ctx.Params("*")
21
+		refName     string
22
+		ext         string
23
+		archivePath string
24
+		archiveType string
25 25
 	)
26 26
 
27 27
 	pathRepo := repository.RepoPath(ctx.RepoOwnerUsername, ctx.Gitxt.Gitxt.Hash)
@@ -40,7 +40,7 @@ func DownloadArchive(ctx *context.Context) {
40 40
 		ctx.Error(404)
41 41
 		return
42 42
 	}
43
-	
43
+
44 44
 	refName = strings.TrimSuffix(uri, ext)
45 45
 	if refName != "master" {
46 46
 		ctx.Handle(500, "Ref other than master not supported", nil)
@@ -65,7 +65,7 @@ func DownloadArchive(ctx *context.Context) {
65 65
 	}
66 66
 
67 67
 	// Test if repository is empty
68
-	isEmpty, err := repo.IsEmpty();
68
+	isEmpty, err := repo.IsEmpty()
69 69
 	if err != nil || isEmpty {
70 70
 		log.Warn("Empty repository or corrupted %s: %s", ctx.Gitxt.Gitxt.Hash, err)
71 71
 		ctx.Flash.Error(ctx.Tr("gitxt_git.repo_corrupt_or_empty"))
@@ -116,4 +116,4 @@ func DownloadArchive(ctx *context.Context) {
116 116
 	}
117 117
 
118 118
 	ctx.ServeFile(archivePath, ctx.Gitxt.Gitxt.Hash+"-"+refName+ext)
119
-}
119
+}

+ 24
- 24
routers/repo/repo.go View File

@@ -4,25 +4,25 @@
4 4
 package repo
5 5
 
6 6
 import (
7
-	"gopkg.in/macaron.v1"
7
+	"bytes"
8
+	"compress/gzip"
8 9
 	"dev.sigpipe.me/dashie/git.txt/context"
9
-	"strings"
10 10
 	"dev.sigpipe.me/dashie/git.txt/models"
11 11
 	"dev.sigpipe.me/dashie/git.txt/models/errors"
12
-	"net/http"
13
-	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
14 12
 	"dev.sigpipe.me/dashie/git.txt/setting"
15
-	log "gopkg.in/clog.v1"
16
-	"regexp"
17
-	"time"
13
+	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
18 14
 	"fmt"
19
-	"path"
20
-	"os"
21 15
 	"github.com/Unknwon/com"
22
-	"compress/gzip"
23
-	"bytes"
16
+	log "gopkg.in/clog.v1"
17
+	"gopkg.in/macaron.v1"
18
+	"net/http"
19
+	"os"
24 20
 	"os/exec"
21
+	"path"
22
+	"regexp"
25 23
 	"strconv"
24
+	"strings"
25
+	"time"
26 26
 )
27 27
 
28 28
 const (
@@ -39,11 +39,11 @@ const (
39 39
 // HTTPContext struct
40 40
 type HTTPContext struct {
41 41
 	*context.Context
42
-	OwnerName	string
43
-	OwnerSalt	string
44
-	RepoID		int64
45
-	RepoName	string
46
-	AuthUser	*models.User
42
+	OwnerName string
43
+	OwnerSalt string
44
+	RepoID    int64
45
+	RepoName  string
46
+	AuthUser  *models.User
47 47
 }
48 48
 
49 49
 // askCredentials responses HTTP header and status which informs client to provide credentials
@@ -125,18 +125,18 @@ func HTTPContexter() macaron.Handler {
125 125
 		log.Trace("HTTPGit - Authenticated user: %s", authUser.UserName)
126 126
 
127 127
 		// Reject if not pulling and user doesn't match repo ID
128
-		if authUser.ID != repo.UserID  && !isPull {
128
+		if authUser.ID != repo.UserID && !isPull {
129 129
 			askCredentials(ctx, http.StatusForbidden, "User permission denied")
130 130
 			return
131 131
 		}
132 132
 
133 133
 		ctx.Map(&HTTPContext{
134
-			Context: ctx,
134
+			Context:   ctx,
135 135
 			OwnerName: ownerName,
136 136
 			OwnerSalt: owner.Salt,
137
-			RepoID: repo.ID,
138
-			RepoName: repoName,
139
-			AuthUser: authUser,
137
+			RepoID:    repo.ID,
138
+			RepoName:  repoName,
139
+			AuthUser:  authUser,
140 140
 		})
141 141
 
142 142
 	}
@@ -250,7 +250,7 @@ func serviceRPC(h serviceHandler, service string) {
250 250
 	cmd.Stderr = &stderr
251 251
 	cmd.Stdin = reqBody
252 252
 	if err = cmd.Run(); err != nil {
253
-		log.Error(2, "HTTP.serviceRPC: fail to serve RPC '%s': %v - %s", service, err, stderr)
253
+		log.Error(2, "HTTP.serviceRPC: fail to serve RPC '%s': %v - %q", service, err, stderr)
254 254
 		h.w.WriteHeader(http.StatusInternalServerError)
255 255
 		return
256 256
 	}
@@ -413,6 +413,6 @@ func HTTP(ctx *HTTPContext) {
413 413
 		return
414 414
 	}
415 415
 
416
-	log.Trace("Not found %s", ctx.Req.Request)
416
+	log.Trace("Not found %s", ctx.Req.Request.URL.Path)
417 417
 	ctx.NotFound()
418
-}
418
+}

+ 10
- 11
routers/user/auth.go View File

@@ -2,14 +2,14 @@ package user
2 2
 
3 3
 import (
4 4
 	"dev.sigpipe.me/dashie/git.txt/context"
5
+	"dev.sigpipe.me/dashie/git.txt/models"
6
+	"dev.sigpipe.me/dashie/git.txt/models/errors"
5 7
 	"dev.sigpipe.me/dashie/git.txt/setting"
6 8
 	"dev.sigpipe.me/dashie/git.txt/stuff/form"
7
-	"dev.sigpipe.me/dashie/git.txt/models"
8 9
 	"dev.sigpipe.me/dashie/git.txt/stuff/mailer"
10
+	"fmt"
9 11
 	log "gopkg.in/clog.v1"
10
-	"dev.sigpipe.me/dashie/git.txt/models/errors"
11 12
 	"net/url"
12
-	"fmt"
13 13
 )
14 14
 
15 15
 const (
@@ -153,7 +153,7 @@ func afterLogin(ctx *context.Context, u *models.User, remember bool) {
153 153
 // Register GET
154 154
 func Register(ctx *context.Context) {
155 155
 	ctx.Title("register.title")
156
-	if ! setting.CanRegister {
156
+	if !setting.CanRegister {
157 157
 		ctx.Flash.Error(ctx.Tr("register.not_allowed"))
158 158
 		ctx.Redirect(setting.AppSubURL + "/")
159 159
 		return
@@ -166,7 +166,7 @@ func Register(ctx *context.Context) {
166 166
 func RegisterPost(ctx *context.Context, f form.Register) {
167 167
 	ctx.Title("register.title")
168 168
 
169
-	if ! setting.CanRegister {
169
+	if !setting.CanRegister {
170 170
 		ctx.Flash.Error(ctx.Tr("register.not_allowed"))
171 171
 		ctx.Redirect(setting.AppSubURL + "/")
172 172
 		return
@@ -185,10 +185,10 @@ func RegisterPost(ctx *context.Context, f form.Register) {
185 185
 	}
186 186
 
187 187
 	u := &models.User{
188
-		UserName:	f.UserName,
189
-		Email:		f.Email,
190
-		Password:	f.Password,
191
-		IsActive:	true, // FIXME: implement user activation by email
188
+		UserName: f.UserName,
189
+		Email:    f.Email,
190
+		Password: f.Password,
191
+		IsActive: true, // FIXME: implement user activation by email
192 192
 	}
193 193
 	if err := models.CreateUser(u); err != nil {
194 194
 		switch {
@@ -234,7 +234,6 @@ func Logout(ctx *context.Context) {
234 234
 	ctx.Redirect(setting.AppSubURL + "/")
235 235
 }
236 236
 
237
-
238 237
 // ResetPasswd GET
239 238
 func ResetPasswd(ctx *context.Context) {
240 239
 	ctx.Title("auth.reset_password")
@@ -352,4 +351,4 @@ func ForgotPasswdPost(ctx *context.Context) {
352 351
 	ctx.Data["Hours"] = 180 / 60
353 352
 	ctx.Data["IsResetSent"] = true
354 353
 	ctx.HTML(200, tmplForgotPassword)
355
-}
354
+}

+ 2
- 2
routers/user/setting.go View File

@@ -2,8 +2,8 @@ package user
2 2
 
3 3
 import (
4 4
 	"dev.sigpipe.me/dashie/git.txt/context"
5
-	"dev.sigpipe.me/dashie/git.txt/stuff/form"
6 5
 	"dev.sigpipe.me/dashie/git.txt/models"
6
+	"dev.sigpipe.me/dashie/git.txt/stuff/form"
7 7
 )
8 8
 
9 9
 const (
@@ -37,4 +37,4 @@ func SettingsPost(ctx *context.Context, f form.UpdateSettingsProfile) {
37 37
 
38 38
 	ctx.Flash.Success(ctx.Tr("settings.update_profile_success"))
39 39
 	ctx.SubURLRedirect("/user/settings")
40
-}
40
+}

+ 54
- 56
setting/setting.go View File

@@ -1,20 +1,20 @@
1 1
 package setting
2 2
 
3 3
 import (
4
-	"os"
5
-	"strings"
6
-	"runtime"
7
-	"os/exec"
8
-	"path/filepath"
4
+	"github.com/Unknwon/com"
5
+	"github.com/go-macaron/session"
9 6
 	log "gopkg.in/clog.v1"
10 7
 	"gopkg.in/ini.v1"
8
+	"net/mail"
9
+	"net/url"
10
+	"os"
11
+	"os/exec"
11 12
 	"path"
13
+	"path/filepath"
14
+	"runtime"
12 15
 	"strconv"
13
-	"github.com/Unknwon/com"
14
-	"net/url"
15
-	"github.com/go-macaron/session"
16
+	"strings"
16 17
 	"time"
17
-	"net/mail"
18 18
 )
19 19
 
20 20
 // Scheme type
@@ -28,44 +28,43 @@ const (
28 28
 	SchemeUnixSocket Scheme = "unix"
29 29
 )
30 30
 
31
-
32 31
 // Settings
33 32
 var (
34 33
 	// Build infos added by -ldflags
35
-	BuildTime	string
36
-	BuildGitHash 	string
34
+	BuildTime    string
35
+	BuildGitHash string
37 36
 
38 37
 	// App Settings
39 38
 
40
-	AppVer		string
41
-	AppPath		string
39
+	AppVer          string
40
+	AppPath         string
42 41
 	AppName         string
43
-	AppURL 		string
42
+	AppURL          string
44 43
 	AppSubURL       string
45 44
 	AppSubURLDepth  int // Number of slashes
46
-	CanRegister	bool
47
-	AnonymousCreate	bool
48
-	ProdMode	bool
45
+	CanRegister     bool
46
+	AnonymousCreate bool
47
+	ProdMode        bool
49 48
 
50 49
 	// Cron tasks
51 50
 	Cron struct {
52 51
 		RepoArchiveCleanup struct {
53
-			Enabled		bool
54
-			RunAtStart	bool
55
-			Schedule	string
56
-			OlderThan	time.Duration
52
+			Enabled    bool
53
+			RunAtStart bool
54
+			Schedule   string
55
+			OlderThan  time.Duration
57 56
 		} `ini:"cron.repo_archive_cleanup"`
58 57
 	}
59 58
 
60 59
 	// Server settings
61 60
 
62
-	Protocol		Scheme
63
-	UnixSocketPermission	uint32
64
-	Domain			string
65
-	HTTPAddr		string
66
-	HTTPPort		string
67
-	DisableRouterLog	bool
68
-	StaticRootPath		string
61
+	Protocol             Scheme
62
+	UnixSocketPermission uint32
63
+	Domain               string
64
+	HTTPAddr             string
65
+	HTTPPort             string
66
+	DisableRouterLog     bool
67
+	StaticRootPath       string
69 68
 
70 69
 	HTTP struct {
71 70
 		AccessControlAllowOrigin string
@@ -73,24 +72,24 @@ var (
73 72
 
74 73
 	// Database Settings
75 74
 
76
-	UseSQLite3	bool
77
-	UseMySQL	bool
78
-	UsePostgreSQL	bool
79
-	UseMSSQL	bool
75
+	UseSQLite3    bool
76
+	UseMySQL      bool
77
+	UsePostgreSQL bool
78
+	UseMSSQL      bool
80 79
 
81 80
 	// Global setting objects
82 81
 
83
-	CustomConf	string
84
-	IsWindows	bool
85
-	Cfg		*ini.File
86
-	HasRobotsTxt	bool
87
-	RobotsTxtPath	string
82
+	CustomConf    string
83
+	IsWindows     bool
84
+	Cfg           *ini.File
85
+	HasRobotsTxt  bool
86
+	RobotsTxtPath string
88 87
 
89 88
 	// Log settings
90 89
 
91
-	LogRootPath	string
92
-	LogModes	[]string
93
-	LogConfigs	[]interface{}
90
+	LogRootPath string
91
+	LogModes    []string
92
+	LogConfigs  []interface{}
94 93
 
95 94
 	// Repository settings
96 95
 
@@ -112,13 +111,13 @@ var (
112 111
 	CookieRememberName      string
113 112
 	CookieSecure            bool
114 113
 	EnableLoginStatusCookie bool
115
-	LoginStatusCookieName string
114
+	LoginStatusCookieName   string
116 115
 
117 116
 	// Cache settings
118 117
 
119 118
 	CacheAdapter  string
120 119
 	CacheInterval int
121
-	CacheConn string
120
+	CacheConn     string
122 121
 
123 122
 	// Langs settings
124 123
 	Langs     []string
@@ -127,25 +126,25 @@ var (
127 126
 
128 127
 	// Markdown sttings
129 128
 	Markdown struct {
130
-	    EnableHardLineBreak bool
131
-	    CustomURLSchemes    []string `ini:"CUSTOM_URL_SCHEMES"`
132
-	    FileExtensions      []string
129
+		EnableHardLineBreak bool
130
+		CustomURLSchemes    []string `ini:"CUSTOM_URL_SCHEMES"`
131
+		FileExtensions      []string
133 132
 	}
134 133
 
135 134
 	// Smartypants settings
136 135
 	Smartypants struct {
137
-	    Enabled      bool
138
-	    Fractions    bool
139
-	    Dashes       bool
140
-	    LatexDashes  bool
141
-	    AngledQuotes bool
136
+		Enabled      bool
137
+		Fractions    bool
138
+		Dashes       bool
139
+		LatexDashes  bool
140
+		AngledQuotes bool
142 141
 	}
143 142
 
144 143
 	// Bloby struct for static limitations
145 144
 	Bloby struct {
146
-		MaxSizeDisplay	int64
147
-		MaxPageDisplay  int64
148
-		MaxRawSize	int64
145
+		MaxSizeDisplay int64
146
+		MaxPageDisplay int64
147
+		MaxRawSize     int64
149 148
 	}
150 149
 )
151 150
 
@@ -205,7 +204,7 @@ func forcePathSeparator(path string) {
205 204
 func InitConfig() {
206 205
 	workDir, err := WorkDir()
207 206
 	if err != nil {
208
-		log.Fatal(2,"Fail to get work directory: %v", err)
207
+		log.Fatal(2, "Fail to get work directory: %v", err)
209 208
 	}
210 209
 
211 210
 	if len(CustomConf) == 0 {
@@ -489,4 +488,3 @@ func initMailer() {
489 488
 
490 489
 	log.Info("Mail Service Enabled")
491 490
 }
492
-

+ 1
- 1
stuff/auth/auth.go View File

@@ -5,9 +5,9 @@
5 5
 package auth
6 6
 
7 7
 import (
8
-	"strings"
9 8
 	"dev.sigpipe.me/dashie/git.txt/models"
10 9
 	"dev.sigpipe.me/dashie/git.txt/models/errors"
10
+	"strings"
11 11
 
12 12
 	"github.com/go-macaron/session"
13 13
 	log "gopkg.in/clog.v1"

+ 7
- 7
stuff/cron/cron.go View File

@@ -1,10 +1,10 @@
1 1
 package cron
2 2
 
3 3
 import (
4
-	log "gopkg.in/clog.v1"
5
-	"github.com/gogits/cron"
6
-	"dev.sigpipe.me/dashie/git.txt/setting"
7 4
 	"dev.sigpipe.me/dashie/git.txt/models"
5
+	"dev.sigpipe.me/dashie/git.txt/setting"
6
+	"github.com/gogits/cron"
7
+	log "gopkg.in/clog.v1"
8 8
 	"time"
9 9
 )
10 10
 
@@ -13,8 +13,8 @@ var c = cron.New()
13 13
 // NewContext initialize Cron stuff
14 14
 func NewContext() {
15 15
 	var (
16
-		entry	*cron.Entry
17
-		err	error
16
+		entry *cron.Entry
17
+		err   error
18 18
 	)
19 19
 
20 20
 	if setting.Cron.RepoArchiveCleanup.Enabled {
@@ -34,7 +34,7 @@ func NewContext() {
34 34
 	if err != nil {
35 35
 		log.Fatal(2, "Cron.(delete expired repositories): %v", err)
36 36
 	}
37
-	entry.Next = time.Now().Add(time.Minute*1)
37
+	entry.Next = time.Now().Add(time.Minute * 1)
38 38
 
39 39
 	c.Start()
40 40
 }
@@ -42,4 +42,4 @@ func NewContext() {
42 42
 // ListTasks returns all running cron tasks.
43 43
 func ListTasks() []*cron.Entry {
44 44
 	return c.Entries()
45
-}
45
+}

+ 2
- 2
stuff/form/auth.go View File

@@ -10,7 +10,7 @@ type Register struct {
10 10
 	UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
11 11
 	Email    string `binding:"Required;Email;MaxSize(254)"`
12 12
 	Password string `binding:"Required;MaxSize(255)"`
13
-	Repeat string
13
+	Repeat   string
14 14
 }
15 15
 
16 16
 // Validate func
@@ -28,4 +28,4 @@ type Login struct {
28 28
 // Validate func
29 29
 func (f *Login) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
30 30
 	return validate(errs, ctx.Data, f, ctx.Locale)
31
-}
31
+}

+ 6
- 6
stuff/form/form.go View File

@@ -1,14 +1,14 @@
1 1
 package form
2 2
 
3 3
 import (
4
-	"reflect"
4
+	"fmt"
5
+	"github.com/Unknwon/com"
5 6
 	"github.com/go-macaron/binding"
7
+	log "gopkg.in/clog.v1"
6 8
 	"gopkg.in/macaron.v1"
7
-	"github.com/Unknwon/com"
8
-	"strings"
9
+	"reflect"
9 10
 	"regexp"
10
-	"fmt"
11
-	log "gopkg.in/clog.v1"
11
+	"strings"
12 12
 )
13 13
 
14 14
 const errAlphaDashDotSlash = "AlphaDashDotSlashError"
@@ -157,4 +157,4 @@ func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaro
157 157
 		}
158 158
 	}
159 159
 	return errs
160
-}
160
+}

+ 9
- 9
stuff/form/gitxt.go View File

@@ -1,8 +1,8 @@
1 1
 package form
2 2
 
3 3
 import (
4
-	"gopkg.in/macaron.v1"
5 4
 	"github.com/go-macaron/binding"
5
+	"gopkg.in/macaron.v1"
6 6
 )
7 7
 
8 8
 // Gitxt form struct
@@ -11,11 +11,11 @@ type Gitxt struct {
11 11
 	IsPublic    bool   `binding:"Default:1"`
12 12
 	// Validation builtin into Macaron/Binding doesn't validates theses slices
13 13
 	// See the router view for manual validation
14
-	FilesFilename	[]string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
15
-	FilesContent	[]string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
14
+	FilesFilename []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
15
+	FilesContent  []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
16 16
 
17 17
 	//				     no, 1h, 4h, 1d, 2d, 3d, 4d, 5d,  6d,  7d,  1m,  1y
18
-	ExpiryHours	int64	`binding:"In(0,1,4,24,48,72,96,120,144,168,730,8760);Default(0)"`
18
+	ExpiryHours int64 `binding:"In(0,1,4,24,48,72,96,120,144,168,730,8760);Default(0)"`
19 19
 }
20 20
 
21 21
 // Validate func
@@ -25,8 +25,8 @@ func (f *Gitxt) Validate(ctx *macaron.Context, errs binding.Errors) binding.Erro
25 25
 
26 26
 // GitxtDelete form
27 27
 type GitxtDelete struct {
28
-	Hash    string   `binding:"Required"`
29
-	Owner    string   `binding:"Required"`
28
+	Hash  string `binding:"Required"`
29
+	Owner string `binding:"Required"`
30 30
 }
31 31
 
32 32
 // Validate func
@@ -39,12 +39,12 @@ type GitxtEdit struct {
39 39
 	Description string `binding:"MaxSize(255)"`
40 40
 	// Validation builtin into Macaron/Binding doesn't validates theses slices
41 41
 	// See the router view for manual validation
42
-	FilesFilename	[]string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
43
-	FilesContent	[]string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
42
+	FilesFilename   []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
43
+	FilesContent    []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
44 44
 	FilesNotHandled []bool
45 45
 
46 46
 	//				     no, 1h, 4h, 1d, 2d, 3d, 4d, 5d,  6d,  7d,  1m,  1y
47
-	ExpiryHours	int64	`binding:"In(0,1,4,24,48,72,96,120,144,168,730,8760);Default(0)"`
47
+	ExpiryHours int64 `binding:"In(0,1,4,24,48,72,96,120,144,168,730,8760);Default(0)"`
48 48
 }
49 49
 
50 50
 // Validate struct

+ 1
- 1
stuff/form/user.go View File

@@ -1,8 +1,8 @@
1 1
 package form
2 2
 
3 3
 import (
4
-	"gopkg.in/macaron.v1"
5 4
 	"github.com/go-macaron/binding"
5
+	"gopkg.in/macaron.v1"
6 6
 )
7 7
 
8 8
 // UpdateSettingsProfile form struct

+ 1
- 1
stuff/gite/gite.go View File

@@ -5,7 +5,7 @@ import (
5 5
 	"archive/zip"
6 6
 	"dev.sigpipe.me/dashie/git.txt/setting"
7 7
 	"github.com/rakyll/magicmime"
8
-	"gopkg.in/libgit2/git2go.v25"
8
+	"gopkg.in/libgit2/git2go.v26"
9 9
 	gotemplate "html/template"
10 10
 	"os"
11 11
 	"path/filepath"

+ 1
- 1
stuff/markup/markdown_test.go View File

@@ -9,8 +9,8 @@ import (
9 9
 
10 10
 	. "github.com/smartystreets/goconvey/convey"
11 11
 
12
-	. "dev.sigpipe.me/dashie/git.txt/stuff/markup"
13 12
 	"dev.sigpipe.me/dashie/git.txt/setting"
13
+	. "dev.sigpipe.me/dashie/git.txt/stuff/markup"
14 14
 )
15 15
 
16 16
 func Test_IsMarkdownFile(t *testing.T) {

+ 1
- 1
stuff/markup/markup.go View File

@@ -14,8 +14,8 @@ import (
14 14
 	"github.com/Unknwon/com"
15 15
 	"golang.org/x/net/html"
16 16
 
17
-	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
18 17
 	"dev.sigpipe.me/dashie/git.txt/setting"
18
+	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
19 19
 )
20 20
 
21 21
 // IsReadmeFile reports whether name looks like a README file based on its extension.

+ 2
- 2
stuff/repository/repository.go View File

@@ -1,8 +1,8 @@
1 1
 package repository
2 2
 
3 3
 import (
4
-	git "gopkg.in/libgit2/git2go.v25"
5 4
 	"dev.sigpipe.me/dashie/git.txt/setting"
5
+	git "gopkg.in/libgit2/git2go.v26"
6 6
 	"path"
7 7
 )
8 8
 
@@ -22,4 +22,4 @@ func InitRepository(username string, repoName string) (*git.Repository, error) {
22 22
 		return nil, err
23 23
 	}
24 24
 	return repo, err
25
-}
25
+}

+ 2
- 2
stuff/template/highlight/highlight.go View File

@@ -20,8 +20,8 @@ var (
20 20
 	// File names that are representing highlight classes.
21 21
 	highlightFileNames = map[string]bool{
22 22
 		"cmakelists.txt": true,
23
-		"dockerfile": true,
24
-		"makefile":   true,
23
+		"dockerfile":     true,
24
+		"makefile":       true,
25 25
 	}
26 26
 
27 27
 	// Extensions that are same as highlight classes.

+ 21
- 21
stuff/template/template.go View File

@@ -1,20 +1,20 @@
1 1
 package template
2 2
 
3 3
 import (
4
-	"time"
5
-	"strings"
6
-	"mime"
7
-	"path/filepath"
8
-	"fmt"
9
-	"runtime"
10
-	"html/template"
4
+	"container/list"
5
+	"dev.sigpipe.me/dashie/git.txt/models"
11 6
 	"dev.sigpipe.me/dashie/git.txt/setting"
12
-	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
13
-	"github.com/microcosm-cc/bluemonday"
14 7
 	"dev.sigpipe.me/dashie/git.txt/stuff/markup"
15 8
 	"dev.sigpipe.me/dashie/git.txt/stuff/template/highlight"
16
-	"container/list"
17
-	"dev.sigpipe.me/dashie/git.txt/models"
9
+	"dev.sigpipe.me/dashie/git.txt/stuff/tool"
10
+	"fmt"
11
+	"github.com/microcosm-cc/bluemonday"
12
+	"html/template"
13
+	"mime"
14
+	"path/filepath"
15
+	"runtime"
16
+	"strings"
17
+	"time"
18 18
 )
19 19
 
20 20
 // NewFuncMap initialize the Functions Map
@@ -50,9 +50,9 @@ func NewFuncMap() []template.FuncMap {
50 50
 		"LoadTimes": func(startTime time.Time) string {
51 51
 			return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
52 52
 		},
53
-		"FileSize": 	tool.FileSize,
54
-		"Safe":         safe,
55
-		"Sanitize":     bluemonday.UGCPolicy().Sanitize,
53
+		"FileSize": tool.FileSize,
54
+		"Safe":     safe,
55
+		"Sanitize": bluemonday.UGCPolicy().Sanitize,
56 56
 		"Str2html": str2html,
57 57
 		"Add": func(a, b int) int {
58 58
 			return a + b
@@ -60,7 +60,7 @@ func NewFuncMap() []template.FuncMap {
60 60
 		"DateFmtLong": func(t time.Time) string {
61 61
 			return t.Format(time.RFC1123Z)
62 62
 		},
63
-			"DateFmtShort": func(t time.Time) string {
63
+		"DateFmtShort": func(t time.Time) string {
64 64
 			return t.Format("Jan 02, 2006")
65 65
 		},
66 66
 		"List": listWhatever,
@@ -77,11 +77,11 @@ func NewFuncMap() []template.FuncMap {
77 77
 			}
78 78
 			return str[start:end]
79 79
 		},
80
-		"Join":                  strings.Join,
81
-		"Sha1":                  sha1,
82
-		"ShortSHA1":             tool.ShortSHA1,
83
-		"MD5":                   tool.MD5,
84
-		"EscapePound":           escapePound,
80
+		"Join":        strings.Join,
81
+		"Sha1":        sha1,
82
+		"ShortSHA1":   tool.ShortSHA1,
83
+		"MD5":         tool.MD5,
84
+		"EscapePound": escapePound,
85 85
 		"FilenameIsImage": func(filename string) bool {
86 86
 			mimeType := mime.TypeByExtension(filepath.Ext(filename))
87 87
 			return strings.HasPrefix(mimeType, "image/")
@@ -136,4 +136,4 @@ func escapePound(str string) string {
136 136
 
137 137
 func str2html(raw string) template.HTML {
138 138
 	return template.HTML(markup.Sanitize(raw))
139
-}
139
+}

+ 1
- 1
stuff/tool/file_test.go View File

@@ -13,7 +13,7 @@ import (
13 13
 func Test_FileSize(t *testing.T) {
14 14
 	Convey("File size to human", t, func() {
15 15
 		testCases := []struct {
16
-			size int64
16
+			size  int64
17 17
 			human string
18 18
 		}{
19 19
 			{6, "6 B"},

+ 7
- 7
stuff/tool/tool.go View File

@@ -1,17 +1,17 @@
1 1
 package tool
2 2
 
3 3
 import (
4
-	"encoding/hex"
5
-	"crypto/sha1"
6 4
 	"crypto/md5"
7
-	"math/big"
8 5
 	"crypto/rand"
9
-	"strings"
6
+	"crypto/sha1"
7
+	"dev.sigpipe.me/dashie/git.txt/setting"
10 8
 	"encoding/base64"
11
-	"time"
9
+	"encoding/hex"
12 10
 	"fmt"
13 11
 	"github.com/Unknwon/com"
14
-	"dev.sigpipe.me/dashie/git.txt/setting"
12
+	"math/big"
13
+	"strings"
14
+	"time"
15 15
 )
16 16
 
17 17
 const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
@@ -233,4 +233,4 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
233 233
 
234 234
 	code := fmt.Sprintf("%s%06d%s", startStr, minutes, encoded)
235 235
 	return code
236
-}
236
+}

+ 6
- 6
stuff/tool/tool_test.go View File

@@ -13,7 +13,7 @@ import (
13 13
 func Test_MD5(t *testing.T) {
14 14
 	Convey("Validate MD5", t, func() {
15 15
 		testCases := []struct {
16
-			src string
16
+			src  string
17 17
 			hash string
18 18
 		}{
19 19
 			{"coincoin", "3dc6862aaced087142142587cba2123e"},
@@ -30,7 +30,7 @@ func Test_MD5(t *testing.T) {
30 30
 func Test_SHA1(t *testing.T) {
31 31
 	Convey("Validate SHA1", t, func() {
32 32
 		testCases := []struct {
33
-			src string
33
+			src  string
34 34
 			hash string
35 35
 		}{
36 36
 			{"coincoin", "0f78ee98759868a8b5d5aeb6b9dbd2106b14e965"},
@@ -47,7 +47,7 @@ func Test_SHA1(t *testing.T) {
47 47
 func Test_ShortSHA1(t *testing.T) {
48 48
 	Convey("Validate SHA1", t, func() {
49 49
 		testCases := []struct {
50
-			src string
50
+			src  string
51 51
 			hash string
52 52
 		}{
53 53
 			{"0aadb9081430eb80435b9a442484387f9a443a65", "0aadb90814"},
@@ -63,7 +63,7 @@ func Test_ShortSHA1(t *testing.T) {
63 63
 
64 64
 func Test_RandomString(t *testing.T) {
65 65
 	Convey("Test random string size 5", t, func() {
66
-		for i := 0; i<10; i++ {
66
+		for i := 0; i < 10; i++ {
67 67
 			r1, _ := RandomString(5)
68 68
 			r2, _ := RandomString(5)
69 69
 			So(r1, ShouldNotEqual, r2)
@@ -71,7 +71,7 @@ func Test_RandomString(t *testing.T) {
71 71
 	})
72 72
 
73 73
 	Convey("Test random string size 10", t, func() {
74
-		for i := 0; i<10; i++ {
74
+		for i := 0; i < 10; i++ {
75 75
 			r1, _ := RandomString(10)
76 76
 			r2, _ := RandomString(10)
77 77
 			So(r1, ShouldNotEqual, r2)
@@ -79,7 +79,7 @@ func Test_RandomString(t *testing.T) {
79 79
 	})
80 80
 
81 81
 	Convey("Test random string size 20", t, func() {
82
-		for i := 0; i<10; i++ {
82
+		for i := 0; i < 10; i++ {
83 83
 			r1, _ := RandomString(20)
84 84
 			r2, _ := RandomString(20)
85 85
 			So(r1, ShouldNotEqual, r2)

Loading…
Cancel
Save