本文整理匯總了Golang中github.com/julienschmidt/httprouter.Router.RedirectFixedPath方法的典型用法代碼示例。如果您正苦於以下問題:Golang Router.RedirectFixedPath方法的具體用法?Golang Router.RedirectFixedPath怎麽用?Golang Router.RedirectFixedPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/julienschmidt/httprouter.Router
的用法示例。
在下文中一共展示了Router.RedirectFixedPath方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetupHTTP
// setupHTTP attaches all the needed handlers to provide the HTTP API.
func (m *Manta) SetupHTTP(mux *httprouter.Router) {
baseRoute := "/" + m.ServiceInstance.UserAccount
mux.NotFound = ErrNotFound
mux.MethodNotAllowed = ErrNotAllowed
mux.RedirectFixedPath = true
mux.RedirectTrailingSlash = true
mux.HandleMethodNotAllowed = true
// this particular route can't be handled by httprouter correctly due to its
// handling of positional parameters but we can't just pass in ErrNotAllowed
// either because it's the wrong type
handleNotAllowed := func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
w.WriteHeader(http.StatusMethodNotAllowed)
w.Header().Set("Content-Type", "text/plain; charset=UTF-8")
w.Write([]byte("Method is not allowed"))
}
mux.POST(baseRoute+"/stor", handleNotAllowed)
// storage APIs
// PutSnapLink and PutMetaData have the same route spec as other routes
// in this group, which isn't permitted by httprouter. We pick up the
// correct path in the handler
mux.PUT(baseRoute+"/stor/:dir", m.handler((*Manta).handleStorage)) // PutDirectory
mux.GET(baseRoute+"/stor/:dir", m.handler((*Manta).handleStorage)) // ListDirectory
mux.DELETE(baseRoute+"/stor/:dir", m.handler((*Manta).handleStorage)) // DeleteDirectory
mux.PUT(baseRoute+"/stor/:dir/:obj", m.handler((*Manta).handleStorage)) // PutObject
mux.GET(baseRoute+"/stor/:dir/:obj", m.handler((*Manta).handleStorage)) // GetObject
mux.DELETE(baseRoute+"/stor/:dir/:obj", m.handler((*Manta).handleStorage)) // DeleteObject
// job APIs
mux.POST(baseRoute+"/jobs", m.handler((*Manta).handleJobs)) // CreateJob
mux.POST(baseRoute+"/jobs/:id/live/in", m.handler((*Manta).handleJobs)) // AddJobInputs
mux.POST(baseRoute+"/jobs/:id/live/in/end", m.handler((*Manta).handleJobs)) // EndJobInput
mux.POST(baseRoute+"/jobs/:id/live/cancel", m.handler((*Manta).handleJobs)) // CancelJob
mux.GET(baseRoute+"/jobs", m.handler((*Manta).handleJobs)) // ListJobs
mux.GET(baseRoute+"/jobs/:id/live/status", m.handler((*Manta).handleJobs)) // GetJob
mux.GET(baseRoute+"/jobs/:id/live/out", m.handler((*Manta).handleJobs)) // GetJobOutput
mux.GET(baseRoute+"/jobs/:id/live/in", m.handler((*Manta).handleJobs)) // GetJobInput
mux.GET(baseRoute+"/jobs/:id/live/fail", m.handler((*Manta).handleJobs)) // GetJobFailures
mux.GET(baseRoute+"/jobs/:id/live/err", m.handler((*Manta).handleJobs)) // GetJobErrors
}