-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpath.go
More file actions
50 lines (41 loc) · 865 Bytes
/
path.go
File metadata and controls
50 lines (41 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (C) 2012 Numerotron Inc.
// Use of this source code is governed by an MIT-style license
// that can be found in the LICENSE file.
package bingo
import (
"net/http"
"strings"
)
type GPath []string
func Path(r *http.Request, prefixLen int) GPath {
path := r.URL.Path[prefixLen:]
if len(path) > 0 && path[0] == '/' {
path = path[1:]
}
if len(path) == 0 {
return GPath(nil)
}
return GPath(strings.Split(path, "/"))
}
func (p GPath) Extension() string {
if len(p) == 0 {
return ""
}
last := p[len(p)-1]
pieces := strings.Split(last, ".")
if len(pieces) < 2 {
return ""
}
return pieces[len(pieces)-1]
}
func (p GPath) Basename() string {
if len(p) == 0 {
return ""
}
last := p[len(p)-1]
pieces := strings.Split(last, ".")
if len(pieces) == 1 {
return pieces[0]
}
return strings.Join(pieces[0:len(pieces)-1], ".")
}