Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
63d9f092
Commit
63d9f092
authored
Dec 12, 2021
by
steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update utils file structure
parent
b20741cc
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
17 additions
and
17 deletions
+17
-17
auth.go
api/auth.go
+2
-2
session.go
api/session.go
+2
-2
memo.go
store/memo.go
+4
-4
query.go
store/query.go
+4
-4
user.go
store/user.go
+4
-4
common.go
utils/common.go
+1
-1
No files found.
api/auth.go
View file @
63d9f092
...
...
@@ -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
,
""
)
...
...
api/session.go
View file @
63d9f092
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
()))
store/memo.go
View file @
63d9f092
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=?`
...
...
store/query.go
View file @
63d9f092
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=?`
...
...
store/user.go
View file @
63d9f092
...
...
@@ -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=?`
...
...
common/utils
.go
→
utils/common
.go
View file @
63d9f092
package
common
package
utils
import
(
"time"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment