not authorized 错误有什么解决办法吗?

Is there any solution to the not authorized error?

sqlite3, err := sql.Open("sqlite3", "./map.gpkg")
if err != nil {
    panic(err.Error())
}

_, err = sqlite3.Exec("select load_extension('mod_spatialite');")
if err != nil {
    panic(err.Error())
}

当我尝试将 spatialite 扩展加载到 sqlite3 中时,出现 returns 未授权错误,我不知道如何修复它。

panic: not authorized

goroutine 1 [running]:
main.main()
        /Users/u/project/project/golang_project/pack/sql/main.go:42 +0x145
exit status 2

您需要使用 SQLiteDriver 的 Extensions 字段注册扩展:

sql.Register("sqlite3_TestExtensionsError",
    &sqlite3.SQLiteDriver{
        Extensions: []string{
            "foobar",
        },
    },
)

看这个例子:https://github.com/mattn/go-sqlite3/blob/1157a4212dcb650962563f67cd405794e9115b45/sqlite3_load_extension_test.go#L15

sql.Register("sqlite3_with_extensions",
    &sqlite3.SQLiteDriver{
        Extensions: []string{
            "mod_spatialite",
        },
    })

db, err := sql.Open("sqlite3_with_extensions", "./map.gpkg")
if err != nil {
    panic(err.Error())
}

我按上面的方法更改了代码,我的代码工作正常。