func (c *Config) startDataBase() chan<- Item { dbc := make(chan Item, DB_BUFFER_SIZE) go func() { var con mysql.Conn for it := range dbc { if con == nil { con = c.connectDataBase() } if con != nil && it.Board != "" && it.Number != "" { var query string if it.Insert { query = fmt.Sprintf( "INSERT INTO thread_title (board,number,title,master,resnum) VALUES('%s',%s,'%s','%s',%d)", it.Board, it.Number, con.Escape(it.Title), con.Escape(utf8Substr(it.Master, 100)), it.Resnum) } else { query = fmt.Sprintf( "UPDATE thread_title SET resnum=%d WHERE board='%s' AND number=%s", it.Resnum, it.Board, it.Number) } _, _, err := con.Query(query) if err != nil { log.Printf("mysql query error [%s]", query) con.Close() con = nil } } } if con != nil { con.Close() con = nil } }() return dbc }