add url package

This commit is contained in:
2025-07-21 03:10:02 +07:00
parent b897a4dfda
commit 78cf1e5e3f
3 changed files with 48 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
package url
type URL struct {
Scheme string
Host string
Path string
}
func Parse(rawURL string) (*URL, error) {
schemeIndex := -1
hostStartIndex := -1
hostEndIndex := -1
for i := 0; i < len(rawURL); i++ {
if schemeIndex == -1 && rawURL[i] == ':' {
schemeIndex = i
hostStartIndex = i + 3
i += 3
continue
}
if rawURL[i] == '/' {
hostEndIndex = i
break
}
}
return &URL{
Scheme: rawURL[:schemeIndex],
Host: rawURL[hostStartIndex:hostEndIndex],
Path: rawURL[hostEndIndex:],
}, nil
}