I have an issue with structs and maybe an issue with pointers, if my guess is correct.
This struct has some fields and a field that holds a slice:
type Bot struct {
// ...
connlist []Connection
}
Connection
type Connection struct {
conn net.Conn
messages int32
channels []string
joins int32
connactive bool
}
connactivetrue
Bot
func (bot *Bot) ListenToConnection(connection Connection) {
reader := bufio.NewReader(connection.conn)
tp := textproto.NewReader(reader)
for {
line, err := tp.ReadLine()
if err != nil {
log.Printf("Error reading from chat connection: %s", err)
break // break loop on errors
}
if strings.Contains(line, "tmi.twitch.tv 001") {
connection.activateConn()
}
if strings.Contains(line, "PING ") {
fmt.Fprintf(connection.conn, "PONG tmi.twitch.tv\r\n")
}
fmt.Fprintf(bot.inconn, line+"\r\n")
}
}
connection.activeConn()
func (connection *Connection) activateConn() {
connection.connactive = true
}
This actually gets executed so it's not an issue of the connection not getting a response or something.
Botconnactivefalse
for i := 0; i < len(bot.connlist); i++ {
log.Println(bot.connlist[i].connactive)
}
connactive = true
Any ideas? Thanks for the help.