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
7564c40c
Commit
7564c40c
authored
Jul 27, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: fix env init
parent
8fd5365a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
44 deletions
+32
-44
main.go
bin/memos/main.go
+30
-37
.air.toml
scripts/.air.toml
+1
-1
memo_service.go
server/router/api/v1/memo_service.go
+1
-6
No files found.
bin/memos/main.go
View file @
7564c40c
...
@@ -31,12 +31,25 @@ const (
...
@@ -31,12 +31,25 @@ const (
)
)
var
(
var
(
instanceProfile
*
profile
.
Profile
rootCmd
=
&
cobra
.
Command
{
rootCmd
=
&
cobra
.
Command
{
Use
:
"memos"
,
Use
:
"memos"
,
Short
:
`An open source, lightweight note-taking service. Easily capture and share your great thoughts.`
,
Short
:
`An open source, lightweight note-taking service. Easily capture and share your great thoughts.`
,
Run
:
func
(
_
*
cobra
.
Command
,
_
[]
string
)
{
Run
:
func
(
_
*
cobra
.
Command
,
_
[]
string
)
{
instanceProfile
:=
&
profile
.
Profile
{
Mode
:
viper
.
GetString
(
"mode"
),
Addr
:
viper
.
GetString
(
"addr"
),
Port
:
viper
.
GetInt
(
"port"
),
Data
:
viper
.
GetString
(
"data"
),
Driver
:
viper
.
GetString
(
"driver"
),
DSN
:
viper
.
GetString
(
"dsn"
),
Public
:
viper
.
GetBool
(
"public"
),
PasswordAuth
:
viper
.
GetBool
(
"password-auth"
),
Version
:
version
.
GetCurrentVersion
(
viper
.
GetString
(
"mode"
)),
}
if
err
:=
instanceProfile
.
Validate
();
err
!=
nil
{
panic
(
err
)
}
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
dbDriver
,
err
:=
db
.
NewDBDriver
(
instanceProfile
)
dbDriver
,
err
:=
db
.
NewDBDriver
(
instanceProfile
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -77,7 +90,7 @@ var (
...
@@ -77,7 +90,7 @@ var (
}
}
}
}
printGreetings
()
printGreetings
(
instanceProfile
)
go
func
()
{
go
func
()
{
<-
c
<-
c
...
@@ -91,11 +104,14 @@ var (
...
@@ -91,11 +104,14 @@ var (
}
}
)
)
func
Execute
()
error
{
return
rootCmd
.
Execute
()
}
func
init
()
{
func
init
()
{
viper
.
SetDefault
(
"mode"
,
"demo"
)
viper
.
SetDefault
(
"driver"
,
"sqlite"
)
viper
.
SetDefault
(
"addr"
,
""
)
viper
.
SetDefault
(
"port"
,
8081
)
viper
.
SetDefault
(
"public"
,
false
)
viper
.
SetDefault
(
"password-auth"
,
true
)
rootCmd
.
PersistentFlags
()
.
String
(
"mode"
,
"demo"
,
`mode of server, can be "prod" or "dev" or "demo"`
)
rootCmd
.
PersistentFlags
()
.
String
(
"mode"
,
"demo"
,
`mode of server, can be "prod" or "dev" or "demo"`
)
rootCmd
.
PersistentFlags
()
.
String
(
"addr"
,
""
,
"address of server"
)
rootCmd
.
PersistentFlags
()
.
String
(
"addr"
,
""
,
"address of server"
)
rootCmd
.
PersistentFlags
()
.
Int
(
"port"
,
8081
,
"port of server"
)
rootCmd
.
PersistentFlags
()
.
Int
(
"port"
,
8081
,
"port of server"
)
...
@@ -143,29 +159,9 @@ func init() {
...
@@ -143,29 +159,9 @@ func init() {
if
err
:=
viper
.
BindEnv
(
"password-auth"
,
"MEMOS_PASSWORD_AUTH"
);
err
!=
nil
{
if
err
:=
viper
.
BindEnv
(
"password-auth"
,
"MEMOS_PASSWORD_AUTH"
);
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
}
viper
.
SetDefault
(
"mode"
,
"demo"
)
func
printGreetings
(
profile
*
profile
.
Profile
)
{
viper
.
SetDefault
(
"driver"
,
"sqlite"
)
viper
.
SetDefault
(
"addr"
,
""
)
viper
.
SetDefault
(
"port"
,
8081
)
viper
.
SetDefault
(
"public"
,
false
)
viper
.
SetDefault
(
"password-auth"
,
true
)
instanceProfile
=
&
profile
.
Profile
{
Mode
:
viper
.
GetString
(
"mode"
),
Addr
:
viper
.
GetString
(
"addr"
),
Port
:
viper
.
GetInt
(
"port"
),
Data
:
viper
.
GetString
(
"data"
),
Driver
:
viper
.
GetString
(
"driver"
),
DSN
:
viper
.
GetString
(
"dsn"
),
Public
:
viper
.
GetBool
(
"public"
),
PasswordAuth
:
viper
.
GetBool
(
"password-auth"
),
Version
:
version
.
GetCurrentVersion
(
viper
.
GetString
(
"mode"
)),
}
if
err
:=
instanceProfile
.
Validate
();
err
!=
nil
{
panic
(
err
)
}
fmt
.
Printf
(
`---
fmt
.
Printf
(
`---
Server profile
Server profile
version: %s
version: %s
...
@@ -178,15 +174,13 @@ public: %t
...
@@ -178,15 +174,13 @@ public: %t
password-auth: %t
password-auth: %t
driver: %s
driver: %s
---
---
`
,
instanceProfile
.
Version
,
instanceProfile
.
Data
,
instanceProfile
.
DSN
,
instanceProfile
.
Addr
,
instanceProfile
.
Port
,
instanceProfile
.
Mode
,
instanceProfile
.
Public
,
instanceProfile
.
PasswordAuth
,
instanceProfile
.
Driver
)
`
,
profile
.
Version
,
profile
.
Data
,
profile
.
DSN
,
profile
.
Addr
,
profile
.
Port
,
profile
.
Mode
,
profile
.
Public
,
profile
.
PasswordAuth
,
profile
.
Driver
)
}
func
printGreetings
()
{
print
(
greetingBanner
)
print
(
greetingBanner
)
if
len
(
instanceP
rofile
.
Addr
)
==
0
{
if
len
(
p
rofile
.
Addr
)
==
0
{
fmt
.
Printf
(
"Version %s has been started on port %d
\n
"
,
instanceProfile
.
Version
,
instanceP
rofile
.
Port
)
fmt
.
Printf
(
"Version %s has been started on port %d
\n
"
,
profile
.
Version
,
p
rofile
.
Port
)
}
else
{
}
else
{
fmt
.
Printf
(
"Version %s has been started on address '%s' and port %d
\n
"
,
instanceProfile
.
Version
,
instanceProfile
.
Addr
,
instanceP
rofile
.
Port
)
fmt
.
Printf
(
"Version %s has been started on address '%s' and port %d
\n
"
,
profile
.
Version
,
profile
.
Addr
,
p
rofile
.
Port
)
}
}
fmt
.
Printf
(
`---
fmt
.
Printf
(
`---
See more in:
See more in:
...
@@ -197,8 +191,7 @@ See more in:
...
@@ -197,8 +191,7 @@ See more in:
}
}
func
main
()
{
func
main
()
{
err
:=
Execute
()
if
err
:=
rootCmd
.
Execute
();
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
}
}
scripts/.air.toml
View file @
7564c40c
...
@@ -2,7 +2,7 @@ root = "."
...
@@ -2,7 +2,7 @@ root = "."
tmp_dir
=
".air"
tmp_dir
=
".air"
[build]
[build]
bin
=
"./.air/memos --mode dev"
bin
=
"./.air/memos --mode dev
--public true
"
cmd
=
"go build -o ./.air/memos ./bin/memos/main.go"
cmd
=
"go build -o ./.air/memos ./bin/memos/main.go"
delay
=
1000
delay
=
1000
exclude_dir
=
[
".air"
,
"web"
,
"build"
]
exclude_dir
=
[
".air"
,
"web"
,
"build"
]
...
...
server/router/api/v1/memo_service.go
View file @
7564c40c
...
@@ -772,11 +772,6 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
...
@@ -772,11 +772,6 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
displayTs
=
memo
.
UpdatedTs
displayTs
=
memo
.
UpdatedTs
}
}
creator
,
err
:=
s
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
ID
:
&
memo
.
CreatorID
})
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"failed to get creator"
)
}
name
:=
fmt
.
Sprintf
(
"%s%d"
,
MemoNamePrefix
,
memo
.
ID
)
name
:=
fmt
.
Sprintf
(
"%s%d"
,
MemoNamePrefix
,
memo
.
ID
)
listMemoRelationsResponse
,
err
:=
s
.
ListMemoRelations
(
ctx
,
&
v1pb
.
ListMemoRelationsRequest
{
Name
:
name
})
listMemoRelationsResponse
,
err
:=
s
.
ListMemoRelations
(
ctx
,
&
v1pb
.
ListMemoRelationsRequest
{
Name
:
name
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -807,7 +802,7 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
...
@@ -807,7 +802,7 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
Name
:
name
,
Name
:
name
,
Uid
:
memo
.
UID
,
Uid
:
memo
.
UID
,
RowStatus
:
convertRowStatusFromStore
(
memo
.
RowStatus
),
RowStatus
:
convertRowStatusFromStore
(
memo
.
RowStatus
),
Creator
:
fmt
.
Sprintf
(
"%s%d"
,
UserNamePrefix
,
creator
.
ID
),
Creator
:
fmt
.
Sprintf
(
"%s%d"
,
UserNamePrefix
,
memo
.
Creator
ID
),
CreateTime
:
timestamppb
.
New
(
time
.
Unix
(
memo
.
CreatedTs
,
0
)),
CreateTime
:
timestamppb
.
New
(
time
.
Unix
(
memo
.
CreatedTs
,
0
)),
UpdateTime
:
timestamppb
.
New
(
time
.
Unix
(
memo
.
UpdatedTs
,
0
)),
UpdateTime
:
timestamppb
.
New
(
time
.
Unix
(
memo
.
UpdatedTs
,
0
)),
DisplayTime
:
timestamppb
.
New
(
time
.
Unix
(
displayTs
,
0
)),
DisplayTime
:
timestamppb
.
New
(
time
.
Unix
(
displayTs
,
0
)),
...
...
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