Skip to content

Commit dbdf6c3

Browse files
committed
feat(app): can print accessible URLs on startup
1 parent 707e7a0 commit dbdf6c3

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ ghfs [options]
282282
otherwise use the first virtual host.
283283
```
284284

285+
## Environment variables
286+
### GHFS_QUIET
287+
To prevent outputting additional information on console, like accessible URLs, etc,
288+
set value to "1".
289+
285290
## Shortcut key for default theme
286291
- ``, ``: move focus between path items
287292
- `Ctrl`/`Opt` + ``: move focus to first path item

README.zh-CN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ ghfs [选项]
280280
如果失败则使用第一个虚拟主机。
281281
```
282282

283+
## 环境变量
284+
### GHFS_QUIET
285+
为避免在控制台输出额外信息,例如可访问的URL等,可将值设为“1”。
286+
283287
## 默认主题的快捷键
284288
- ``, ``:使焦点在路径项之间移动
285289
- `Ctrl`/`Opt` + ``:把焦点移动到第一个路径项

src/app/accessibleUrls.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package app
2+
3+
import (
4+
"../goVirtualHost"
5+
"../util"
6+
"fmt"
7+
)
8+
9+
func printAccessibleURLs(vhSvc *goVirtualHost.Service) {
10+
vhostsUrls := vhSvc.GetAccessibleURLs(false)
11+
file, teardown := util.GetTTYFile()
12+
13+
for vhIndex := range vhostsUrls {
14+
fmt.Fprintln(file, "Host", vhIndex, "may be accessed by URLs:")
15+
for urlIndex := range vhostsUrls[vhIndex] {
16+
fmt.Fprintln(file, " ", vhostsUrls[vhIndex][urlIndex])
17+
}
18+
}
19+
20+
teardown()
21+
}

src/app/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"../serverErrHandler"
77
"../serverLog"
88
"../tpl"
9+
"../util"
910
"../vhostHandler"
1011
"os"
1112
"path/filepath"
@@ -94,6 +95,10 @@ func NewApp(params []*param.Param) *App {
9495
}
9596
}
9697

98+
if !util.GetBoolEnv("GHFS_QUIET") {
99+
go printAccessibleURLs(vhSvc)
100+
}
101+
97102
return &App{
98103
vhostSvc: vhSvc,
99104
vhostHandlers: vhHandlers,

test/main.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export fs=$(realpath fs)
1515
export cert=$(realpath cert)
1616
export src=$(realpath ../src)
1717
export ghfs=$(realpath bin)/ghfs
18+
export GHFS_QUIET=1
1819

1920
GO111MODULE=auto go build -o "$ghfs" "$src/main.go"
2021

0 commit comments

Comments
 (0)