From b863b7d9b2af5f5ef390e6769c74b30b0a95ef69 Mon Sep 17 00:00:00 2001 From: amirhnajafiz Date: Mon, 10 Oct 2022 16:36:33 +0330 Subject: [PATCH] update: url struct --- client.go | 2 +- url.go | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/client.go b/client.go index 946716a..b3af43d 100644 --- a/client.go +++ b/client.go @@ -27,7 +27,7 @@ func NewClient(uri string) (Client, error) { return nil, fmt.Errorf("invalid uri: %w", err) } - conn, err := net.Dial("tcp", url.host+":"+url.port) + conn, err := net.Dial("tcp", url.address) if err != nil { return nil, fmt.Errorf("failed to connect to server: %w", err) } diff --git a/url.go b/url.go index 4cafaef..a4341d9 100644 --- a/url.go +++ b/url.go @@ -10,8 +10,7 @@ import ( // - host // - port type url struct { - host string - port string + address string } // urlUnpack @@ -29,13 +28,11 @@ func urlUnpack(inputUrl string) (*url, error) { } // exporting the host:port pair. - hostInformation := strings.Split(protocolSplit[1], ":") - if len(hostInformation) < 2 { + if len(strings.Split(protocolSplit[1], ":")) < 2 { return nil, fmt.Errorf("server ip or port is not given") } return &url{ - host: hostInformation[0], - port: hostInformation[1], + address: protocolSplit[1], }, nil }