forked from manyminds/api2go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
resolver.go
42 lines (34 loc) · 1.01 KB
/
resolver.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
42
package api2go
import "net/http"
type callbackResolver struct {
callback func(r http.Request) string
r http.Request
}
// NewCallbackResolver handles each resolve via
// your provided callback func
func NewCallbackResolver(callback func(http.Request) string) URLResolver {
return &callbackResolver{callback: callback}
}
// GetBaseURL calls the callback given in the constructor method
// to implement `URLResolver`
func (c callbackResolver) GetBaseURL() string {
return c.callback(c.r)
}
// SetRequest to implement `RequestAwareURLResolver`
func (c *callbackResolver) SetRequest(r http.Request) {
c.r = r
}
// staticResolver is only used
// for backwards compatible reasons
// and might be removed in the future
type staticResolver struct {
baseURL string
}
func (s staticResolver) GetBaseURL() string {
return s.baseURL
}
// NewStaticResolver returns a simple resolver that
// will always answer with the same url
func NewStaticResolver(baseURL string) URLResolver {
return &staticResolver{baseURL: baseURL}
}