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
925773db
Commit
925773db
authored
Feb 05, 2022
by
email
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: address comments
parent
226e9c15
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
45 additions
and
39 deletions
+45
-39
memo.go
api/memo.go
+5
-5
profile_dev.go
bin/server/cmd/profile_dev.go
+1
-1
root.go
bin/server/cmd/root.go
+1
-1
go.mod
go.mod
+6
-3
auth.go
server/auth.go
+4
-4
basic_auth.go
server/basic_auth.go
+4
-4
memo.go
server/memo.go
+4
-4
resource.go
server/resource.go
+2
-2
server.go
server/server.go
+2
-2
shortcut.go
server/shortcut.go
+4
-4
user.go
server/user.go
+4
-4
webhook.go
server/webhook.go
+1
-1
10001_schema.sql
store/seed/10001_schema.sql
+7
-4
No files found.
api/memo.go
View file @
925773db
...
...
@@ -18,14 +18,14 @@ type MemoCreate struct {
type
MemoPatch
struct
{
Id
int
Content
*
string
RowStatus
*
string
Content
*
string
`json:"content"`
RowStatus
*
string
`json:"rowStatus"`
}
type
MemoFind
struct
{
Id
*
int
CreatorId
*
int
RowStatus
*
string
Id
*
int
`json:"id"`
CreatorId
*
int
`json:"creatorId"`
RowStatus
*
string
`json:"rowStatus"`
}
type
MemoDelete
struct
{
...
...
bin/server/cmd/profile_dev.go
View file @
925773db
...
...
@@ -11,7 +11,7 @@ import (
func
GetDevProfile
(
dataDir
string
)
Profile
{
return
Profile
{
mode
:
"8080"
,
port
:
1234
,
port
:
8080
,
dsn
:
fmt
.
Sprintf
(
"file:%s/memos_dev.db"
,
dataDir
),
}
}
bin/server/cmd/root.go
View file @
925773db
...
...
@@ -79,7 +79,7 @@ func (m *Main) Run() error {
m
.
db
=
db
s
:=
server
.
NewServer
()
s
:=
server
.
NewServer
(
m
.
profile
.
port
)
s
.
ShortcutService
=
store
.
NewShortcutService
(
db
)
s
.
MemoService
=
store
.
NewMemoService
(
db
)
...
...
go.mod
View file @
925773db
...
...
@@ -8,9 +8,6 @@ require github.com/google/uuid v1.3.0
require (
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/labstack/echo/v4 v4.6.3
github.com/labstack/gommon v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
...
...
@@ -22,6 +19,12 @@ require (
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
)
require (
github.com/gorilla/context v1.1.1 // indirect
github.com/labstack/echo/v4 v4.6.3
github.com/labstack/gommon v0.3.1 // indirect
)
require (
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1
...
...
server/auth.go
View file @
925773db
...
...
@@ -28,7 +28,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"User not found: %s"
,
login
.
Name
))
}
// Compare the stored
hashed password, with the hashed version of the password that was received.
// Compare the stored
password
if
login
.
Password
!=
user
.
Password
{
// If the two passwords don't match, return a 401 status.
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Incorrect password"
)
.
SetInternal
(
err
)
...
...
@@ -41,7 +41,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
user
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal creat
e user response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encod
e user response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
@@ -69,7 +69,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to authenticate user"
)
.
SetInternal
(
err
)
}
if
user
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"Exist user found: %s"
,
signup
.
Name
))
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"Exist
ed
user found: %s"
,
signup
.
Name
))
}
userCreate
:=
&
api
.
UserCreate
{
...
...
@@ -89,7 +89,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
user
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal create
user response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode created
user response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
server/basic_auth.go
View file @
925773db
...
...
@@ -59,7 +59,7 @@ func removeUserSession(c echo.Context) error {
return
nil
}
// Use session in
stead of jwt in
the initial version
// Use session in the initial version
func
BasicAuthMiddleware
(
us
api
.
UserService
,
next
echo
.
HandlerFunc
)
echo
.
HandlerFunc
{
return
func
(
c
echo
.
Context
)
error
{
// Skips auth
...
...
@@ -88,13 +88,13 @@ func BasicAuthMiddleware(us api.UserService, next echo.HandlerFunc) echo.Handler
}
user
,
err
:=
us
.
FindUser
(
principalFind
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"
Server error to find user
ID: %d"
,
userId
))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"
Failed to find user by
ID: %d"
,
userId
))
.
SetInternal
(
err
)
}
if
user
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"
Failed to fi
nd user ID: %d"
,
userId
))
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"
Not fou
nd user ID: %d"
,
userId
))
}
// Stores
principalID
into context.
// Stores
userId
into context.
c
.
Set
(
getUserIdContextKey
(),
userId
)
return
next
(
c
)
}
...
...
server/memo.go
View file @
925773db
...
...
@@ -28,7 +28,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
memo
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
memo response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
memo response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
@@ -53,7 +53,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
memo
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
memo response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
memo response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
@@ -81,7 +81,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
list
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
memo list response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
memo list response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
@@ -105,7 +105,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
memo
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
memo response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
memo response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
server/resource.go
View file @
925773db
...
...
@@ -54,7 +54,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
resource
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
shortcut response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
shortcut response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
@@ -71,7 +71,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
list
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
resource list response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
resource list response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
server/server.go
View file @
925773db
...
...
@@ -22,7 +22,7 @@ type Server struct {
port
int
}
func
NewServer
()
*
Server
{
func
NewServer
(
port
int
)
*
Server
{
e
:=
echo
.
New
()
e
.
Debug
=
true
e
.
HideBanner
=
true
...
...
@@ -49,7 +49,7 @@ func NewServer() *Server {
s
:=
&
Server
{
e
:
e
,
port
:
8080
,
port
:
port
,
}
webhookGroup
:=
e
.
Group
(
"/h"
)
...
...
server/shortcut.go
View file @
925773db
...
...
@@ -27,7 +27,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
shortcut
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
shortcut response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
shortcut response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
@@ -52,7 +52,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
shortcut
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
shortcut response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
shortcut response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
@@ -69,7 +69,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
list
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
shortcut list response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
shortcut list response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
@@ -90,7 +90,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
shortcut
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
shortcut response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
shortcut response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
server/user.go
View file @
925773db
...
...
@@ -28,7 +28,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
user
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
user response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
user response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
@@ -58,7 +58,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
isUsable
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
rename check response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
rename check response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
@@ -90,7 +90,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
isValid
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
password check response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
password check response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
@@ -116,7 +116,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
user
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
user response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
user response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
server/webhook.go
View file @
925773db
...
...
@@ -42,7 +42,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
memo
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
marshal
memo response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to
encode
memo response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
store/seed/10001_schema.sql
View file @
925773db
...
...
@@ -12,7 +12,7 @@ CREATE TABLE user (
INSERT
INTO
sqlite_sequence
(
name
,
seq
)
VALUES
(
'user'
,
0
);
(
'user'
,
10
0
);
CREATE
TRIGGER
IF
NOT
EXISTS
`trigger_update_user_modification_time`
AFTER
...
...
@@ -72,7 +72,7 @@ CREATE TABLE shortcut (
INSERT
INTO
sqlite_sequence
(
name
,
seq
)
VALUES
(
'shortcut'
,
0
);
(
'shortcut'
,
10
0
);
CREATE
TRIGGER
IF
NOT
EXISTS
`trigger_update_shortcut_modification_time`
AFTER
...
...
@@ -99,6 +99,11 @@ CREATE TABLE resource (
FOREIGN
KEY
(
creator_id
)
REFERENCES
users
(
id
)
);
INSERT
INTO
sqlite_sequence
(
name
,
seq
)
VALUES
(
'resource'
,
100
);
CREATE
TRIGGER
IF
NOT
EXISTS
`trigger_update_resource_modification_time`
AFTER
UPDATE
...
...
@@ -116,10 +121,8 @@ INSERT INTO user
(
`id`
,
`name`
,
`password`
,
`open_id`
)
VALUES
(
1
,
'guest'
,
'123456'
,
'guest_open_id'
),
(
2
,
'mine'
,
'123456'
,
'mine_open_id'
);
INSERT
INTO
memo
(
`content`
,
`creator_id`
)
VALUES
(
'👋 Welcome to memos'
,
1
),
(
'👋 Welcome to memos'
,
2
);
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