本文整理汇总了Golang中github.com/stretchrcom/goweb/context.Context.Path方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Path方法的具体用法?Golang Context.Path怎么用?Golang Context.Path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/stretchrcom/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
}