forked from andreaskoch/allmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
absolute.go
41 lines (32 loc) · 954 Bytes
/
absolute.go
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
// Copyright 2014 Andreas Koch. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package webpaths
import (
"github.com/andreaskoch/allmark/common/route"
"strings"
)
// Create a new absolute web path provider
func newAbsoluteWebPathProvider(prefix string) *AbsoluteWebPathProvider {
return &AbsoluteWebPathProvider{
prefix: prefix,
}
}
type AbsoluteWebPathProvider struct {
prefix string
}
// Get the absolute path for the supplied item
func (webPathProvider *AbsoluteWebPathProvider) Path(itemPath string) string {
// return the supplied item path if it is already absolute
if IsAbsoluteURI(itemPath) {
return itemPath
}
// don't do it twice
if strings.HasPrefix(itemPath, webPathProvider.prefix) {
return itemPath
}
return webPathProvider.prefix + itemPath
}
func (webPathProvider *AbsoluteWebPathProvider) Base() route.Route {
return route.New()
}