move ObjectUrl() to a func on Configuration
This commit is contained in:
parent
3488d5a0b9
commit
f8b861df19
@ -12,9 +12,7 @@ import (
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
@ -395,7 +393,7 @@ func setErrorHeaderContext(err *WrappedError, prefix string, head http.Header) {
|
||||
}
|
||||
|
||||
func clientRequest(method, oid string) (*http.Request, Creds, error) {
|
||||
u := ObjectUrl(oid)
|
||||
u := Config.ObjectUrl(oid)
|
||||
req, err := http.NewRequest(method, u.String(), nil)
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
if err == nil {
|
||||
@ -413,13 +411,6 @@ func clientRequest(method, oid string) (*http.Request, Creds, error) {
|
||||
return req, nil, err
|
||||
}
|
||||
|
||||
func ObjectUrl(oid string) *url.URL {
|
||||
c := Config
|
||||
u, _ := url.Parse(c.Endpoint())
|
||||
u.Path = path.Join(u.Path, "objects", oid)
|
||||
return u
|
||||
}
|
||||
|
||||
type ClientError struct {
|
||||
Message string `json:"message"`
|
||||
RequestId string `json:"request_id,omitempty"`
|
||||
|
@ -347,10 +347,9 @@ func TestObjectUrl(t *testing.T) {
|
||||
"http://example.com/foo/": "http://example.com/foo/objects/oid",
|
||||
}
|
||||
|
||||
config := Config
|
||||
for endpoint, expected := range tests {
|
||||
config.SetConfig("hawser.url", endpoint)
|
||||
assert.Equal(t, expected, ObjectUrl(oid).String())
|
||||
Config.SetConfig("hawser.url", endpoint)
|
||||
assert.Equal(t, expected, Config.ObjectUrl(oid).String())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/hawser/git-hawser/git"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
@ -96,6 +97,12 @@ func (c *Configuration) SetConfig(key, value string) {
|
||||
c.gitConfig[key] = value
|
||||
}
|
||||
|
||||
func (c *Configuration) ObjectUrl(oid string) *url.URL {
|
||||
u, _ := url.Parse(c.Endpoint())
|
||||
u.Path = path.Join(u.Path, "objects", oid)
|
||||
return u
|
||||
}
|
||||
|
||||
type AltConfig struct {
|
||||
Remote map[string]*struct {
|
||||
Media string
|
||||
|
Loading…
Reference in New Issue
Block a user