Skip to content

Commit fe8ace3

Browse files
committed
更新配置文件错误和在多个项目中运行
1 parent 2029c3f commit fe8ace3

35 files changed

+2675
-392
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

Gopkg.lock

Lines changed: 22 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

conf.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ___jb_old___=___jb_old___
1717

1818
##监听的目录
1919
[listenDir]
20-
path=/Volumes/E/www/php/aix-system
20+
path=
2121

2222
##显示变动的文件
2323
ShowLog=false

gohot

3.12 MB
Binary file not shown.

linux/.DS_Store

6 KB
Binary file not shown.

main.go

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,21 @@ package main
22

33
import (
44
"fmt"
5-
"github.com/Unknwon/goconfig"
65
"github.com/fsnotify/fsnotify"
76
"github.com/syyongx/php2go"
8-
"hello/services/watch/sh"
97
"log"
8+
"os"
109
"strings"
10+
"wl_GoHot/sh"
1111
)
1212

13-
var countChan = make(chan int, 0)
14-
15-
func fibonacci(c, quit chan int) {
16-
x, y := 0, 1
17-
for {
18-
select {
19-
case c <- x:
20-
x, y = y, x+y
21-
case <-quit:
22-
fmt.Println("quit")
23-
return
24-
}
25-
}
26-
}
2713

2814
//读取监听文件
2915
func readFile() []string {
30-
path := readConf("listenDir")["path"]
16+
path := sh.ReadConf("listenDir")["path"]
3117

3218
if php2go.Empty(path) { //如果配置文件为空 就获取当前目录
33-
path = sh.GetCurrentDirectory()
19+
path,_= os.Getwd()
3420
}
3521

3622
fmt.Printf("\n %c[1;40;44m%s%c[0m\n\n", 0x1B, "监听目录"+path, 0x1B)
@@ -41,7 +27,7 @@ func readFile() []string {
4127

4228
}
4329

44-
less := readConf("ellipsisDir")
30+
less := sh.ReadConf("ellipsisDir")
4531

4632
listenDirs := []string{}
4733

@@ -72,24 +58,15 @@ func readFile() []string {
7258

7359
}
7460

75-
//读取配置文件
76-
func readConf(section string) map[string]string {
77-
cfg, err := goconfig.LoadConfigFile("conf.ini")
78-
if err != nil {
79-
panic("错误")
80-
}
81-
82-
sec, err := cfg.GetSection(section)
83-
84-
return sec
8561

86-
}
8762
func main() {
8863

8964
runPHP()
9065

9166
}
9267

68+
69+
9370
func runPHP() {
9471

9572
watcher, err := fsnotify.NewWatcher()
@@ -98,7 +75,7 @@ func runPHP() {
9875
} else {
9976

10077
fmt.Printf("\n %c[1;40;32m%s%c[0m\n\n", 0x1B, ""+
101-
" WL_HotSwoole \n"+
78+
" Wl_GoHot \n"+
10279
" V 1.0 \n"+
10380
" ====开始运行===== "+
10481
"", 0x1B)
@@ -119,14 +96,14 @@ func runPHP() {
11996
name := event.String()
12097

12198
//是否输出变动的文件
122-
if readConf("listenDir")["ShowLog"] == "true" {
99+
if sh.ReadConf("listenDir")["ShowLog"] == "true" {
123100
fmt.Println(name)
124101
}
125102

126103
var index int = -1
127104
var isHave bool = false
128105

129-
for _, v := range readConf("ellipsisFile") {
106+
for _, v := range sh.ReadConf("ellipsisFile") {
130107
index = strings.Index(name, v)
131108
if index == -1 { //没匹配
132109
isHave = false

reload.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
clear ;
2-
/Volumes/E/www/php/aix-system/bin/laravels reload
2+
/bin/laravels reload

sh/.DS_Store

6 KB
Binary file not shown.

sh/config.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package sh
2+
3+
import (
4+
"fmt"
5+
"github.com/Unknwon/goconfig"
6+
7+
)
8+
9+
var time_total=0
10+
//读取配置文件
11+
func ReadConf(section string) map[string]string {
12+
file:=GetCurrentPath()+"conf.ini"
13+
14+
if time_total<1 {
15+
fmt.Printf("配置文件: %s\n", file)
16+
}
17+
time_total++
18+
19+
cfg, err := goconfig.LoadConfigFile(file)
20+
if err != nil {
21+
panic("读取配置文件错误")
22+
}
23+
24+
sec, err := cfg.GetSection(section)
25+
26+
return sec
27+
28+
}

0 commit comments

Comments
 (0)