GO語言"net/http"包中"StripPrefix"函數的用法及代碼示例。
用法:
func StripPrefix(prefix string, h Handler) Handler
StripPrefix 返回一個處理 HTTP 請求的處理程序,方法是從請求 URL 的路徑(和 RawPath,如果設置)中刪除給定的前綴並調用處理程序 h。 StripPrefix 通過回複 HTTP 404 not found 錯誤來處理對不以前綴開頭的路徑的請求。前綴必須完全匹配:如果請求中的前綴包含轉義字符,則回複也是 HTTP 404 not found 錯誤。
例子:
package main
import (
"net/http"
)
func main() {
// To serve a directory on disk (/tmp) under an alternate URL
// path (/tmpfiles/), use StripPrefix to modify the request
// URL's path before the FileServer sees it:
http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer(http.Dir("/tmp"))))
}
相關用法
- GO Strings用法及代碼示例
- GO Stringer用法及代碼示例
- GO StreamWriter用法及代碼示例
- GO StructTag.Lookup用法及代碼示例
- GO StructTag用法及代碼示例
- GO StructOf用法及代碼示例
- GO StreamReader用法及代碼示例
- GO Stmt用法及代碼示例
- GO Stmt.QueryRowContext用法及代碼示例
- GO Scanner.Scan用法及代碼示例
- GO Split用法及代碼示例
- GO Server.Shutdown用法及代碼示例
- GO Slice用法及代碼示例
- GO SplitAfter用法及代碼示例
- GO Sum256用法及代碼示例
- GO SectionReader用法及代碼示例
- GO Sin用法及代碼示例
- GO Sprintf用法及代碼示例
- GO SendMail用法及代碼示例
- GO Sprint用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 StripPrefix。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。