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
7d040701
Commit
7d040701
authored
Aug 24, 2022
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: make `golangci-lint` happy
parent
0e4e2e4b
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
130 additions
and
35 deletions
+130
-35
tests.yml
.github/workflows/tests.yml
+18
-0
.golangci.yaml
.golangci.yaml
+62
-0
user_setting.go
api/user_setting.go
+1
-1
root.go
bin/server/cmd/root.go
+8
-4
main.go
bin/server/main.go
+10
-2
error.go
common/error.go
+1
-1
profile.go
server/profile/profile.go
+3
-3
tag.go
server/tag.go
+1
-1
db.go
store/db/db.go
+4
-18
migration_history.go
store/db/migration_history.go
+11
-2
memo_organizer.go
store/memo_organizer.go
+4
-0
store.go
store/store.go
+2
-2
user.go
store/user.go
+4
-0
user_setting.go
store/user_setting.go
+1
-1
No files found.
.github/workflows/tests.yml
View file @
7d040701
...
@@ -27,3 +27,21 @@ jobs:
...
@@ -27,3 +27,21 @@ jobs:
with
:
with
:
args
:
-v
args
:
-v
skip-cache
:
true
skip-cache
:
true
go-tests
:
runs-on
:
ubuntu-latest
timeout-minutes
:
15
steps
:
-
name
:
Checkout
uses
:
actions/checkout@v3
with
:
fetch-depth
:
0
-
uses
:
actions/setup-go@v3
with
:
go-version
:
1.18
check-latest
:
true
cache
:
true
-
name
:
Run all tests
run
:
go test -v ./... | tee test.log; exit ${PIPESTATUS[0]}
-
name
:
Pretty print tests running time
run
:
grep --color=never -e '--- PASS:' -e '--- FAIL:' test.log | sed 's/[:()]//g' | awk '{print $2,$3,$4}' | sort -t' ' -nk3 -r | awk '{sum += $3; print $1,$2,$3,sum"s"}'
.golangci.yaml
0 → 100644
View file @
7d040701
linters
:
enable
:
-
goimports
-
revive
-
govet
-
staticcheck
-
misspell
-
gocritic
-
sqlclosecheck
-
rowserrcheck
-
nilerr
-
godot
issues
:
exclude
:
-
Rollback
linters-settings
:
revive
:
enable-all-rules
:
true
rules
:
-
name
:
file-header
disabled
:
true
-
name
:
line-length-limit
disabled
:
true
-
name
:
function-length
disabled
:
true
-
name
:
max-public-structs
disabled
:
true
-
name
:
function-result-limit
disabled
:
true
-
name
:
banned-characters
disabled
:
true
-
name
:
argument-limit
disabled
:
true
-
name
:
cognitive-complexity
disabled
:
true
-
name
:
cyclomatic
disabled
:
true
-
name
:
confusing-results
disabled
:
true
-
name
:
add-constant
disabled
:
true
-
name
:
flag-parameter
disabled
:
true
-
name
:
nested-structs
disabled
:
true
-
name
:
import-shadowing
disabled
:
true
-
name
:
early-return
disabled
:
true
gocritic
:
disabled-checks
:
-
ifElseChain
govet
:
settings
:
printf
:
funcs
:
-
common.Errorf
forbidigo
:
forbid
:
-
'
fmt\.Errorf(#
Please
use
errors\.Wrap\|Wrapf\|Errorf
instead)?'
api/user_setting.go
View file @
7d040701
...
@@ -10,7 +10,7 @@ type UserSettingKey string
...
@@ -10,7 +10,7 @@ type UserSettingKey string
const
(
const
(
// UserSettingLocaleKey is the key type for user locale.
// UserSettingLocaleKey is the key type for user locale.
UserSettingLocaleKey
UserSettingKey
=
"locale"
UserSettingLocaleKey
UserSettingKey
=
"locale"
// UserSettingMemoVisibilityKey is the key type for user p
er
ference memo default visibility.
// UserSettingMemoVisibilityKey is the key type for user p
re
ference memo default visibility.
UserSettingMemoVisibilityKey
UserSettingKey
=
"memoVisibility"
UserSettingMemoVisibilityKey
UserSettingKey
=
"memoVisibility"
)
)
...
...
bin/server/cmd/root.go
View file @
7d040701
...
@@ -3,7 +3,6 @@ package cmd
...
@@ -3,7 +3,6 @@ package cmd
import
(
import
(
"context"
"context"
"fmt"
"fmt"
"os"
"github.com/usememos/memos/server"
"github.com/usememos/memos/server"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/server/profile"
...
@@ -41,8 +40,11 @@ func Run(profile *profile.Profile) error {
...
@@ -41,8 +40,11 @@ func Run(profile *profile.Profile) error {
return
s
.
Run
()
return
s
.
Run
()
}
}
func
Execute
()
{
func
Execute
()
error
{
profile
:=
profile
.
GetProfile
()
profile
,
err
:=
profile
.
GetProfile
()
if
err
!=
nil
{
return
err
}
println
(
"---"
)
println
(
"---"
)
println
(
"profile"
)
println
(
"profile"
)
...
@@ -54,6 +56,8 @@ func Execute() {
...
@@ -54,6 +56,8 @@ func Execute() {
if
err
:=
Run
(
profile
);
err
!=
nil
{
if
err
:=
Run
(
profile
);
err
!=
nil
{
fmt
.
Printf
(
"error: %+v
\n
"
,
err
)
fmt
.
Printf
(
"error: %+v
\n
"
,
err
)
os
.
Exit
(
1
)
return
err
}
}
return
nil
}
}
bin/server/main.go
View file @
7d040701
package
main
package
main
import
"github.com/usememos/memos/bin/server/cmd"
import
(
"os"
_
"github.com/mattn/go-sqlite3"
"github.com/usememos/memos/bin/server/cmd"
)
func
main
()
{
func
main
()
{
cmd
.
Execute
()
if
err
:=
cmd
.
Execute
();
err
!=
nil
{
os
.
Exit
(
1
)
}
}
}
common/error.go
View file @
7d040701
...
@@ -9,7 +9,7 @@ type Code int
...
@@ -9,7 +9,7 @@ type Code int
// Application error codes.
// Application error codes.
const
(
const
(
// 0 ~ 99 general error
// 0 ~ 99 general error
.
Ok
Code
=
0
Ok
Code
=
0
Internal
Code
=
1
Internal
Code
=
1
NotAuthorized
Code
=
2
NotAuthorized
Code
=
2
...
...
server/profile/profile.go
View file @
7d040701
...
@@ -45,7 +45,7 @@ func checkDSN(dataDir string) (string, error) {
...
@@ -45,7 +45,7 @@ func checkDSN(dataDir string) (string, error) {
}
}
// GetDevProfile will return a profile for dev or prod.
// GetDevProfile will return a profile for dev or prod.
func
GetProfile
()
*
Profile
{
func
GetProfile
()
(
*
Profile
,
error
)
{
profile
:=
Profile
{}
profile
:=
Profile
{}
flag
.
StringVar
(
&
profile
.
Mode
,
"mode"
,
"dev"
,
"mode of server"
)
flag
.
StringVar
(
&
profile
.
Mode
,
"mode"
,
"dev"
,
"mode of server"
)
flag
.
IntVar
(
&
profile
.
Port
,
"port"
,
8080
,
"port of server"
)
flag
.
IntVar
(
&
profile
.
Port
,
"port"
,
8080
,
"port of server"
)
...
@@ -63,12 +63,12 @@ func GetProfile() *Profile {
...
@@ -63,12 +63,12 @@ func GetProfile() *Profile {
dataDir
,
err
:=
checkDSN
(
profile
.
Data
)
dataDir
,
err
:=
checkDSN
(
profile
.
Data
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Printf
(
"Failed to check dsn: %s, err: %+v
\n
"
,
dataDir
,
err
)
fmt
.
Printf
(
"Failed to check dsn: %s, err: %+v
\n
"
,
dataDir
,
err
)
os
.
Exit
(
1
)
return
nil
,
err
}
}
profile
.
Data
=
dataDir
profile
.
Data
=
dataDir
profile
.
DSN
=
fmt
.
Sprintf
(
"%s/memos_%s.db"
,
dataDir
,
profile
.
Mode
)
profile
.
DSN
=
fmt
.
Sprintf
(
"%s/memos_%s.db"
,
dataDir
,
profile
.
Mode
)
profile
.
Version
=
common
.
GetCurrentVersion
(
profile
.
Mode
)
profile
.
Version
=
common
.
GetCurrentVersion
(
profile
.
Mode
)
return
&
profile
return
&
profile
,
nil
}
}
server/tag.go
View file @
7d040701
...
@@ -47,7 +47,7 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
...
@@ -47,7 +47,7 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
tagMapSet
:=
make
(
map
[
string
]
bool
)
tagMapSet
:=
make
(
map
[
string
]
bool
)
r
,
err
:=
regexp
.
Compile
(
"#(.+?) "
)
r
:=
regexp
.
Must
Compile
(
"#(.+?) "
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to compile regexp"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to compile regexp"
)
.
SetInternal
(
err
)
}
}
...
...
store/db/db.go
View file @
7d040701
...
@@ -14,8 +14,6 @@ import (
...
@@ -14,8 +14,6 @@ import (
"github.com/usememos/memos/common"
"github.com/usememos/memos/common"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/server/profile"
_
"github.com/mattn/go-sqlite3"
)
)
//go:embed migration
//go:embed migration
...
@@ -175,11 +173,7 @@ func (db *DB) applyMigrationForMinorVersion(ctx context.Context, minorVersion st
...
@@ -175,11 +173,7 @@ func (db *DB) applyMigrationForMinorVersion(ctx context.Context, minorVersion st
return
err
return
err
}
}
if
err
:=
tx
.
Commit
();
err
!=
nil
{
return
tx
.
Commit
()
return
err
}
return
nil
}
}
func
(
db
*
DB
)
seed
(
ctx
context
.
Context
)
error
{
func
(
db
*
DB
)
seed
(
ctx
context
.
Context
)
error
{
...
@@ -204,7 +198,7 @@ func (db *DB) seed(ctx context.Context) error {
...
@@ -204,7 +198,7 @@ func (db *DB) seed(ctx context.Context) error {
return
nil
return
nil
}
}
// ex
c
ecute runs a single SQL statement within a transaction.
// execute runs a single SQL statement within a transaction.
func
(
db
*
DB
)
execute
(
ctx
context
.
Context
,
stmt
string
)
error
{
func
(
db
*
DB
)
execute
(
ctx
context
.
Context
,
stmt
string
)
error
{
tx
,
err
:=
db
.
Db
.
Begin
()
tx
,
err
:=
db
.
Db
.
Begin
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -216,11 +210,7 @@ func (db *DB) execute(ctx context.Context, stmt string) error {
...
@@ -216,11 +210,7 @@ func (db *DB) execute(ctx context.Context, stmt string) error {
return
err
return
err
}
}
if
err
:=
tx
.
Commit
();
err
!=
nil
{
return
tx
.
Commit
()
return
err
}
return
nil
}
}
// minorDirRegexp is a regular expression for minor version directory.
// minorDirRegexp is a regular expression for minor version directory.
...
@@ -264,9 +254,5 @@ func (db *DB) createMigrationHistoryTable(ctx context.Context) error {
...
@@ -264,9 +254,5 @@ func (db *DB) createMigrationHistoryTable(ctx context.Context) error {
return
err
return
err
}
}
if
err
:=
tx
.
Commit
();
err
!=
nil
{
return
tx
.
Commit
()
return
err
}
return
nil
}
}
store/db/migration_history.go
View file @
7d040701
...
@@ -33,9 +33,10 @@ func (db *DB) FindMigrationHistory(ctx context.Context, find *MigrationHistoryFi
...
@@ -33,9 +33,10 @@ func (db *DB) FindMigrationHistory(ctx context.Context, find *MigrationHistoryFi
if
len
(
list
)
==
0
{
if
len
(
list
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
else
{
return
list
[
0
],
nil
}
}
migrationHistory
:=
list
[
0
]
return
migrationHistory
,
nil
}
}
func
(
db
*
DB
)
UpsertMigrationHistory
(
ctx
context
.
Context
,
upsert
*
MigrationHistoryUpsert
)
(
*
MigrationHistory
,
error
)
{
func
(
db
*
DB
)
UpsertMigrationHistory
(
ctx
context
.
Context
,
upsert
*
MigrationHistoryUpsert
)
(
*
MigrationHistory
,
error
)
{
...
@@ -92,6 +93,10 @@ func findMigrationHistoryList(ctx context.Context, tx *sql.Tx, find *MigrationHi
...
@@ -92,6 +93,10 @@ func findMigrationHistoryList(ctx context.Context, tx *sql.Tx, find *MigrationHi
migrationHistoryList
=
append
(
migrationHistoryList
,
&
migrationHistory
)
migrationHistoryList
=
append
(
migrationHistoryList
,
&
migrationHistory
)
}
}
if
err
:=
rows
.
Err
();
err
!=
nil
{
return
nil
,
err
}
return
migrationHistoryList
,
nil
return
migrationHistoryList
,
nil
}
}
...
@@ -121,5 +126,9 @@ func upsertMigrationHistory(ctx context.Context, tx *sql.Tx, upsert *MigrationHi
...
@@ -121,5 +126,9 @@ func upsertMigrationHistory(ctx context.Context, tx *sql.Tx, upsert *MigrationHi
return
nil
,
err
return
nil
,
err
}
}
if
err
:=
row
.
Err
();
err
!=
nil
{
return
nil
,
err
}
return
&
migrationHistory
,
nil
return
&
migrationHistory
,
nil
}
}
store/memo_organizer.go
View file @
7d040701
...
@@ -95,6 +95,10 @@ func findMemoOrganizer(ctx context.Context, tx *sql.Tx, find *api.MemoOrganizerF
...
@@ -95,6 +95,10 @@ func findMemoOrganizer(ctx context.Context, tx *sql.Tx, find *api.MemoOrganizerF
return
nil
,
FormatError
(
err
)
return
nil
,
FormatError
(
err
)
}
}
if
err
:=
row
.
Err
();
err
!=
nil
{
return
nil
,
err
}
return
&
memoOrganizerRaw
,
nil
return
&
memoOrganizerRaw
,
nil
}
}
...
...
store/store.go
View file @
7d040701
...
@@ -7,14 +7,14 @@ import (
...
@@ -7,14 +7,14 @@ import (
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/server/profile"
)
)
// Store provides database access to all raw objects
// Store provides database access to all raw objects
.
type
Store
struct
{
type
Store
struct
{
db
*
sql
.
DB
db
*
sql
.
DB
profile
*
profile
.
Profile
profile
*
profile
.
Profile
cache
api
.
CacheService
cache
api
.
CacheService
}
}
// New creates a new instance of Store
// New creates a new instance of Store
.
func
New
(
db
*
sql
.
DB
,
profile
*
profile
.
Profile
)
*
Store
{
func
New
(
db
*
sql
.
DB
,
profile
*
profile
.
Profile
)
*
Store
{
cacheService
:=
NewCacheService
()
cacheService
:=
NewCacheService
()
...
...
store/user.go
View file @
7d040701
...
@@ -258,6 +258,10 @@ func patchUser(ctx context.Context, tx *sql.Tx, patch *api.UserPatch) (*userRaw,
...
@@ -258,6 +258,10 @@ func patchUser(ctx context.Context, tx *sql.Tx, patch *api.UserPatch) (*userRaw,
return
nil
,
FormatError
(
err
)
return
nil
,
FormatError
(
err
)
}
}
if
err
:=
row
.
Err
();
err
!=
nil
{
return
nil
,
err
}
return
&
userRaw
,
nil
return
&
userRaw
,
nil
}
}
...
...
store/user_setting.go
View file @
7d040701
...
@@ -111,7 +111,7 @@ func findUserSettingList(ctx context.Context, tx *sql.Tx, find *api.UserSettingF
...
@@ -111,7 +111,7 @@ func findUserSettingList(ctx context.Context, tx *sql.Tx, find *api.UserSettingF
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
if
v
:=
find
.
Key
;
v
!=
nil
{
if
v
:=
find
.
Key
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"key = ?"
),
append
(
args
,
(
*
v
)
.
String
())
where
,
args
=
append
(
where
,
"key = ?"
),
append
(
args
,
v
.
String
())
}
}
where
,
args
=
append
(
where
,
"user_id = ?"
),
append
(
args
,
find
.
UserID
)
where
,
args
=
append
(
where
,
"user_id = ?"
),
append
(
args
,
find
.
UserID
)
...
...
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