From 3229d9ea4583b7b3cce9c3e3ffe2dac4c9006920 Mon Sep 17 00:00:00 2001 From: yinw Date: Fri, 26 Feb 2016 16:07:20 +0800 Subject: [PATCH] add json annotations for model --- dao/dao_test.go | 4 ---- models/access_log.go | 8 ++++---- models/notification.go | 6 +++--- models/project.go | 6 +++--- models/project_role.go | 6 +++--- models/user.go | 6 +++--- models/user_project_role.go | 6 +++--- 7 files changed, 19 insertions(+), 23 deletions(-) diff --git a/dao/dao_test.go b/dao/dao_test.go index e1218b376..5cf8d4366 100644 --- a/dao/dao_test.go +++ b/dao/dao_test.go @@ -16,7 +16,6 @@ package dao import ( "fmt" - // "fmt" "log" "os" "testing" @@ -116,11 +115,8 @@ func TestMain(m *testing.M) { os.Setenv("MYSQL_USR", dbUser) os.Setenv("MYSQL_PWD", dbPassword) os.Setenv("AUTH_MODE", "db_auth") - fmt.Println("a") InitDB() - fmt.Println("b") clearUp(username) - fmt.Println("c") os.Exit(m.Run()) } diff --git a/models/access_log.go b/models/access_log.go index 9f23a6261..6894d3495 100644 --- a/models/access_log.go +++ b/models/access_log.go @@ -19,11 +19,11 @@ import ( ) type AccessLog struct { - LogID int `orm:"column(log_id)"` - UserID int `orm:"column(user_id)"` - ProjectID int64 `orm:"column(project_id)"` + LogID int `orm:"column(log_id)" json:"LogId"` + UserID int `orm:"column(user_id)" json:"UserId"` + ProjectID int64 `orm:"column(project_id)" json:"ProjectId"` RepoName string `orm:"column(repo_name)"` - GUID string `orm:"column(GUID)"` + GUID string `orm:"column(GUID)" json:"Guid"` Operation string `orm:"column(operation)"` OpTime time.Time `orm:"column(op_time)"` Username string diff --git a/models/notification.go b/models/notification.go index 4be24a68d..6c2933bf7 100644 --- a/models/notification.go +++ b/models/notification.go @@ -23,7 +23,7 @@ type Notification struct { } type Event struct { - ID string + ID string `json:"Id"` TimeStamp time.Time Action string Target *Target @@ -35,7 +35,7 @@ type Target struct { MediaType string Digest string Repository string - URL string + URL string `json:"Url"` } type Actor struct { @@ -43,7 +43,7 @@ type Actor struct { } type Request struct { - ID string + ID string `json:"Id"` Method string UserAgent string } diff --git a/models/project.go b/models/project.go index 2196a3983..5ff4584ac 100644 --- a/models/project.go +++ b/models/project.go @@ -19,13 +19,13 @@ import ( ) type Project struct { - ProjectID int64 `orm:"column(project_id)"` - OwnerID int `orm:"column(owner_id)"` + ProjectID int64 `orm:"column(project_id)" json:"ProjectId"` + OwnerID int `orm:"column(owner_id)" json:"OwnerId"` Name string `orm:"column(name)"` CreationTime time.Time `orm:"column(creation_time)"` CreationTimeStr string Deleted int `orm:"column(deleted)"` - UserID int + UserID int `json:"UserId"` OwnerName string Public int `orm:"column(public)"` //This field does not have correspondent column in DB, this is just for UI to disable button diff --git a/models/project_role.go b/models/project_role.go index cd85bb829..88da32d6a 100644 --- a/models/project_role.go +++ b/models/project_role.go @@ -15,7 +15,7 @@ package models type ProjectRole struct { - PrID int `orm:"column(pr_id)"` - ProjectID int64 `orm:"column(project_id)"` - RoleID int `orm:"column(role_id)"` + PrID int `orm:"column(pr_id)" json:"PrId"` + ProjectID int64 `orm:"column(project_id)" json:"ProjectId"` + RoleID int `orm:"column(role_id)" json:"RoleId"` } diff --git a/models/user.go b/models/user.go index 6ee909a38..8640c878a 100644 --- a/models/user.go +++ b/models/user.go @@ -15,7 +15,7 @@ package models type User struct { - UserID int `orm:"column(user_id)"` + UserID int `orm:"column(user_id)" json:"UserId"` Username string `orm:"column(username)"` Email string `orm:"column(email)"` Password string `orm:"column(password)"` @@ -23,9 +23,9 @@ type User struct { Comment string `orm:"column(comment)"` Deleted int `orm:"column(deleted)"` Rolename string - RoleID int + RoleID int `json:"RoleId"` RoleList []Role HasAdminRole int - ResetUUID string `orm:"column(reset_uuid)"` + ResetUUID string `orm:"column(reset_uuid)" json:"ResetUuid"` Salt string `orm:"column(salt)"` } diff --git a/models/user_project_role.go b/models/user_project_role.go index fbdff1f80..d6e52d1e0 100644 --- a/models/user_project_role.go +++ b/models/user_project_role.go @@ -15,7 +15,7 @@ package models type UserProjectRole struct { - UprID int `orm:"column(upr_id)"` - UserID int `orm:"column(user_id)"` - PrID int64 `orm:"column(pr_id)"` + UprID int `orm:"column(upr_id)" json:"UprId"` + UserID int `orm:"column(user_id)" json:"UserId"` + PrID int64 `orm:"column(pr_id)" json:"PrId"` }