MCPcopy Create free account
hub / github.com/cloudwan/gohan / fixRelativeURL

Function fixRelativeURL

schema/url.go:28–53  ·  view source on GitHub ↗
(rawurl string, dir string)

Source from the content-addressed store, hash-verified

26}
27
28func fixRelativeURL(rawurl string, dir string) (string, error) {
29 if rawurl == "" {
30 return "", nil
31 }
32
33 u, err := url.Parse(rawurl)
34 if err != nil {
35 return "", fmt.Errorf("could not parse url: %s", err)
36 }
37
38 if u.Scheme == "" {
39 u.Scheme = "file"
40 }
41
42 if !isURLRelative(u) {
43 return u.String(), nil
44 }
45
46 dir, err = filepath.Abs(dir)
47 if err != nil {
48 return "", fmt.Errorf("failed to get absolute path: %s", err)
49 }
50 u.Host, u.Path = "", filepath.Join(dir, u.Host, u.Path)
51
52 return u.String(), nil
53}

Callers 3

TestFixRelativeURLFunction · 0.85
NewExtensionFunction · 0.85
loadSchemaFromFileMethod · 0.85

Calls 5

isURLRelativeFunction · 0.85
JoinMethod · 0.80
ParseMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by 1

TestFixRelativeURLFunction · 0.68