本文整理匯總了Golang中github.com/valyala/fasthttp.RequestCtx.Redirect方法的典型用法代碼示例。如果您正苦於以下問題:Golang RequestCtx.Redirect方法的具體用法?Golang RequestCtx.Redirect怎麽用?Golang RequestCtx.Redirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/valyala/fasthttp.RequestCtx
的用法示例。
在下文中一共展示了RequestCtx.Redirect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HandleAuthorizeRequest
// HandleAuthorizeRequest 處理授權請求
func (fs *FastServer) HandleAuthorizeRequest(ctx *fasthttp.RequestCtx, authReq *AuthorizeRequest) (err error) {
if authReq.UserID == "" {
err = ErrUserInvalid
return
}
tgr := &oauth2.TokenGenerateRequest{
ClientID: authReq.ClientID,
UserID: authReq.UserID,
RedirectURI: authReq.RedirectURI,
Scope: authReq.Scope,
}
ti, terr := fs.manager.GenerateAuthToken(oauth2.Code, tgr)
if terr != nil {
err = terr
return
}
redirectURI, err := fs.GetRedirectURI(authReq, ti)
if err != nil {
return
}
ctx.Redirect(redirectURI, 302)
return
}
示例2: Handler
// Handler makes the router implement the fasthttp.ListenAndServe interface.
func (r *Router) Handler(ctx *fasthttp.RequestCtx) {
if r.PanicHandler != nil {
defer r.recv(ctx)
}
method := string(ctx.Method())
if root := r.trees[method]; root != nil {
path := string(ctx.Path())
if f, ps, tsr := root.getValue(path); f != nil {
f(ctx, ps)
return
} else if method != "CONNECT" && path != "/" {
code := 301 // Permanent redirect, request with GET method
if method != "GET" {
// Temporary redirect, request with same method
// As of Go 1.3, Go does not support status code 308.
code = 307
}
if tsr && r.RedirectTrailingSlash {
var uri string
if len(path) > 1 && path[len(path)-1] == '/' {
uri = path[:len(path)-1]
} else {
uri = path + "/"
}
ctx.Redirect(uri, code)
return
}
// Try to fix the request path
if r.RedirectFixedPath {
fixedPath, found := root.findCaseInsensitivePath(
CleanPath(path),
r.RedirectTrailingSlash,
)
if found {
uri := string(fixedPath)
ctx.Redirect(uri, code)
return
}
}
}
}
// Handle 405
if r.HandleMethodNotAllowed {
for method := range r.trees {
// Skip the requested method - we already tried this one
if method == string(ctx.Method()) {
continue
}
f, _, _ := r.trees[method].getValue(string(ctx.Path()))
if f != nil {
if r.MethodNotAllowed != nil {
r.MethodNotAllowed(ctx)
} else {
ctx.Error(fasthttp.StatusMessage(fasthttp.StatusMethodNotAllowed),
fasthttp.StatusMethodNotAllowed)
}
return
}
}
}
// Handle 404
if r.NotFound != nil {
r.NotFound(ctx)
} else {
ctx.Error(fasthttp.StatusMessage(fasthttp.StatusNotFound),
fasthttp.StatusNotFound)
}
}
示例3: Handler
// Handler makes the router implement the fasthttp.ListenAndServe interface.
func (r *Router) Handler(ctx *fasthttp.RequestCtx) {
if r.PanicHandler != nil {
defer r.recv(ctx)
}
path := string(ctx.Path())
method := string(ctx.Method())
if root := r.trees[method]; root != nil {
if f, ps, tsr := root.getValue(path); f != nil {
f(ctx, ps)
return
} else if method != "CONNECT" && path != "/" {
code := 301 // Permanent redirect, request with GET method
if method != "GET" {
// Temporary redirect, request with same method
// As of Go 1.3, Go does not support status code 308.
code = 307
}
if tsr && r.RedirectTrailingSlash {
var uri string
if len(path) > 1 && path[len(path)-1] == '/' {
uri = path[:len(path)-1]
} else {
uri = path + "/"
}
ctx.Redirect(uri, code)
return
}
// Try to fix the request path
if r.RedirectFixedPath {
fixedPath, found := root.findCaseInsensitivePath(
CleanPath(path),
r.RedirectTrailingSlash,
)
if found {
uri := string(fixedPath)
ctx.Redirect(uri, code)
return
}
}
}
}
if method == "OPTIONS" {
// Handle OPTIONS requests
if r.HandleOPTIONS {
if allow := r.allowed(path, method); len(allow) > 0 {
ctx.Response.Header.Set("Allow", allow)
return
}
}
} else {
// Handle 405
if r.HandleMethodNotAllowed {
if allow := r.allowed(path, method); len(allow) > 0 {
ctx.Response.Header.Set("Allow", allow)
if r.MethodNotAllowed != nil {
r.MethodNotAllowed(ctx)
} else {
ctx.SetStatusCode(fasthttp.StatusMethodNotAllowed)
ctx.SetContentTypeBytes(defaultContentType)
ctx.SetBodyString(fasthttp.StatusMessage(fasthttp.StatusMethodNotAllowed))
}
return
}
}
}
// Handle 404
if r.NotFound != nil {
r.NotFound(ctx)
} else {
ctx.Error(fasthttp.StatusMessage(fasthttp.StatusNotFound),
fasthttp.StatusNotFound)
}
}