Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: address comments

email925773dbd631
diff --git a/api/memo.go b/api/memo.go
index f1255f24f..3b2495ee5 100644
--- a/api/memo.go
+++ b/api/memo.go
@@ -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 {
diff --git a/bin/server/cmd/profile_dev.go b/bin/server/cmd/profile_dev.go
index 0c2eadb33..15a7dac8b 100644
--- a/bin/server/cmd/profile_dev.go
+++ b/bin/server/cmd/profile_dev.go
@@ -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),
}
}
diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.go
index bde1bac4b..1a52340f1 100644
--- a/bin/server/cmd/root.go
+++ b/bin/server/cmd/root.go
@@ -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)
diff --git a/go.mod b/go.mod
index 4ee1d61ff..f116b7428 100644
--- a/go.mod
+++ b/go.mod
@@ -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
diff --git a/server/auth.go b/server/auth.go
index abe2ded3e..085346adc 100644
--- a/server/auth.go
+++ b/server/auth.go
@@ -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 create user response").SetInternal(err)
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode 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("Existed 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
diff --git a/server/basic_auth.go b/server/basic_auth.go
index d38287d46..5a15605ec 100644
--- a/server/basic_auth.go
+++ b/server/basic_auth.go
@@ -59,7 +59,7 @@ func removeUserSession(c echo.Context) error {
return nil
}
-// Use session instead 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 find user ID: %d", userId))
+ return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Not found user ID: %d", userId))
}
- // Stores principalID into context.
+ // Stores userId into context.
c.Set(getUserIdContextKey(), userId)
return next(c)
}
diff --git a/server/memo.go b/server/memo.go
index a2be2d1b4..b433fa14a 100644
--- a/server/memo.go
+++ b/server/memo.go
@@ -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
diff --git a/server/resource.go b/server/resource.go
index 5841e467b..38b91d2cf 100644
--- a/server/resource.go
+++ b/server/resource.go
@@ -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
diff --git a/server/server.go b/server/server.go
index 0f26e52ab..4693ab53c 100644
--- a/server/server.go
+++ b/server/server.go
@@ -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")
diff --git a/server/shortcut.go b/server/shortcut.go
index 5d2063e9c..47b709784 100644
--- a/server/shortcut.go
+++ b/server/shortcut.go
@@ -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
diff --git a/server/user.go b/server/user.go
index f8ade7cf9..c444ab82f 100644
--- a/server/user.go
+++ b/server/user.go
@@ -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
diff --git a/server/webhook.go b/server/webhook.go
index c6d734aa1..017e7efb1 100644
--- a/server/webhook.go
+++ b/server/webhook.go
@@ -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
diff --git a/store/seed/10001_schema.sql b/store/seed/10001_schema.sql
index cdfdea613..76086342f 100644
--- a/store/seed/10001_schema.sql
+++ b/store/seed/10001_schema.sql
@@ -12,7 +12,7 @@ CREATE TABLE user (
INSERT INTO
sqlite_sequence (name, seq)
VALUES
- ('user', 0);
+ ('user', 100);
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', 100);
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);