dornc9470 2014-10-21 11:13
浏览 27
已采纳

MySQL和Go-ircevent

I'm new to golang and i'm trying to impliment MySQL lookup for multiple connections, however I keep getting an error using the below code.

cannot use irc.IRC("goTest", "goTee") (type *irc.Connection) as type string in assignment

result[0] is the network name

If i change
result[0] = irc.IRC("goTest", "goTee")
to
conn := irc.IRC("goTest", "goTee")
it works fine.

Any help is greatly appreciated.

package main

import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/thoj/go-ircevent"
)

func main() {

db, err := sql.Open("mysql", sqllogin()+":"+sqlpasswd()+"@("+sqlip()+":"+sqlport()+")/"+sqlgodb())

rows, err := db.Query("SELECT * FROM `network` ")

cols, err := rows.Columns()

rawResult := make([][]byte, len(cols))
result := make([]string, len(cols))
fmt.Println(rawResult)
dest := make([]interface{}, len(cols))
for i, _ := range rawResult {
    dest[i] = &rawResult[i]
}

for rows.Next() {
    err = rows.Scan(dest...)
    if err != nil {
        fmt.Println("Failed to scan row", err)
        return
    }

    for i, raw := range rawResult {
        if raw == nil {
            result[i] = ""
        } else {
            result[i] = string(raw)
        }
    }
    result[0] = irc.IRC("goTest", "goTee")

    result[0].Connect("ip:port")

}
    result[0].Loop()

}
  • 写回答

1条回答 默认 最新

  • dpw50696 2014-10-22 07:34
    关注

    The types don't match.

    result := make([]string, len(cols)) Here you make result to be a slice of strings

    result[0] = irc.IRC("goTest", "goTee") You are trying to put a pointer to a connection into a string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料