Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package should consume and return pointers to net.IPNet #2

Closed
ericchiang opened this issue Dec 14, 2016 · 1 comment
Closed

Package should consume and return pointers to net.IPNet #2

ericchiang opened this issue Dec 14, 2016 · 1 comment

Comments

@ericchiang
Copy link

ericchiang commented Dec 14, 2016

Was trying to write an example for this package and saw that this doesn't compile.

package main

import (
	"fmt"
	"net"
	"os"

	"github.com/dghubble/ipnets"
)

func main() {
	_, ipNet, err := net.ParseCIDR("192.0.2.0/24")
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}

	nets, err := ipnets.Subnet(ipNet, 4)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}

	for _, net := range nets {
		fmt.Println(net)
	}
}
$ go run example.go 
# command-line-arguments
./example.go:18: cannot use ipNet (type *net.IPNet) as type net.IPNet in argument to ipnets.Subnet

Looks like everything in "net" always uses pointers to *IPNet. Maybe this package should too?

Edit. Also IPNet.String() is on a pointer so fmt.Println doesn't invoke that method.

@dghubble
Copy link
Owner

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants