mirror of
https://github.com/restic/rest-server.git
synced 2025-12-07 09:36:13 -08:00
Vendor dependencies
This commit is contained in:
committed by
Zlatko Čalušić
parent
2f0a16d8b7
commit
6054876201
51
vendor/goji.io/pat/match.go
generated
vendored
Normal file
51
vendor/goji.io/pat/match.go
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
package pat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
|
||||
"goji.io/internal"
|
||||
"goji.io/pattern"
|
||||
)
|
||||
|
||||
type match struct {
|
||||
context.Context
|
||||
pat *Pattern
|
||||
matches []string
|
||||
}
|
||||
|
||||
func (m match) Value(key interface{}) interface{} {
|
||||
switch key {
|
||||
case pattern.AllVariables:
|
||||
var vs map[pattern.Variable]interface{}
|
||||
if vsi := m.Context.Value(key); vsi == nil {
|
||||
if len(m.pat.pats) == 0 {
|
||||
return nil
|
||||
}
|
||||
vs = make(map[pattern.Variable]interface{}, len(m.matches))
|
||||
} else {
|
||||
vs = vsi.(map[pattern.Variable]interface{})
|
||||
}
|
||||
|
||||
for _, p := range m.pat.pats {
|
||||
vs[p.name] = m.matches[p.idx]
|
||||
}
|
||||
return vs
|
||||
case internal.Path:
|
||||
if len(m.matches) == len(m.pat.pats)+1 {
|
||||
return m.matches[len(m.matches)-1]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
if k, ok := key.(pattern.Variable); ok {
|
||||
i := sort.Search(len(m.pat.pats), func(i int) bool {
|
||||
return m.pat.pats[i].name >= k
|
||||
})
|
||||
if i < len(m.pat.pats) && m.pat.pats[i].name == k {
|
||||
return m.matches[m.pat.pats[i].idx]
|
||||
}
|
||||
}
|
||||
|
||||
return m.Context.Value(key)
|
||||
}
|
||||
Reference in New Issue
Block a user