update utils file structure

This commit is contained in:
steven
2021-12-12 14:39:28 +08:00
parent b20741cca8
commit 63d9f092c5
6 changed files with 17 additions and 17 deletions

View File

@ -7,9 +7,9 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"memos/api/e" "memos/api/e"
"memos/common"
"memos/config" "memos/config"
"memos/store" "memos/store"
"memos/utils"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -222,7 +222,7 @@ func handleGithubAuthCallback(w http.ResponseWriter, r *http.Request) {
username := githubUser.Name username := githubUser.Name
usernameUsable, _ := store.CheckUsernameUsable(username) usernameUsable, _ := store.CheckUsernameUsable(username)
for !usernameUsable { for !usernameUsable {
username = githubUser.Name + common.GenUUID() username = githubUser.Name + utils.GenUUID()
usernameUsable, _ = store.CheckUsernameUsable(username) usernameUsable, _ = store.CheckUsernameUsable(username)
} }
user, _ = store.CreateNewUser(username, username, githubUser.Login, "") user, _ = store.CreateNewUser(username, username, githubUser.Login, "")

View File

@ -1,9 +1,9 @@
package api package api
import ( import (
"memos/common" "memos/utils"
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
) )
var SessionStore = sessions.NewCookieStore([]byte(common.GenUUID())) var SessionStore = sessions.NewCookieStore([]byte(utils.GenUUID()))

View File

@ -1,7 +1,7 @@
package store package store
import ( import (
"memos/common" "memos/utils"
"strings" "strings"
) )
@ -15,9 +15,9 @@ type Memo struct {
} }
func CreateNewMemo(content string, userId string) (Memo, error) { func CreateNewMemo(content string, userId string) (Memo, error) {
nowDateTimeStr := common.GetNowDateTimeStr() nowDateTimeStr := utils.GetNowDateTimeStr()
newMemo := Memo{ newMemo := Memo{
Id: common.GenUUID(), Id: utils.GenUUID(),
Content: content, Content: content,
UserId: userId, UserId: userId,
DeletedAt: "", DeletedAt: "",
@ -48,7 +48,7 @@ func UpdateMemo(id string, memoPatch *MemoPatch) (Memo, error) {
memo.DeletedAt = *v memo.DeletedAt = *v
set, args = append(set, "deleted_at=?"), append(args, *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) args = append(args, id)
sqlQuery := `UPDATE memos SET ` + strings.Join(set, ",") + ` WHERE id=?` sqlQuery := `UPDATE memos SET ` + strings.Join(set, ",") + ` WHERE id=?`

View File

@ -1,7 +1,7 @@
package store package store
import ( import (
"memos/common" "memos/utils"
"strings" "strings"
) )
@ -16,9 +16,9 @@ type Query struct {
} }
func CreateNewQuery(title string, querystring string, userId string) (Query, error) { func CreateNewQuery(title string, querystring string, userId string) (Query, error) {
nowDateTimeStr := common.GetNowDateTimeStr() nowDateTimeStr := utils.GetNowDateTimeStr()
newQuery := Query{ newQuery := Query{
Id: common.GenUUID(), Id: utils.GenUUID(),
Title: title, Title: title,
Querystring: querystring, Querystring: querystring,
UserId: userId, UserId: userId,
@ -55,7 +55,7 @@ func UpdateQuery(id string, queryPatch *QueryPatch) (Query, error) {
query.PinnedAt = *v query.PinnedAt = *v
set, args = append(set, "pinned_at=?"), append(args, *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) args = append(args, id)
sqlQuery := `UPDATE queries SET ` + strings.Join(set, ",") + ` WHERE id=?` sqlQuery := `UPDATE queries SET ` + strings.Join(set, ",") + ` WHERE id=?`

View File

@ -3,7 +3,7 @@ package store
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"memos/common" "memos/utils"
"strings" "strings"
) )
@ -18,9 +18,9 @@ type User struct {
} }
func CreateNewUser(username string, password string, githubName string, wxOpenId string) (User, error) { func CreateNewUser(username string, password string, githubName string, wxOpenId string) (User, error) {
nowDateTimeStr := common.GetNowDateTimeStr() nowDateTimeStr := utils.GetNowDateTimeStr()
newUser := User{ newUser := User{
Id: common.GenUUID(), Id: utils.GenUUID(),
Username: username, Username: username,
Password: password, Password: password,
WxOpenId: wxOpenId, WxOpenId: wxOpenId,
@ -62,7 +62,7 @@ func UpdateUser(id string, userPatch *UserPatch) (User, error) {
user.WxOpenId = *v user.WxOpenId = *v
set, args = append(set, "wx_open_id=?"), append(args, *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) args = append(args, id)
sqlQuery := `UPDATE users SET ` + strings.Join(set, ",") + ` WHERE id=?` sqlQuery := `UPDATE users SET ` + strings.Join(set, ",") + ` WHERE id=?`

View File

@ -1,4 +1,4 @@
package common package utils
import ( import (
"time" "time"