From 7101d23abe2dfde7d29a9e0ed5845d25084a00e0 Mon Sep 17 00:00:00 2001
From: yesAnd <850208971@qq.com>
Date: Thu, 11 Jul 2024 15:14:02 +0800
Subject: [PATCH] readme.md add filesserver
---
README.md | 20 +++++++++++++++++-
cmd/git.go | 2 +-
handler/fileserver/file_server.go | 4 ++--
handler/fileserver/file_server_test.go | 4 +++-
.../testdata => testdata}/github.png | Bin
5 files changed, 25 insertions(+), 5 deletions(-)
rename {handler/fileserver/testdata => testdata}/github.png (100%)
diff --git a/README.md b/README.md
index aae3db8..e267414 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,7 @@ lwe是leave work early的缩写,也就是"早点下班"!🤣🤣🤣
- 获取Navicat连接配置中的密码
- 同步两个目录下文件
- 显示本机配置的环境变量
+- 静态资源代理
- 格式化请求url
@@ -146,8 +147,25 @@ lwe fsync sourceDir targetDir [-d=true]
详细使用说明,可以查阅[Wiki](https://github.com/yesAnd92/lwe/wiki/%E5%85%B6%E5%AE%83%E5%B0%8F%E5%B7%A5%E5%85%B7#%E5%90%8C%E6%AD%A5%E4%B8%A4%E4%B8%AA%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%96%87%E4%BB%B6)
+
静态资源代理
+可以为静态资源提供代理,方便本地访问测试
+
+使用方式:
+```text
+lwe fileserver your-file-dir [-p=8080]
+```
+如将 `/lwe/handler/fileserver/testdata/` 进行代理,可以通过`http://127.0.0.1:9527/` 进行访问该目录下资源,并提供简单的访问统计
+
+```
+/lwe/handler/fileserver/testdata/ ==> http://127.0.0.1:9527/
+/github.png - 1 visit
+```
+
+详细使用说明,可以查阅[Wiki](https://github.com/yesAnd92/lwe/wiki/%E5%85%B6%E5%AE%83%E5%B0%8F%E5%B7%A5%E5%85%B7#%E5%90%8C%E6%AD%A5%E4%B8%A4%E4%B8%AA%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%96%87%E4%BB%B6)
+
+
显示环境变量
-显示本机配置的环境变量,目前仅测试了mac平台
+显示本机配置的环境变量,目前仅支持mac平台
使用方式:
diff --git a/cmd/git.go b/cmd/git.go
index 90fd8e1..6f62221 100644
--- a/cmd/git.go
+++ b/cmd/git.go
@@ -24,7 +24,7 @@ var (
Use: `glog`,
Short: `Get all git repository commit log under the given dir `,
Long: `Get all git repository commit log under the given dir ,and specify author,date etc. supported!`,
- Example: `lwe glog [git repo dir] [-a=yesAnd] [-n=50] [-s=2023-08-04] [-e=2023-08-04] [-ab=ture]`,
+ Example: `lwe glog [git repo dir] [-a=yesAnd] [-n=50] [-s=2023-08-04] [-e=2023-08-04] [-b=ture]`,
Args: cobra.MatchAll(),
Run: func(cmd *cobra.Command, args []string) {
diff --git a/handler/fileserver/file_server.go b/handler/fileserver/file_server.go
index cf881ad..d1da7aa 100644
--- a/handler/fileserver/file_server.go
+++ b/handler/fileserver/file_server.go
@@ -17,7 +17,7 @@ var (
lock sync.Mutex
)
-// 文件访问次数增加的函数
+// add visit count
func addAccessCount(filePath string) int {
lock.Lock()
defer lock.Unlock()
@@ -46,7 +46,7 @@ func ServerStart(port, rootDir string) {
//file access statistic
count := addAccessCount(filePath)
- fmt.Printf("%s - %d times\n", filePath, count)
+ fmt.Printf("%s - %d visit\n", filePath, count)
http.ServeFile(w, r, rootDir+filePath)
diff --git a/handler/fileserver/file_server_test.go b/handler/fileserver/file_server_test.go
index 04bd4df..e03e97a 100644
--- a/handler/fileserver/file_server_test.go
+++ b/handler/fileserver/file_server_test.go
@@ -4,7 +4,9 @@ import "testing"
func TestServerStart(t *testing.T) {
- rootDir := "./testdata"
+ //go test skip this case
+ t.Skip()
+ rootDir := "../../testdata"
ServerStart("", rootDir)
}
diff --git a/handler/fileserver/testdata/github.png b/testdata/github.png
similarity index 100%
rename from handler/fileserver/testdata/github.png
rename to testdata/github.png