Пример #1
0
func (i *Irc) Serve() {
	if i.eventReceived == nil || i.messageReceived == nil {
		log.Fatal("Missing an event handler")
	}

	var err error
	i.Client, err = irc.DialSSL(
		i.config.Irc.Server,
		i.config.Nick,
		i.config.FullName,
		i.config.Irc.Pass,
		true,
	)
	if err != nil {
		log.Fatal(err)
	}

	for _, c := range i.config.Channels {
		i.JoinChannel(c)
	}

	i.quit = make(chan bool)
	go i.handleConnection()
	<-i.quit
}
Пример #2
0
Файл: main.go Проект: aoeu/acme
// Connect returns a channel upon which the
// value true is sent when a connection with
// the server is successfully established.
func connect(addr string) <-chan bool {
	conn := make(chan bool)
	go func(chan<- bool) {
		timeout := initialTimeout
		for {
			var err error
			if *ssl {
				client, err = irc.DialSSL(addr, *nick, *full, *pass, *trustSsl)
			} else {
				client, err = irc.Dial(addr, *nick, *full, *pass)
			}
			if err == nil {
				conn <- true
				return
			}
			serverWin.WriteString("Failed to connect: " + err.Error())
			timeout *= 2
			<-time.After(timeout)
		}
	}(conn)
	return conn
}