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
7c94db0c
Commit
7c94db0c
authored
Jul 09, 2022
by
boojack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: use flags instead of env vars
parent
1d8603df
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
20 deletions
+35
-20
.gitignore
.gitignore
+1
-0
root.go
bin/server/cmd/root.go
+7
-0
build.sh
scripts/build.sh
+10
-0
profile.go
server/profile/profile.go
+17
-20
No files found.
.gitignore
View file @
7c94db0c
...
...
@@ -24,5 +24,6 @@ data
# build folder
build
memos-build
.DS_Store
\ No newline at end of file
bin/server/cmd/root.go
View file @
7c94db0c
...
...
@@ -49,6 +49,13 @@ func Execute() {
profile
:
profile
,
}
println
(
"---"
)
println
(
"profile"
)
println
(
"mode:"
,
profile
.
Mode
)
println
(
"port:"
,
profile
.
Port
)
println
(
"dsn:"
,
profile
.
DSN
)
println
(
"version:"
,
profile
.
Version
)
println
(
"---"
)
println
(
greetingBanner
)
fmt
.
Printf
(
"Version %s has started at :%d
\n
"
,
profile
.
Version
,
profile
.
Port
)
...
...
scripts/build.sh
0 → 100644
View file @
7c94db0c
# Usage: sh ./scripts/build.sh
set
-e
cd
"
$(
dirname
"
$0
"
)
/../"
echo
"Start building..."
go build
-o
./memos-build/memos ./bin/server/main.go
echo
"Build finished"
server/profile/profile.go
View file @
7c94db0c
package
profile
import
(
"flag"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/usememos/memos/common"
...
...
@@ -16,6 +16,8 @@ type Profile struct {
Mode
string
`json:"mode"`
// Port is the binding port for server
Port
int
`json:"port"`
// Data is the data directory
Data
string
`json:"data"`
// DSN points to where Memos stores its own data
DSN
string
`json:"dsn"`
// Version is the current version of server
...
...
@@ -43,35 +45,30 @@ func checkDSN(dataDir string) (string, error) {
return
dataDir
,
nil
}
// GetDevProfile will return a profile for dev.
// GetDevProfile will return a profile for dev
or prod
.
func
GetProfile
()
*
Profile
{
mode
:=
os
.
Getenv
(
"mode"
)
if
mode
!=
"dev"
&&
mode
!=
"prod"
{
mode
=
"dev"
}
profile
:=
Profile
{}
flag
.
StringVar
(
&
profile
.
Mode
,
"mode"
,
"dev"
,
"mode of server"
)
flag
.
IntVar
(
&
profile
.
Port
,
"port"
,
8080
,
"port of server"
)
flag
.
StringVar
(
&
profile
.
Data
,
"data"
,
""
,
"data directory"
)
flag
.
Parse
()
port
,
err
:=
strconv
.
Atoi
(
os
.
Getenv
(
"port"
))
if
err
!=
nil
{
port
=
8080
if
profile
.
Mode
!=
"dev"
&&
profile
.
Mode
!=
"prod"
{
profile
.
Mode
=
"dev"
}
data
:=
""
if
mode
==
"prod"
{
data
=
"/var/opt/memos"
if
profile
.
Mode
==
"prod"
&&
profile
.
Data
==
""
{
profile
.
Data
=
"/var/opt/memos"
}
dataDir
,
err
:=
checkDSN
(
d
ata
)
dataDir
,
err
:=
checkDSN
(
profile
.
D
ata
)
if
err
!=
nil
{
fmt
.
Printf
(
"Failed to check dsn: %s, err: %+v
\n
"
,
dataDir
,
err
)
os
.
Exit
(
1
)
}
dsn
:=
fmt
.
Sprintf
(
"%s/memos_%s.db"
,
dataDir
,
mode
)
profile
.
DSN
=
fmt
.
Sprintf
(
"%s/memos_%s.db"
,
dataDir
,
profile
.
Mode
)
profile
.
Version
=
common
.
GetCurrentVersion
(
profile
.
Mode
)
return
&
Profile
{
Mode
:
mode
,
Port
:
port
,
DSN
:
dsn
,
Version
:
common
.
GetCurrentVersion
(
mode
),
}
return
&
profile
}
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