Skip to content

Commit e93145d

Browse files
committed
Remove Go install script and refine Dockerfile and server.go
Deleted the standalone Go installation shell script, and made changes to both Dockerfile and server.go to optimize our app build process and provide enhanced server feedback. Our Go applications are now built directly using Docker which reduces the setup complexity. Hence, the install_go.sh script is no longer needed. In Dockerfile, additional networking tools (ping and mtr) are now included in the image for better network diagnostics. In the server.go file, the response now includes detailed failure message for better troubleshooting. Also, commented code has been removed to clean up the codebase.
1 parent 01a9dbd commit e93145d

File tree

3 files changed

+6
-33
lines changed

3 files changed

+6
-33
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# 使用官方的 Ubuntu 基础镜像
22
FROM ubuntu:latest
33

4-
# 安装必要的依赖
4+
# 安装必要的依赖,包括 ping 和 mtr 工具
55
RUN apt-get update && \
6-
apt-get install -y net-tools iproute2 procps
6+
apt-get install -y net-tools iproute2 procps iputils-ping mtr
77

88
# 将编译好的 server 和 client 二进制文件复制到容器中
99
COPY server /app/server
@@ -16,4 +16,4 @@ WORKDIR /app
1616
EXPOSE 7788 7789
1717

1818
# 设置容器启动时执行的命令,其中 mode 默认值为 "client"
19-
CMD [ "/bin/bash", "-c", "if [ \"$mode\" = \"server\" ]; then ./server; else ./client; fi" ]
19+
CMD [ "/bin/bash", "-c", "if [ \"$mode\" = \"server\" ]; then ./server; else ./client; fi" ]

install_go.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

server.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ func web() {
4949
return
5050
}
5151
time.Sleep(3 * time.Second)
52-
if do(req.Client+"/ping", "baidu.com", req.Token).Status {
52+
test := do(req.Client+"/ping", "baidu.com", req.Token)
53+
if test.Status {
5354
fmt.Fprint(w, "Reg success")
5455
fmt.Println("Reg success")
5556
reg(req)
5657
} else {
57-
fmt.Fprint(w, "Reg fail")
58+
fmt.Fprint(w, "Reg fail:\n"+test.Result)
5859
fmt.Println("Reg fail")
5960
}
6061
} else {
@@ -124,19 +125,6 @@ func add(a, b int) int {
124125
return a + b
125126
}
126127

127-
// func pingHandler(w http.ResponseWriter, r *http.Request) {
128-
// if r.Method == "GET" {
129-
// // 显示页面
130-
// tmpl := template.Must(template.ParseFiles("ping.html"))
131-
// tmpl.Execute(w, nil)
132-
// } else if r.Method == "POST" {
133-
// // 处理表单提交
134-
// s := strconv.FormatInt(time.Now().Unix(), 10)
135-
// t := common.Sha(s + ServerToken)
136-
// url := "/site/01H4NX14RM0000000000000000?do=ping&s=" + s + "&t=" + t + "&to=" + r.FormValue("url")
137-
// http.Redirect(w, r, url, http.StatusSeeOther)
138-
// }
139-
// }
140128
func do(url, to, token string) conf.ExRes {
141129
req := conf.ExReq{To: to, Stamp: strconv.FormatInt(time.Now().Unix(), 10)}
142130
req.Token = common.Sha(req.Stamp + token + req.To)

0 commit comments

Comments
 (0)