IPNet -> JSONIPnet
This commit is contained in:
parent
099324b7f8
commit
0e118b3b6f
4
init.go
4
init.go
@ -35,12 +35,12 @@ func Init() {
|
||||
|
||||
// get a random /22 subnet on 10.0.0.0 (1023 hosts) (or /24?)
|
||||
// TODO also the 20 bit block and 16 bit block?
|
||||
func getRandomNetwork() IPNet {
|
||||
func getRandomNetwork() JSONIPNet {
|
||||
rbs := make([]byte, 2)
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
rand.Read(rbs)
|
||||
|
||||
return IPNet{
|
||||
return JSONIPNet{
|
||||
net.IPNet {
|
||||
net.IP{10,rbs[0],rbs[1]<<2,0},
|
||||
net.IPMask{255,255,252,0},
|
||||
|
6
types.go
6
types.go
@ -64,14 +64,14 @@ type Dsnet struct {
|
||||
Peers []Peer
|
||||
}
|
||||
|
||||
type IPNet struct {
|
||||
type JSONIPNet struct {
|
||||
ipNet net.IPNet
|
||||
}
|
||||
|
||||
func (n IPNet) MarshalJSON() ([]byte, error) {
|
||||
func (n JSONIPNet) MarshalJSON() ([]byte, error) {
|
||||
return []byte("\"" + n.ipNet.String() + "\""), nil
|
||||
}
|
||||
|
||||
func (n *IPNet) String() string {
|
||||
func (n *JSONIPNet) String() string {
|
||||
return n.ipNet.String()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user