-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl.go
More file actions
31 lines (24 loc) · 617 Bytes
/
url.go
File metadata and controls
31 lines (24 loc) · 617 Bytes
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
package fetch
import (
. "github.com/tinywasm/fmt"
)
var defaultBaseURL string
// SetBaseURL sets the global base URL for all requests.
func SetBaseURL(url string) {
defaultBaseURL = url
}
// GetBaseURL returns the current global base URL.
func GetBaseURL() string {
return defaultBaseURL
}
// buildURL constructs the full request URL using the new resolution logic.
func buildURL(r *Request) (string, error) {
endpoint, err := resolveEndpoint(r.endpoint)
if err != nil {
return "", err
}
if endpoint == "" {
return "", Err("endpoint cannot be empty")
}
return buildFullURL(endpoint, r.baseURL)
}