diff --git a/http/client.go b/http/client.go index 25bfdb9..36afcd2 100644 --- a/http/client.go +++ b/http/client.go @@ -4,7 +4,8 @@ import ( "crypto/tls" "errors" "net" - "net/url" + + "git.3crabs.ru/VLADIMIR/net/url" ) type client struct{} diff --git a/url/examples/main.go b/url/examples/main.go new file mode 100644 index 0000000..4aa9c33 --- /dev/null +++ b/url/examples/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + + "git.3crabs.ru/VLADIMIR/net/url" +) + +func main() { + u, err := url.Parse("http://test.ru/") + if err != nil { + panic(err) + } + fmt.Printf("%+v", u) +} diff --git a/url/url.go b/url/url.go new file mode 100644 index 0000000..7b31ac8 --- /dev/null +++ b/url/url.go @@ -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 +}