From 65992b12b714bab1e801acc0e13c2c2f3f1b019d Mon Sep 17 00:00:00 2001 From: baiqll Date: Tue, 20 Aug 2024 11:09:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=87=8D=E5=AE=9A=E5=90=91?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 3514f02..b4be8b0 100644 --- a/main.go +++ b/main.go @@ -121,7 +121,16 @@ func http_server(server string, tls_crt string, tls_key string, payload string, } fmt.Print("\n") - if(strings.HasPrefix(r.URL.String(), "/default")){ + if (strings.HasPrefix(r.URL.String(), "/redirect")){ + // 设置重定向 + + location := r.URL.Query().Get("url") + + http.Redirect(w, r, location, http.StatusFound) + + }else if(strings.HasPrefix(r.URL.String(), "/default")){ + // 设置默认信息 + data, err := ioutil.ReadFile(default_file) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -131,14 +140,17 @@ func http_server(server string, tls_crt string, tls_key string, payload string, http_write(w,data) }else if(strings.HasPrefix(r.URL.String(), "/Payload")){ + // 自定义返回内容 http_write(w,[]byte(payload)) }else if(strings.HasPrefix(r.URL.String(), "/message")){ + // 返回全内容(接收消息) http_write(w,[]byte(`{"message": "OK"}`)) }else{ + // 文件系统 http.FileServer(http.Dir("./")).ServeHTTP(w, r)