Closed ningblue closed 2 months ago
Describe the bug
I got an error when running main.go --- undefined: register
To Reproduce
Steps to reproduce the behavior:
// Code generated by hertz generator.
package main
import ( "xxx/apps/core/biz/dal" "xxx/apps/core/config" "fmt" "github.com/cloudwego/hertz/pkg/app/server" )
func main() { c := config.Data() // init config dal.InitData() // init db h := server.Default( server.WithHostPorts(fmt.Sprintf("%s:%d", c.Host, c.Port))) register(h) h.Spin() }
2.在同路径下有一个使用 hz 生成的 router_gen.go 文件 ```go // Code generated by hertz generator. DO NOT EDIT. package main import ( router "xxx/apps/core/biz/router" "github.com/cloudwego/hertz/pkg/app/server" ) // register registers all routers. func register(r *server.Hertz) { router.GeneratedRegister(r) customizedRegister(r) }
3.run main.go got error
# go run main.go # command-line-arguments ./main.go:17:2: undefined: register
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
Hertz version:
v0.9.1
Environment: mac go1.21
go run . 就可以,main package 下还有其他文件,需要都导入进来,否则无法编译
go run .
ok 好的 , 那就是可以使用 go run . 或者 go build -o xxx && ./xxx 这种
go build -o xxx && ./xxx
Describe the bug
I got an error when running main.go --- undefined: register
To Reproduce
Steps to reproduce the behavior:
package main
import ( "xxx/apps/core/biz/dal" "xxx/apps/core/config" "fmt" "github.com/cloudwego/hertz/pkg/app/server" )
func main() { c := config.Data() // init config dal.InitData() // init db h := server.Default( server.WithHostPorts(fmt.Sprintf("%s:%d", c.Host, c.Port))) register(h) h.Spin() }
3.run main.go got error
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
Hertz version:
v0.9.1
Environment: mac go1.21