简体   繁体   中英

Go “cannot find package”

I have a public repository https://github.com/zhksoftGo/Packet . I have put some common go files in it. Currently, there are two.

 Packet.go under github.com/zhksoftGo/Packet
 TypeDefineCactus.go under github.com/zhksoftGo/Packet/protocol/Cactus/

I meet trouble at importing one of them.

import "github.com/zhksoftGo/Packet"   // works fine
import "github.com/zhksoftGo/Packet/protocol/Cactus" // "cannot find package"

//referer project.mod file:

module github.com/zhksoftGo/SnowWolf

go 1.15

require (
    github.com/gookit/slog v0.1.3
    github.com/panjf2000/gnet v1.4.2
    github.com/smartystreets/goconvey v1.6.4 // indirect
    github.com/zhksoftGo/Packet v0.0.0-20210320131229-5311a044e61f
    gopkg.in/ini.v1 v1.62.0
)

I have already set GO111MODULE=on. Could somebody help on this?

The root reason is my generator inserts utf-8 BOM chars in the generated Go file header. It works if a normal Go file import a generated Go file. But does not work if the generated Go file has another generated Go file imported. So for Go source file, we'd better use UTF-8.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM