Skip to content

Commit

Permalink
use url.Parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken2mer committed Mar 2, 2021
1 parent a7de105 commit cb746e6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions net/dial.go
Expand Up @@ -5,16 +5,21 @@ import (
"log"
"net"
"net/http"
"strings"
"net/url"
)

// HTTPClient inspired by https://ascii.jp/elem/000/001/276/1276572/
func HTTPClient(url string) (*http.Response, error) {
conn, err := net.Dial("tcp", strings.Split(url, "://")[1])
func HTTPClient(rawurl string) (*http.Response, error) {
u, err := url.Parse(rawurl)
if err != nil {
log.Fatal(err)
}
request, err := http.NewRequest("GET", url, nil)

conn, err := net.Dial("tcp", u.Host)
if err != nil {
log.Fatal(err)
}
request, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit cb746e6

Please sign in to comment.