diff --git a/hit.go b/hit.go index 4f579bad..690f1580 100644 --- a/hit.go +++ b/hit.go @@ -39,7 +39,6 @@ package hit import ( "context" - "fmt" "net/http" "golang.org/x/xerrors" @@ -68,9 +67,6 @@ type Hit interface { // BaseURL returns the current base url. BaseURL() string - // SetBaseURL sets the base url. - SetBaseURL(url string, a ...interface{}) - // CurrentStep returns the current working step. CurrentStep() IStep @@ -167,10 +163,6 @@ func (hit *hitImpl) BaseURL() string { return hit.baseURL } -func (hit *hitImpl) SetBaseURL(url string, a ...interface{}) { - hit.baseURL = fmt.Sprintf(url, a...) -} - func (hit *hitImpl) collectSteps(state StepTime) []IStep { var collectedSteps []IStep for i := 0; i < len(hit.steps); i++ { diff --git a/static.go b/static.go index 5151ee3d..a72f4ac1 100644 --- a/static.go +++ b/static.go @@ -2,6 +2,7 @@ package hit import ( "context" + "fmt" "io" "net/http" "os" @@ -154,7 +155,10 @@ func BaseURL(url string, a ...interface{}) IStep { When: requestCreateStep, CallPath: newCallPath("BaseURL", nil), Exec: func(hit *hitImpl) error { - hit.SetBaseURL(url, a...) + if len(a) > 0 { + url = fmt.Sprintf(url, a...) + } + hit.baseURL = url return nil }, } @@ -192,7 +196,7 @@ func makeMethodStep(fnName, method, url string, a ...interface{}) IStep { CallPath: newCallPath(fnName, nil), Exec: func(hit *hitImpl) error { hit.request.Method = method - url = misc.MakeURL(hit.BaseURL(), url, a...) + url = misc.MakeURL(hit.baseURL, url, a...) if url == "" { hit.request.URL = new(urlpkg.URL) return nil