Skip to content

Commit

Permalink
update: url struct
Browse files Browse the repository at this point in the history
  • Loading branch information
amirhnajafiz committed Oct 10, 2022
1 parent 8699077 commit b863b7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 3 additions & 6 deletions url.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
// - host
// - port
type url struct {
host string
port string
address string
}

// urlUnpack
Expand All @@ -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
}

0 comments on commit b863b7d

Please sign in to comment.