tinygo-org / net

Port of Go's "net" package to work with TinyGo on embedded processors.
https://tinygo.org
BSD 2-Clause "Simplified" License
23 stars 9 forks source link

Add ResolveTCPAddr ResolveUnixAddr #5

Open hmmftg opened 1 year ago

hmmftg commented 1 year ago

Hi, I newly started using tiny go, when I tried build my gin project I got these errors:

tinygo build -o a.out main
# github.com/go-playground/validator/v10
vendor/github.com/go-playground/validator/v10/baked_in.go:2350:16: undefined: net.ResolveTCPAddr
vendor/github.com/go-playground/validator/v10/baked_in.go:2360:16: undefined: net.ResolveTCPAddr
vendor/github.com/go-playground/validator/v10/baked_in.go:2371:16: undefined: net.ResolveTCPAddr
vendor/github.com/go-playground/validator/v10/baked_in.go:2382:16: undefined: net.ResolveUDPAddr
vendor/github.com/go-playground/validator/v10/baked_in.go:2393:16: undefined: net.ResolveUDPAddr
vendor/github.com/go-playground/validator/v10/baked_in.go:2404:16: undefined: net.ResolveUDPAddr
vendor/github.com/go-playground/validator/v10/baked_in.go:2415:16: undefined: net.ResolveIPAddr
vendor/github.com/go-playground/validator/v10/baked_in.go:2426:16: undefined: net.ResolveIPAddr
vendor/github.com/go-playground/validator/v10/baked_in.go:2437:16: undefined: net.ResolveIPAddr
vendor/github.com/go-playground/validator/v10/baked_in.go:2444:16: undefined: net.ResolveUnixAddr

I don't really need ResolveTCPAddr but if you please add this method to library, I can start using tinygo.

scottfeldman commented 1 year ago

Hello @hmmftg,

I believe based on your err listing that you're using standard TinyGo compiler, which doesn't have support for net.ResolveXXXAddr. This github project (tinygo-org/net) is an effort to update TinyGo's net package support, but it is not included in standard TinyGo. It will be in the future and it will include support for net.ResolveXXXAddr.

A work-around for you would be to add stubbed out versions of net.ResolveTCPAddr to the tinygo project (tinygo-org/tinygo/src/net). Just to make the compiler happy so you can continue.

An alternate work-around is to try with the development version of TinyGo that includes this github project. I can give you tips on building a custom tinygo if you want to go this route.

scottfeldman commented 11 months ago

@hmmftg, if you don't want to wait for the next release, please try the dev version of TinyGo. It should have support:

sfeldma@nuc:~/work/tinygo/src/net$ grep -r "func Resolve.*Addr" .
./udpsock.go:func ResolveUDPAddr(network, address string) (*UDPAddr, error) {
./tcpsock.go:func ResolveTCPAddr(network, address string) (*TCPAddr, error) {
hmmftg commented 11 months ago

actually I was thinking about migrating a big rest api written with gin to tiny go, it seems I'm going in wrong path. no?