mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-03 14:37:44 +01:00
go vet refactor
This commit is contained in:
parent
ed60d2245e
commit
61f12f089d
@ -87,7 +87,7 @@ func (p *ProjectAPI) Post() {
|
||||
project := models.Project{OwnerID: p.userID, Name: projectName, CreationTime: time.Now(), Public: public}
|
||||
err = dao.AddProject(project)
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ func (ra *RepositoryAPI) Get() {
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
Name string `json: "name"`
|
||||
Name string `json:"name"`
|
||||
Tags []string `json:"tags"`
|
||||
}
|
||||
|
||||
|
20
dao/base.go
20
dao/base.go
@ -22,7 +22,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
@ -74,25 +73,6 @@ func InitDB() {
|
||||
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"
|
||||
ch := make(chan int, 1)
|
||||
go func() {
|
||||
|
@ -108,9 +108,6 @@ func TestMain(m *testing.M) {
|
||||
log.Fatalf("environment variable DB_PORT is not set")
|
||||
}
|
||||
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)
|
||||
|
||||
@ -468,14 +465,14 @@ func TestGetUserByProject(t *testing.T) {
|
||||
}
|
||||
users, err := GetUserByProject(pid, u1)
|
||||
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 {
|
||||
t.Errorf("unexpected length of user list, expected: 1, the users list: %+v", users)
|
||||
}
|
||||
users, err = GetUserByProject(pid, u2)
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
2
main.go
2
main.go
@ -42,7 +42,7 @@ func updateInitPassword(userID int, password string) error {
|
||||
}
|
||||
if user == nil {
|
||||
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 == "" {
|
||||
salt, err := dao.GenerateRandomString()
|
||||
if err != nil {
|
||||
|
@ -21,5 +21,5 @@ type V1Repo struct {
|
||||
}
|
||||
|
||||
type Repo struct {
|
||||
Repositories []string `json:repositories`
|
||||
Repositories []string `json:"repositories"`
|
||||
}
|
||||
|
@ -15,6 +15,6 @@
|
||||
package models
|
||||
|
||||
type Tag struct {
|
||||
Version string `json:version`
|
||||
ImageID string `json:image_id`
|
||||
Version string `json:"version"`
|
||||
ImageID string `json:"image_id"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user