go vet refactor

This commit is contained in:
yinw 2016-02-26 14:24:44 +08:00
parent ed60d2245e
commit 61f12f089d
7 changed files with 21 additions and 44 deletions

View File

@ -87,7 +87,7 @@ func (p *ProjectAPI) Post() {
project := models.Project{OwnerID: p.userID, Name: projectName, CreationTime: time.Now(), Public: public} project := models.Project{OwnerID: p.userID, Name: projectName, CreationTime: time.Now(), Public: public}
err = dao.AddProject(project) err = dao.AddProject(project)
if err != nil { if err != nil {
beego.Error("Failed to add project, error: %v", err) beego.Error("Failed to add project, error: ", err)
p.RenderError(http.StatusInternalServerError, "Failed to add project") p.RenderError(http.StatusInternalServerError, "Failed to add project")
} }
} }

View File

@ -103,7 +103,7 @@ func (ra *RepositoryAPI) Get() {
} }
type Tag struct { type Tag struct {
Name string `json: "name"` Name string `json:"name"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
} }

View File

@ -22,7 +22,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm" "github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
) )
@ -74,25 +73,6 @@ func InitDB() {
password = os.Getenv("MYSQL_PWD") password = os.Getenv("MYSQL_PWD")
} }
var flag = true
if addr == "" {
beego.Error("Unset env of MYSQL_HOST")
flag = false
} else if port == "" {
beego.Error("Unset env of MYSQL_PORT_3306_TCP_PORT")
flag = false
} else if username == "" {
beego.Error("Unset env of MYSQL_USR")
flag = false
} else if password == "" {
beego.Error("Unset env of MYSQL_PWD")
flag = false
}
if !flag {
os.Exit(1)
}
dbStr := username + ":" + password + "@tcp(" + addr + ":" + port + ")/registry" dbStr := username + ":" + password + "@tcp(" + addr + ":" + port + ")/registry"
ch := make(chan int, 1) ch := make(chan int, 1)
go func() { go func() {

View File

@ -108,9 +108,6 @@ func TestMain(m *testing.M) {
log.Fatalf("environment variable DB_PORT is not set") log.Fatalf("environment variable DB_PORT is not set")
} }
dbPassword := os.Getenv("DB_PWD") dbPassword := os.Getenv("DB_PWD")
if len(dbPassword) == 0 {
log.Fatalf("environment variable DB_PWD is not set")
}
fmt.Printf("DB_HOST: %s, DB_USR: %s, DB_PORT: %s, DB_PWD: %s\n", dbHost, dbUser, dbPort, dbPassword) fmt.Printf("DB_HOST: %s, DB_USR: %s, DB_PORT: %s, DB_PWD: %s\n", dbHost, dbUser, dbPort, dbPassword)
@ -468,14 +465,14 @@ func TestGetUserByProject(t *testing.T) {
} }
users, err := GetUserByProject(pid, u1) users, err := GetUserByProject(pid, u1)
if err != nil { if err != nil {
t.Errorf("Error happened in GetUserByProject: %v, project Id: %d, user: %+v", u1) t.Errorf("Error happened in GetUserByProject: %v, project Id: %d, user: %+v", err, pid, u1)
} }
if len(users) != 1 { if len(users) != 1 {
t.Errorf("unexpected length of user list, expected: 1, the users list: %+v", users) t.Errorf("unexpected length of user list, expected: 1, the users list: %+v", users)
} }
users, err = GetUserByProject(pid, u2) users, err = GetUserByProject(pid, u2)
if err != nil { if err != nil {
t.Errorf("Error happened in GetUserByProject: %v, project Id: %d, user: %+v", u2) t.Errorf("Error happened in GetUserByProject: %v, project Id: %d, user: %+v", err, pid, u2)
} }
if len(users) != 0 { if len(users) != 0 {
t.Errorf("unexpected length of user list, expected: 0, the users list: %+v", users) t.Errorf("unexpected length of user list, expected: 0, the users list: %+v", users)
@ -682,6 +679,6 @@ func TestDeleteUser(t *testing.T) {
t.Errorf("Error occurred in GetUser: %v", err) t.Errorf("Error occurred in GetUser: %v", err)
} }
if user != nil { if user != nil {
t.Error("user is not nil after deletion, user: %+v", user) t.Errorf("user is not nil after deletion, user: %+v", user)
} }
} }

View File

@ -42,7 +42,7 @@ func updateInitPassword(userID int, password string) error {
} }
if user == nil { if user == nil {
log.Printf("User id: %d does not exist.", userID) log.Printf("User id: %d does not exist.", userID)
return fmt.Errorf("User id: %s does not exist.", userID) return fmt.Errorf("User id: %d does not exist.", userID)
} else if user.Salt == "" { } else if user.Salt == "" {
salt, err := dao.GenerateRandomString() salt, err := dao.GenerateRandomString()
if err != nil { if err != nil {

View File

@ -21,5 +21,5 @@ type V1Repo struct {
} }
type Repo struct { type Repo struct {
Repositories []string `json:repositories` Repositories []string `json:"repositories"`
} }

View File

@ -15,6 +15,6 @@
package models package models
type Tag struct { type Tag struct {
Version string `json:version` Version string `json:"version"`
ImageID string `json:image_id` ImageID string `json:"image_id"`
} }