Skip to content

Commit

Permalink
新增重定向设置
Browse files Browse the repository at this point in the history
  • Loading branch information
baiqll committed Aug 20, 2024
1 parent 137cb6d commit 65992b1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 65992b1

Please sign in to comment.