Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: use flags instead of env vars

boojack7c94db0ca066
diff --git a/.gitignore b/.gitignore
index 78660904e..bdf7a6038 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,5 +24,6 @@ data
# build folder
build
+memos-build
.DS_Store
\ No newline at end of file
diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.go
index ec52fffb7..7a3e0bb33 100644
--- a/bin/server/cmd/root.go
+++ b/bin/server/cmd/root.go
@@ -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)
diff --git a/scripts/build.sh b/scripts/build.sh
new file mode 100644
index 000000000..c506f0875
--- /dev/null
+++ b/scripts/build.sh
@@ -0,0 +1,10 @@
+# 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"
diff --git a/server/profile/profile.go b/server/profile/profile.go
index 41038a018..cf370b124 100644
--- a/server/profile/profile.go
+++ b/server/profile/profile.go
@@ -1,10 +1,10 @@
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(data)
+ dataDir, err := checkDSN(profile.Data)
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
}