Skip to content

Commit

Permalink
readme.md add filesserver
Browse files Browse the repository at this point in the history
  • Loading branch information
yesAnd92 committed Jul 11, 2024
1 parent 690cde7 commit 7101d23
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ lwe是leave work early的缩写,也就是"早点下班"!🤣🤣🤣
- 获取Navicat连接配置中的密码
- 同步两个目录下文件
- 显示本机配置的环境变量
- 静态资源代理
- 格式化请求url


Expand Down Expand Up @@ -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)


<h4>静态资源代理</h4>
可以为静态资源提供代理,方便本地访问测试

使用方式:
```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)


<h4>显示环境变量</h4>
显示本机配置的环境变量,目前仅测试了mac平台
显示本机配置的环境变量,目前仅支持mac平台

使用方式:

Expand Down
2 changes: 1 addition & 1 deletion cmd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
4 changes: 2 additions & 2 deletions handler/fileserver/file_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
lock sync.Mutex
)

// 文件访问次数增加的函数
// add visit count
func addAccessCount(filePath string) int {
lock.Lock()
defer lock.Unlock()
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion handler/fileserver/file_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import "testing"

func TestServerStart(t *testing.T) {

rootDir := "./testdata"
//go test skip this case
t.Skip()
rootDir := "../../testdata"
ServerStart("", rootDir)

}
File renamed without changes

0 comments on commit 7101d23

Please sign in to comment.