Beginner go, read database write file error

error signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x11fd947

package main

import (
    "database/sql"
    "fmt"
    "log"
    _ "github.com/go-sql-driver/mysql"
    "github.com/tealeg/xlsx"
)

var (
    dbHostsIp  = ""
    dbUserName = ""
    dbPassword = ""
    dbName     = ""
)

func main() {
    db, err := sql.Open("mysql", "root:univer@tcp(10.10.0.49:3306)/audit_test?charset=utf8")
    if err != nil {
        fmt.Println(err)
        return
    }

    defer db.Close()

    fmt.Println("")

    var fileX *xlsx.File
    var sheetX *xlsx.Sheet
    var rowX *xlsx.Row
    var cellX *xlsx.Cell


    /*
        
        
        

        v1, v2, _ := function(...)
     */
    fileX, _ = xlsx.OpenFile("MyXLSXFile.xlsx")
    sheetX = fileX.Sheet["Sheet1"]

    rows, err := db.Query("select * from media;")

    if err != nil {
        log.Fatal(err)
    }
    defer rows.Close()
    columns, err := rows.Columns()
    if err != nil {
        log.Fatal(err)
    }

    values := make([]sql.RawBytes, len(columns))
        scanArgs := make([]interface{}, len(values))
        for i := range values {
            scanArgs[i] = &values[i]
        }
        for rows.Next() {
            rowX = sheetX.AddRow()
            err = rows.Scan(scanArgs...)
            if err != nil {
                log.Fatal(err)
            }
            var value string
            for i, col := range values {
                if col == nil {
                    value = "NULL"
                } else {
                    value = string(col)
                }
                fmt.Println(columns[i], ": ", value)
                cellX = rowX.AddCell()
                cellX.Value = value
                fileX.Save("MyXLSXFile1.xlsx")
            }
            fmt.Println("------------------")

        }
        if err = rows.Err(); err != nil {
            log.Fatal(err)
        }



}
Apr.07,2021

preliminary judgment is null pointer, I see you fileX these variables defined not initialized, but the following used.


this problem is probably due to the failure to establish your database connection

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5ba0a-44300.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5ba0a-44300.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?