From 05b5b67f932c74e78612da84bf04ddf0ac218dc9 Mon Sep 17 00:00:00 2001 From: BaoXuebin Date: Mon, 6 Dec 2021 22:07:19 +0800 Subject: [PATCH] update readme --- README.md | 40 ++++++++++++++++++++++++++++++++++++++-- config/white_list.json | 1 - script/config.go | 27 +++++++++++++++++++-------- 3 files changed, 57 insertions(+), 11 deletions(-) delete mode 100644 config/white_list.json diff --git a/README.md b/README.md index 2f47125..5fda8f5 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,47 @@ ## 如何使用 +**本地打包** + +1. 克隆本项目到本地 +2. 根目录执行 `go build` +3. 执行 `./beancount-gs` (`-p` 指定端口号,`-secret` 指定配置密钥) + +**release** + +1. 下载并解压项目的 `release` 包 +2. 执行根目录下的 `./beancount-gs.exe` + +**docker** + ```shell -go build +docker run --name benacount-gs -dp 10000:80 \ +-w /app \ +-v "/data/beancount:/data/beancount" \ +-v "/data/beancount/icons:/app/public/icons" \ +-v "/data/beancount/config:/app/config" \ +xdbin/beancount-gs:latest \ +sh -c "cp -rn /app/public/default_icons/* /app/public/icons && ./beancount-gs -p 80" ``` -将打包获得的文件与项目的 `config/`, `public/`, `example/` 三个文件夹放置同一目录,然后执行 +**docker-compose** + +```yaml +version: "3.9" +services: + app: + container_name: beancount-gs + image: xdbin/beancount-gs:latest + ports: + - "10000:80" + # volumes 挂载目录会导 /app/public/icons 中的图标被覆盖,这里将默认图标在挂载后重新拷贝图标 + command: > + sh -c "cp -rn /app/public/default_icons/* /app/public/icons && ./beancount-gs -p 80" + volumes: + - "${dataPath:-/data/beancount}:${dataPath:-/data/beancount}" + - "${dataPath:-/data/beancount}/icons:/app/public/icons" + - "${dataPath:-/data/beancount}/config:/app/config" +``` ## 项目负责人 diff --git a/config/white_list.json b/config/white_list.json deleted file mode 100644 index 0637a08..0000000 --- a/config/white_list.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/script/config.go b/script/config.go index 97c27d5..fd4895a 100644 --- a/script/config.go +++ b/script/config.go @@ -71,14 +71,25 @@ func LoadServerConfig() error { LogSystemInfo("Success load config file (" + filePath + ")") // load white list whiteListFilePath := GetServerWhiteListFilePath() - fileContent, err = ReadFile(whiteListFilePath) - if err != nil { - return err - } - err = json.Unmarshal(fileContent, &whiteList) - if err != nil { - LogSystemError("Failed unmarshal whitelist file (" + whiteListFilePath + ")") - return err + if FileIfExist(whiteListFilePath) { + fileContent, err = ReadFile(whiteListFilePath) + if err != nil { + return err + } + err = json.Unmarshal(fileContent, &whiteList) + if err != nil { + LogSystemError("Failed unmarshal whitelist file (" + whiteListFilePath + ")") + return err + } + } else { + file, _ := os.OpenFile(whiteListFilePath, os.O_CREATE, 0644) + _, err = file.WriteString("[]") + if err != nil { + LogSystemError("Failed to create whitelist file (" + whiteListFilePath + ")") + return err + } + whiteList = make([]string, 0) + defer file.Close() } LogSystemInfo("Success load whitelist file (" + whiteListFilePath + ")") return nil