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
d11bd30e
Commit
d11bd30e
authored
Aug 28, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: tweak logger
parent
de980fb7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
14 deletions
+16
-14
profile.go
server/profile/profile.go
+3
-2
runner.go
server/runner/version/runner.go
+2
-2
server.go
server/server.go
+3
-3
migrator.go
store/migrator.go
+3
-2
store.go
test/store/store.go
+5
-5
No files found.
server/profile/profile.go
View file @
d11bd30e
...
@@ -2,6 +2,7 @@ package profile
...
@@ -2,6 +2,7 @@ package profile
import
(
import
(
"fmt"
"fmt"
"log/slog"
"os"
"os"
"path/filepath"
"path/filepath"
"runtime"
"runtime"
...
@@ -68,7 +69,7 @@ func (p *Profile) Validate() error {
...
@@ -68,7 +69,7 @@ func (p *Profile) Validate() error {
p
.
Data
=
filepath
.
Join
(
os
.
Getenv
(
"ProgramData"
),
"memos"
)
p
.
Data
=
filepath
.
Join
(
os
.
Getenv
(
"ProgramData"
),
"memos"
)
if
_
,
err
:=
os
.
Stat
(
p
.
Data
);
os
.
IsNotExist
(
err
)
{
if
_
,
err
:=
os
.
Stat
(
p
.
Data
);
os
.
IsNotExist
(
err
)
{
if
err
:=
os
.
MkdirAll
(
p
.
Data
,
0770
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
p
.
Data
,
0770
);
err
!=
nil
{
fmt
.
Printf
(
"Failed to create data directory: %s, err: %+v
\n
"
,
p
.
Data
,
err
)
slog
.
Error
(
"failed to create data directory"
,
slog
.
String
(
"data"
,
p
.
Data
),
slog
.
String
(
"error"
,
err
.
Error
())
)
return
err
return
err
}
}
}
}
...
@@ -79,7 +80,7 @@ func (p *Profile) Validate() error {
...
@@ -79,7 +80,7 @@ func (p *Profile) Validate() error {
dataDir
,
err
:=
checkDataDir
(
p
.
Data
)
dataDir
,
err
:=
checkDataDir
(
p
.
Data
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Printf
(
"Failed to check dsn: %s, err: %+v
\n
"
,
dataDir
,
err
)
slog
.
Error
(
"failed to check dsn"
,
slog
.
String
(
"data"
,
dataDir
),
slog
.
String
(
"error"
,
err
.
Error
())
)
return
err
return
err
}
}
...
...
server/runner/version/runner.go
View file @
d11bd30e
...
@@ -5,11 +5,11 @@ import (
...
@@ -5,11 +5,11 @@ import (
"bytes"
"bytes"
"context"
"context"
"encoding/json"
"encoding/json"
"fmt"
"net/http"
"net/http"
"time"
"time"
"github.com/pkg/errors"
"github.com/pkg/errors"
"golang.org/x/exp/slog"
storepb
"github.com/usememos/memos/proto/gen/store"
storepb
"github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/server/profile"
...
@@ -115,7 +115,7 @@ func (r *Runner) Check(ctx context.Context) {
...
@@ -115,7 +115,7 @@ func (r *Runner) Check(ctx context.Context) {
ActivityId
:
&
activity
.
ID
,
ActivityId
:
&
activity
.
ID
,
},
},
});
err
!=
nil
{
});
err
!=
nil
{
fmt
.
Printf
(
"failed to create inbox: %s
\n
"
,
err
)
slog
.
Error
(
"failed to create inbox"
,
slog
.
String
(
"error"
,
err
.
Error
())
)
}
}
}
}
...
...
server/server.go
View file @
d11bd30e
...
@@ -129,15 +129,15 @@ func (s *Server) Shutdown(ctx context.Context) {
...
@@ -129,15 +129,15 @@ func (s *Server) Shutdown(ctx context.Context) {
// Shutdown echo server.
// Shutdown echo server.
if
err
:=
s
.
echoServer
.
Shutdown
(
ctx
);
err
!=
nil
{
if
err
:=
s
.
echoServer
.
Shutdown
(
ctx
);
err
!=
nil
{
fmt
.
Printf
(
"failed to shutdown server, error: %v
\n
"
,
err
)
slog
.
Error
(
"failed to shutdown server"
,
slog
.
String
(
"error"
,
err
.
Error
())
)
}
}
// Close database connection.
// Close database connection.
if
err
:=
s
.
Store
.
Close
();
err
!=
nil
{
if
err
:=
s
.
Store
.
Close
();
err
!=
nil
{
fmt
.
Printf
(
"failed to close database, error: %v
\n
"
,
err
)
slog
.
Error
(
"failed to close database"
,
slog
.
String
(
"error"
,
err
.
Error
())
)
}
}
fmt
.
Printf
(
"memos stopped properly
\n
"
)
slog
.
Info
(
"memos stopped properly
"
)
}
}
func
(
s
*
Server
)
StartBackgroundRunners
(
ctx
context
.
Context
)
{
func
(
s
*
Server
)
StartBackgroundRunners
(
ctx
context
.
Context
)
{
...
...
store/migrator.go
View file @
d11bd30e
...
@@ -72,7 +72,7 @@ func (s *Store) Migrate(ctx context.Context) error {
...
@@ -72,7 +72,7 @@ func (s *Store) Migrate(ctx context.Context) error {
}
}
defer
tx
.
Rollback
()
defer
tx
.
Rollback
()
fmt
.
Println
(
"start migration"
)
slog
.
Info
(
"start migration"
,
slog
.
String
(
"currentSchemaVersion"
,
latestMigrationHistoryVersion
),
slog
.
String
(
"targetSchemaVersion"
,
schemaVersion
)
)
for
_
,
filePath
:=
range
filePaths
{
for
_
,
filePath
:=
range
filePaths
{
fileSchemaVersion
,
err
:=
s
.
getSchemaVersionOfMigrateScript
(
filePath
)
fileSchemaVersion
,
err
:=
s
.
getSchemaVersionOfMigrateScript
(
filePath
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -93,7 +93,7 @@ func (s *Store) Migrate(ctx context.Context) error {
...
@@ -93,7 +93,7 @@ func (s *Store) Migrate(ctx context.Context) error {
if
err
:=
tx
.
Commit
();
err
!=
nil
{
if
err
:=
tx
.
Commit
();
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to commit transaction"
)
return
errors
.
Wrap
(
err
,
"failed to commit transaction"
)
}
}
fmt
.
Println
(
"end migrate"
)
slog
.
Info
(
"end migrate"
)
// Upsert the current schema version to migration_history.
// Upsert the current schema version to migration_history.
if
_
,
err
=
s
.
driver
.
UpsertMigrationHistory
(
ctx
,
&
UpsertMigrationHistory
{
if
_
,
err
=
s
.
driver
.
UpsertMigrationHistory
(
ctx
,
&
UpsertMigrationHistory
{
...
@@ -255,6 +255,7 @@ func (s *Store) normalizedMigrationHistoryList(ctx context.Context) error {
...
@@ -255,6 +255,7 @@ func (s *Store) normalizedMigrationHistoryList(ctx context.Context) error {
sort
.
Sort
(
version
.
SortVersion
(
versions
))
sort
.
Sort
(
version
.
SortVersion
(
versions
))
latestVersion
:=
versions
[
len
(
versions
)
-
1
]
latestVersion
:=
versions
[
len
(
versions
)
-
1
]
latestMinorVersion
:=
version
.
GetMinorVersion
(
latestVersion
)
latestMinorVersion
:=
version
.
GetMinorVersion
(
latestVersion
)
// If the latest version is greater than 0.22, return.
// If the latest version is greater than 0.22, return.
// As of 0.22, the migration history is already normalized.
// As of 0.22, the migration history is already normalized.
if
version
.
IsVersionGreaterThan
(
latestMinorVersion
,
"0.22"
)
{
if
version
.
IsVersionGreaterThan
(
latestMinorVersion
,
"0.22"
)
{
...
...
test/store/store.go
View file @
d11bd30e
...
@@ -2,7 +2,7 @@ package teststore
...
@@ -2,7 +2,7 @@ package teststore
import
(
import
(
"context"
"context"
"
fmt
"
"
log/slog
"
"testing"
"testing"
// sqlite driver.
// sqlite driver.
...
@@ -18,13 +18,13 @@ func NewTestingStore(ctx context.Context, t *testing.T) *store.Store {
...
@@ -18,13 +18,13 @@ func NewTestingStore(ctx context.Context, t *testing.T) *store.Store {
profile
:=
test
.
GetTestingProfile
(
t
)
profile
:=
test
.
GetTestingProfile
(
t
)
dbDriver
,
err
:=
db
.
NewDBDriver
(
profile
)
dbDriver
,
err
:=
db
.
NewDBDriver
(
profile
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Printf
(
"failed to create db driver, error: %+v
\n
"
,
err
)
slog
.
Error
(
"failed to create db driver"
,
slog
.
String
(
"error"
,
err
.
Error
())
)
}
}
resetTestingDB
(
ctx
,
profile
,
dbDriver
)
resetTestingDB
(
ctx
,
profile
,
dbDriver
)
store
:=
store
.
New
(
dbDriver
,
profile
)
store
:=
store
.
New
(
dbDriver
,
profile
)
if
err
:=
store
.
Migrate
(
ctx
);
err
!=
nil
{
if
err
:=
store
.
Migrate
(
ctx
);
err
!=
nil
{
fmt
.
Printf
(
"failed to migrate db, error: %+v
\n
"
,
err
)
slog
.
Error
(
"failed to migrate db"
,
slog
.
String
(
"error"
,
err
.
Error
())
)
}
}
return
store
return
store
}
}
...
@@ -48,7 +48,7 @@ func resetTestingDB(ctx context.Context, profile *profile.Profile, dbDriver stor
...
@@ -48,7 +48,7 @@ func resetTestingDB(ctx context.Context, profile *profile.Profile, dbDriver stor
DROP TABLE IF EXISTS webhook;
DROP TABLE IF EXISTS webhook;
DROP TABLE IF EXISTS reaction;`
)
DROP TABLE IF EXISTS reaction;`
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Printf
(
"failed to reset testing db, error: %+v
\n
"
,
err
)
slog
.
Error
(
"failed to reset testing db"
,
slog
.
String
(
"error"
,
err
.
Error
())
)
panic
(
err
)
panic
(
err
)
}
}
}
else
if
profile
.
Driver
==
"postgres"
{
}
else
if
profile
.
Driver
==
"postgres"
{
...
@@ -69,7 +69,7 @@ func resetTestingDB(ctx context.Context, profile *profile.Profile, dbDriver stor
...
@@ -69,7 +69,7 @@ func resetTestingDB(ctx context.Context, profile *profile.Profile, dbDriver stor
DROP TABLE IF EXISTS webhook CASCADE;
DROP TABLE IF EXISTS webhook CASCADE;
DROP TABLE IF EXISTS reaction CASCADE;`
)
DROP TABLE IF EXISTS reaction CASCADE;`
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Printf
(
"failed to reset testing db, error: %+v
\n
"
,
err
)
slog
.
Error
(
"failed to reset testing db"
,
slog
.
String
(
"error"
,
err
.
Error
())
)
panic
(
err
)
panic
(
err
)
}
}
}
}
...
...
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