From 5af7432d79c5c9670d5632ee65ba0dc984359a45 Mon Sep 17 00:00:00 2001 From: JustSong Date: Fri, 29 Jul 2022 23:05:29 +0800 Subject: [PATCH] :tada: now you can use --version to print version string --- README.md | 4 ++++ common/constants.go | 22 +++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ce37c10..45d2fe3 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,10 @@ Please visit https://go-file.herokuapp.com/ to have a try yourself. 3. 选择`在此处打开 PowerShell`(如果是 Windows 11 的话则需要先点击`显示更多选项`), 4. 在打开的终端中输入:`./go-file --port 80 --video ./path/to/video` +**使用 Docker 部署:** +1. 拉取镜像:`docker pull justsong/go-file:latest` +2. 运行:`docker -p 3000:3000 run justsong/go-file:latest` + **注意:** 1. 如果主机有多个 ip 地址,请使用 host 参数指定一个其他设备可访问的 ip 地址,如:`go-file.exe --host xxx.xxx.xxx.xxx`,否则二维码将生成错误。 2. 默认配置下访客可以上传和下载文件,可在 `管理` -> `系统设置` 中修改权限配置。 diff --git a/common/constants.go b/common/constants.go index b376cc7..a62a32e 100644 --- a/common/constants.go +++ b/common/constants.go @@ -3,6 +3,7 @@ package common import ( "embed" "flag" + "fmt" "github.com/google/uuid" "os" "path" @@ -11,7 +12,7 @@ import ( ) var StartTime = time.Now() -var Version = "v0.4.2" +var Version = "v0.4.3" var OptionMap map[string]string var ItemsPerPage = 10 @@ -51,11 +52,12 @@ const ( ) var ( - Port = flag.Int("port", 3000, "specify the server listening port.") - Host = flag.String("host", "localhost", "the server's ip address or domain") - Path = flag.String("path", "", "specify a local path to public") - VideoPath = flag.String("video", "", "specify a video folder to public") - NoBrowser = flag.Bool("no-browser", false, "open browser or not") + Port = flag.Int("port", 3000, "specify the server listening port.") + Host = flag.String("host", "localhost", "the server's ip address or domain") + Path = flag.String("path", "", "specify a local path to public") + VideoPath = flag.String("video", "", "specify a video folder to public") + NoBrowser = flag.Bool("no-browser", false, "open browser or not") + PrintVersion = flag.Bool("version", false, "print version") ) // UploadPath Maybe override by ENV_VAR @@ -72,6 +74,13 @@ var SessionSecret = uuid.New().String() var SQLitePath = ".go-file.db" func init() { + flag.Parse() + + if *PrintVersion { + fmt.Println(Version) + os.Exit(0) + } + if os.Getenv("SESSION_SECRET") != "" { SessionSecret = os.Getenv("SESSION_SECRET") } @@ -84,7 +93,6 @@ func init() { ImageUploadPath = path.Join(UploadPath, "images") VideoServePath = UploadPath } - flag.Parse() if *Path != "" { ExplorerRootPath = *Path }