Add IPv6 address support

This commit is contained in:
Viktor Villainov 2019-04-03 17:50:05 -04:00
parent 139f940005
commit b9b3e9bcc0

5
irc.go
View File

@ -428,7 +428,7 @@ func (irc *Connection) Connect(server string) error {
if len(irc.Server) == 0 { if len(irc.Server) == 0 {
return errors.New("empty 'server'") return errors.New("empty 'server'")
} }
if strings.Count(irc.Server, ":") != 1 { if !strings.HasPrefix("[", irc.Server) && strings.Count(irc.Server, ":") != 1 {
return errors.New("wrong number of ':' in address") return errors.New("wrong number of ':' in address")
} }
if strings.Index(irc.Server, ":") == 0 { if strings.Index(irc.Server, ":") == 0 {
@ -438,7 +438,8 @@ func (irc *Connection) Connect(server string) error {
return errors.New("port missing") return errors.New("port missing")
} }
// check for valid range // check for valid range
ports := strings.Split(irc.Server, ":")[1] substrings := strings.Split(irc.Server, ":")
ports := substrings[len(substrings) - 1]
port, err := strconv.Atoi(ports) port, err := strconv.Atoi(ports)
if err != nil { if err != nil {
return errors.New("extracting port failed") return errors.New("extracting port failed")