Go -已导入且未使用但必需[重复]

szqfcxe2  于 2023-09-28  发布在  Go
关注(0)|答案(1)|浏览(98)

此问题已在此处有答案

imported and not used error(1个答案)
rand package error in Go(2个答案)
15天前关闭。
我尝试导入一个go包,但得到以下错误:

.\data.go:10:2: "github.com/username/test/my-project/model" imported and not used
.\data.go:38:13: undefined: DataModel

这些是我的go文件:

main.go

package main

func main() {consumeApi()}

data.go

package main

import(
    "github.com/username/test/my-project/model"
)

func consumeApi() {
    ...
    var result DataModel
    if err := json.Unmarshal(body, &result); err != nil {
        fmt.Println("Can not unmarshal JSON")
    }
    ...
}
model.go
package model

type DataModel struct {
...
}

go.mod

module github.com/username/test/my-project

go 1.21.0

有人能帮我解决吗?

rn0zuynd

rn0zuynd1#

取代

var result DataModel

var result model.DataModel

相关问题