fix: custom absolute endpoints

This commit is contained in:
Livio Amstutz 2020-02-21 10:04:50 +01:00
parent 30d8dec409
commit 660519a19f
4 changed files with 41 additions and 16 deletions

View file

@ -2,14 +2,28 @@ package op
import "strings"
type Endpoint string
type Endpoint struct {
path string
url string
}
func NewEndpoint(path string) Endpoint {
return Endpoint{path: path}
}
func NewEndpointWithURL(path, url string) Endpoint {
return Endpoint{path: path, url: url}
}
func (e Endpoint) Relative() string {
return relativeEndpoint(string(e))
return relativeEndpoint(e.path)
}
func (e Endpoint) Absolute(host string) string {
return absoluteEndpoint(host, string(e))
if e.url != "" {
return e.url
}
return absoluteEndpoint(host, e.path)
}
func (e Endpoint) Validate() error {