diff --git a/api/auth.go b/api/auth.go index e2d22c46..da446dde 100644 --- a/api/auth.go +++ b/api/auth.go @@ -7,9 +7,9 @@ import ( "fmt" "io/ioutil" "memos/api/e" - "memos/common" "memos/config" "memos/store" + "memos/utils" "net/http" "github.com/gorilla/mux" @@ -222,7 +222,7 @@ func handleGithubAuthCallback(w http.ResponseWriter, r *http.Request) { username := githubUser.Name usernameUsable, _ := store.CheckUsernameUsable(username) for !usernameUsable { - username = githubUser.Name + common.GenUUID() + username = githubUser.Name + utils.GenUUID() usernameUsable, _ = store.CheckUsernameUsable(username) } user, _ = store.CreateNewUser(username, username, githubUser.Login, "") diff --git a/api/session.go b/api/session.go index c4d80515..b6935633 100644 --- a/api/session.go +++ b/api/session.go @@ -1,9 +1,9 @@ package api import ( - "memos/common" + "memos/utils" "github.com/gorilla/sessions" ) -var SessionStore = sessions.NewCookieStore([]byte(common.GenUUID())) +var SessionStore = sessions.NewCookieStore([]byte(utils.GenUUID())) diff --git a/store/memo.go b/store/memo.go index 8bcb4e7b..64acc4f9 100644 --- a/store/memo.go +++ b/store/memo.go @@ -1,7 +1,7 @@ package store import ( - "memos/common" + "memos/utils" "strings" ) @@ -15,9 +15,9 @@ type Memo struct { } func CreateNewMemo(content string, userId string) (Memo, error) { - nowDateTimeStr := common.GetNowDateTimeStr() + nowDateTimeStr := utils.GetNowDateTimeStr() newMemo := Memo{ - Id: common.GenUUID(), + Id: utils.GenUUID(), Content: content, UserId: userId, DeletedAt: "", @@ -48,7 +48,7 @@ func UpdateMemo(id string, memoPatch *MemoPatch) (Memo, error) { memo.DeletedAt = *v set, args = append(set, "deleted_at=?"), append(args, *v) } - set, args = append(set, "updated_at=?"), append(args, common.GetNowDateTimeStr()) + set, args = append(set, "updated_at=?"), append(args, utils.GetNowDateTimeStr()) args = append(args, id) sqlQuery := `UPDATE memos SET ` + strings.Join(set, ",") + ` WHERE id=?` diff --git a/store/query.go b/store/query.go index 97e0163d..7a8aab1a 100644 --- a/store/query.go +++ b/store/query.go @@ -1,7 +1,7 @@ package store import ( - "memos/common" + "memos/utils" "strings" ) @@ -16,9 +16,9 @@ type Query struct { } func CreateNewQuery(title string, querystring string, userId string) (Query, error) { - nowDateTimeStr := common.GetNowDateTimeStr() + nowDateTimeStr := utils.GetNowDateTimeStr() newQuery := Query{ - Id: common.GenUUID(), + Id: utils.GenUUID(), Title: title, Querystring: querystring, UserId: userId, @@ -55,7 +55,7 @@ func UpdateQuery(id string, queryPatch *QueryPatch) (Query, error) { query.PinnedAt = *v set, args = append(set, "pinned_at=?"), append(args, *v) } - set, args = append(set, "updated_at=?"), append(args, common.GetNowDateTimeStr()) + set, args = append(set, "updated_at=?"), append(args, utils.GetNowDateTimeStr()) args = append(args, id) sqlQuery := `UPDATE queries SET ` + strings.Join(set, ",") + ` WHERE id=?` diff --git a/store/user.go b/store/user.go index bbdee291..cf5b6aba 100644 --- a/store/user.go +++ b/store/user.go @@ -3,7 +3,7 @@ package store import ( "database/sql" "fmt" - "memos/common" + "memos/utils" "strings" ) @@ -18,9 +18,9 @@ type User struct { } func CreateNewUser(username string, password string, githubName string, wxOpenId string) (User, error) { - nowDateTimeStr := common.GetNowDateTimeStr() + nowDateTimeStr := utils.GetNowDateTimeStr() newUser := User{ - Id: common.GenUUID(), + Id: utils.GenUUID(), Username: username, Password: password, WxOpenId: wxOpenId, @@ -62,7 +62,7 @@ func UpdateUser(id string, userPatch *UserPatch) (User, error) { user.WxOpenId = *v set, args = append(set, "wx_open_id=?"), append(args, *v) } - set, args = append(set, "updated_at=?"), append(args, common.GetNowDateTimeStr()) + set, args = append(set, "updated_at=?"), append(args, utils.GetNowDateTimeStr()) args = append(args, id) sqlQuery := `UPDATE users SET ` + strings.Join(set, ",") + ` WHERE id=?` diff --git a/common/utils.go b/utils/common.go similarity index 92% rename from common/utils.go rename to utils/common.go index db76158a..b2d5ec8d 100644 --- a/common/utils.go +++ b/utils/common.go @@ -1,4 +1,4 @@ -package common +package utils import ( "time"