echo: http: 恐慌服务:45724: 运行时错误: 无效的内存地址或 nil 指针取消引用 goroutine 10 :

echo: http: 恐慌服务:45724: 运行时错误: 无效的内存地址或 nil 指针取消引用 goroutine 10 :

问题内容

我尝试使用 go/echo 和 postgres 使用原始 sql 创建一个 REST API,但我无法使其工作,不知道问题是什么

控制台打印标题中的文本

食谱.go

func CreateRecipe(recipe *Recipe) error { query := `INSERT INTO recipes(title, ingredients, description) VALUES($1, $2, $3);` _, err := db.Exec(query, recipe.Title, recipe.Ingredients, recipe.Description) if err != nil { return err } return nil }登录后复制