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
79180928
Unverified
Commit
79180928
authored
Jan 03, 2023
by
boojack
Committed by
GitHub
Jan 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update server activity (#898)
parent
e5550828
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
28 deletions
+50
-28
activity.go
api/activity.go
+2
-1
system_setting.go
api/system_setting.go
+9
-2
main.go
bin/server/main.go
+14
-24
server.go
server/server.go
+25
-1
No files found.
api/activity.go
View file @
79180928
...
...
@@ -103,7 +103,8 @@ type ActivityTagCreatePayload struct {
}
type
ActivityServerStartPayload
struct
{
Profile
*
profile
.
Profile
`json:"profile"`
ServerID
string
`json:"serverId"`
Profile
*
profile
.
Profile
`json:"profile"`
}
type
Activity
struct
{
...
...
api/system_setting.go
View file @
79180928
...
...
@@ -2,6 +2,7 @@ package api
import
(
"encoding/json"
"errors"
"fmt"
"golang.org/x/exp/slices"
...
...
@@ -10,6 +11,8 @@ import (
type
SystemSettingName
string
const
(
// SystemSettingServerID is the key type of server id.
SystemSettingServerID
SystemSettingName
=
"serverId"
// SystemSettingAllowSignUpName is the key type of allow signup setting.
SystemSettingAllowSignUpName
SystemSettingName
=
"allowSignUp"
// SystemSettingAdditionalStyleName is the key type of additional style.
...
...
@@ -38,6 +41,8 @@ type CustomizedProfile struct {
func
(
key
SystemSettingName
)
String
()
string
{
switch
key
{
case
SystemSettingServerID
:
return
"serverId"
case
SystemSettingAllowSignUpName
:
return
"allowSignUp"
case
SystemSettingAdditionalStyleName
:
...
...
@@ -56,7 +61,7 @@ var (
type
SystemSetting
struct
{
Name
SystemSettingName
// Value is a JSON string with basic value
// Value is a JSON string with basic value
.
Value
string
Description
string
}
...
...
@@ -68,7 +73,9 @@ type SystemSettingUpsert struct {
}
func
(
upsert
SystemSettingUpsert
)
Validate
()
error
{
if
upsert
.
Name
==
SystemSettingAllowSignUpName
{
if
upsert
.
Name
==
SystemSettingServerID
{
return
errors
.
New
(
"update server id is not allowed"
)
}
else
if
upsert
.
Name
==
SystemSettingAllowSignUpName
{
value
:=
false
err
:=
json
.
Unmarshal
([]
byte
(
upsert
.
Value
),
&
value
)
if
err
!=
nil
{
...
...
bin/server/main.go
View file @
79180928
...
...
@@ -26,8 +26,19 @@ const (
`
)
func
run
(
profile
*
profile
.
Profile
)
error
{
func
run
()
error
{
ctx
:=
context
.
Background
()
profile
,
err
:=
profile
.
GetProfile
()
if
err
!=
nil
{
return
err
}
println
(
"---"
)
println
(
"profile"
)
println
(
"mode:"
,
profile
.
Mode
)
println
(
"port:"
,
profile
.
Port
)
println
(
"dsn:"
,
profile
.
DSN
)
println
(
"version:"
,
profile
.
Version
)
println
(
"---"
)
db
:=
DB
.
NewDB
(
profile
)
if
err
:=
db
.
Open
(
ctx
);
err
!=
nil
{
...
...
@@ -48,30 +59,9 @@ func run(profile *profile.Profile) error {
return
serverInstance
.
Run
(
ctx
)
}
func
execute
()
error
{
profile
,
err
:=
profile
.
GetProfile
()
if
err
!=
nil
{
return
err
}
println
(
"---"
)
println
(
"profile"
)
println
(
"mode:"
,
profile
.
Mode
)
println
(
"port:"
,
profile
.
Port
)
println
(
"dsn:"
,
profile
.
DSN
)
println
(
"version:"
,
profile
.
Version
)
println
(
"---"
)
if
err
:=
run
(
profile
);
err
!=
nil
{
fmt
.
Printf
(
"error: %+v
\n
"
,
err
)
return
err
}
return
nil
}
func
main
()
{
if
err
:=
execute
();
err
!=
nil
{
if
err
:=
run
();
err
!=
nil
{
fmt
.
Printf
(
"error: %+v
\n
"
,
err
)
os
.
Exit
(
1
)
}
}
server/server.go
View file @
79180928
...
...
@@ -6,8 +6,10 @@ import (
"fmt"
"time"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/usememos/memos/api"
"github.com/usememos/memos/common"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/store"
...
...
@@ -21,6 +23,8 @@ import (
type
Server
struct
{
e
*
echo
.
Echo
ID
string
Collector
*
MetricCollector
Profile
*
profile
.
Profile
...
...
@@ -99,15 +103,35 @@ func NewServer(profile *profile.Profile) *Server {
}
func
(
s
*
Server
)
Run
(
ctx
context
.
Context
)
error
{
serverIDKey
:=
api
.
SystemSettingServerID
serverIDValue
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
Name
:
&
serverIDKey
,
})
if
err
!=
nil
&&
common
.
ErrorCode
(
err
)
!=
common
.
NotFound
{
return
err
}
if
serverIDValue
==
nil
||
serverIDValue
.
Value
==
""
{
serverIDValue
,
err
=
s
.
Store
.
UpsertSystemSetting
(
ctx
,
&
api
.
SystemSettingUpsert
{
Name
:
serverIDKey
,
Value
:
uuid
.
NewString
(),
})
if
err
!=
nil
{
return
err
}
}
s
.
ID
=
serverIDValue
.
Value
if
err
:=
s
.
createServerStartActivity
(
ctx
);
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to create activity"
)
}
return
s
.
e
.
Start
(
fmt
.
Sprintf
(
":%d"
,
s
.
Profile
.
Port
))
}
func
(
s
*
Server
)
createServerStartActivity
(
ctx
context
.
Context
)
error
{
payload
:=
api
.
ActivityServerStartPayload
{
Profile
:
s
.
Profile
,
ServerID
:
s
.
ID
,
Profile
:
s
.
Profile
,
}
payloadStr
,
err
:=
json
.
Marshal
(
payload
)
if
err
!=
nil
{
...
...
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