Skip to content

Commit 57d3dab

Browse files
committed
更改和 fmt
1 parent f86ff05 commit 57d3dab

2 files changed

Lines changed: 26 additions & 24 deletions

File tree

cmd/frpc/sub/root.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"io/fs"
8+
"io/ioutil"
89
"net"
910
"net/http"
1011
"os"
@@ -107,7 +108,13 @@ func EasyStartGetConf(token string, tunnelId string) {
107108
return
108109
}
109110
if response.StatusCode != http.StatusOK {
110-
err = fmt.Errorf("ME Frp API 错误 可能是您的启动信息错误%d", response.StatusCode)
111+
err = fmt.Errorf("ME Frp API 校验失败 可能是您的启动信息错误%d", response.StatusCode)
112+
bodyBytes, err := ioutil.ReadAll(response.Body)
113+
if err != nil {
114+
fmt.Println(err)
115+
return
116+
}
117+
fmt.Println(string(bodyBytes))
111118
fmt.Println(err)
112119
os.Exit(1)
113120
return
@@ -157,13 +164,14 @@ var rootCmd = &cobra.Command{
157164
// 如果 tunnelId 后面跟了多个数字,那么就是多个隧道
158165
if strings.Contains(tunnelId, ",") {
159166
fmt.Println("检测到多个隧道,正在启动多个隧道")
167+
fmt.Printf(tunnelId)
160168
_ = runMultipleClientsEasyStart(userToken, tunnelId)
161-
}
162-
163-
// 多隧道不行就单隧道
164-
err := runClient(cfgFile, userToken, tunnelId)
165-
if err != nil {
166-
os.Exit(1)
169+
} else {
170+
// 多隧道不行就单隧道
171+
err := runClient(cfgFile, userToken, tunnelId)
172+
if err != nil {
173+
os.Exit(1)
174+
}
167175
}
168176
return nil
169177
},
@@ -197,16 +205,15 @@ func runMultipleClientsEasyStart(userToken string, tunnelId string) error {
197205
tunnelIdList := strings.Split(tunnelId, ",")
198206
for _, tunnelId := range tunnelIdList {
199207
wg.Add(1)
200-
time.Sleep(time.Millisecond)
201-
go func() {
208+
go func(tunnelId string) {
202209
defer wg.Done()
203210
err := runClient("", userToken, tunnelId)
204211
if err != nil {
205212
fmt.Printf("frpc service error for config file [%s]\n", tunnelId)
206213
}
207-
}()
208-
return nil
214+
}(tunnelId)
209215
}
216+
210217
wg.Wait()
211218
return nil
212219
}

pkg/util/vhost/resource.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
package vhost
1616

1717
import (
18-
"bytes"
19-
"io"
2018
"net/http"
2119
"os"
2220

@@ -68,20 +66,17 @@ func getNotFoundPageContent() []byte {
6866
}
6967

7068
func notFoundResponse() *http.Response {
69+
targetUrl := "https://www.mefrp.com/ServiceNotFound"
7170
header := make(http.Header)
72-
header.Set("server", "frp/"+version.Full())
73-
header.Set("Content-Type", "text/html")
71+
header.Set("server", "ME-Frp/"+version.Full())
72+
header.Set("Location", targetUrl)
7473

75-
content := getNotFoundPageContent()
7674
res := &http.Response{
77-
Status: "Not Found",
78-
StatusCode: 404,
79-
Proto: "HTTP/1.1",
80-
ProtoMajor: 1,
81-
ProtoMinor: 1,
82-
Header: header,
83-
Body: io.NopCloser(bytes.NewReader(content)),
84-
ContentLength: int64(len(content)),
75+
Proto: "HTTP/1.1",
76+
Status: "Found",
77+
StatusCode: 302,
78+
Header: header,
8579
}
8680
return res
81+
8782
}

0 commit comments

Comments
 (0)