package main import ( "net/http" ) func main() { http.HandleFunc("/redirect", func(writer http.ResponseWriter, request *http.Request) { url := "http://www.manong.life/" // 要跳转到的URL,可使用相对路径,如:/login.html // 跳转到指定页面 // 重要提醒:若http.Redirect()后面还有代码,这些代码依然会执行,故如有必要可配合return使用。 http.Redirect(writer, request, url, http.StatusFound) // const StatusFound int = 302 }) _ = http.ListenAndServe(":8081", nil) }
Copyright © 2024 码农人生. All Rights Reserved