seancfoley / ipaddress-go

Go library for handling IP addresses and subnets, both IPv4 and IPv6
https://seancfoley.github.io/IPAddress/
Apache License 2.0
87 stars 9 forks source link

"main redeclared in this block" #7

Closed hickford closed 12 months ago

hickford commented 1 year ago

I tried to build this library go build ./... and got error:

# github.com/seancfoley/ipaddress-go/ipaddr/cmd
ipaddr/cmd/test.go:25:6: main redeclared in this block
        ipaddr/cmd/main.go:37:6: other declaration of main
seancfoley commented 1 year ago

I've taken a look at this issue and your associated PR.

I haven't quite made up my mind, but it's likely that I will not merge your associated PR as the solution, which moves the test.go main function into the ipaddr/test package, because the test package is meant to contain code for that package only and not a second package. AFAIK, the usual go convention is to avoid having a go "main" package source file in the same folder as other packages, so as not to mix the library or test code with application code to create binaries.

I've looked into how the go community usually handles this situation of having multiple binaries, and while there are not a lot of resources out there addressing this, I have found more than one resource suggesting that each binary should be in its own subfolder of the cmd folder, so I'm likely gonna do that, which should address this.

seancfoley commented 12 months ago

fixed in version 1.5.5