本文整理匯總了Golang中github.com/MG-RAST/golib/stretchr/goweb/context.Context.Path方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Path方法的具體用法?Golang Context.Path怎麽用?Golang Context.Path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MG-RAST/golib/stretchr/goweb/context.Context
的用法示例。
在下文中一共展示了Context.Path方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WillHandle
// WillHandle checks whether this handler will be used to handle the specified
// request or not.
func (p *PathMatchHandler) WillHandle(c context.Context) (bool, error) {
// check each matcher func
matcherFuncMatches := true
matcherFuncDecisionMade := false
for _, matcherFunc := range p.MatcherFuncs {
decision, matcherFuncErr := matcherFunc(c)
if matcherFuncErr != nil {
return false, matcherFuncErr
}
switch decision {
case NoMatch:
matcherFuncMatches = false
matcherFuncDecisionMade = true
break
case Match:
matcherFuncMatches = true
matcherFuncDecisionMade = true
break
}
if matcherFuncDecisionMade {
break
}
}
// check HTTP methods
var httpMethodMatch bool = false
if len(p.HttpMethods) == 0 {
// no specific HTTP methods
httpMethodMatch = true
} else {
for _, httpMethod := range p.HttpMethods {
if httpMethod == c.MethodString() {
httpMethodMatch = true
break
}
}
}
// cancel early if we didn't get an HTTP Method match
if !httpMethodMatch {
return false, nil
}
// check path match
pathMatch := p.PathPattern.GetPathMatch(c.Path())
var allMatch bool
if matcherFuncDecisionMade {
allMatch = matcherFuncMatches
} else {
allMatch = pathMatch.Matches
}
if allMatch {
// save the match parameters for later
c.Data().Set(context.DataKeyPathParameters, pathMatch.Parameters)
}
return allMatch, nil
}