-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
64 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2020 Walter Scheper <[email protected]> | ||
// Copyright 2022 Walter Scheper <[email protected]> | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
|
@@ -9,7 +9,6 @@ package rapid | |
import ( | ||
"fmt" | ||
"net" | ||
"reflect" | ||
) | ||
|
||
const ( | ||
|
@@ -18,8 +17,6 @@ const ( | |
) | ||
|
||
var ( | ||
ipType = reflect.TypeOf(net.IP{}) | ||
|
||
ipv4Gen = SliceOfN(Byte(), ipv4Len, ipv4Len) | ||
ipv6Gen = SliceOfN(Byte(), ipv6Len, ipv6Len) | ||
) | ||
|
@@ -32,30 +29,26 @@ func (g *ipGen) String() string { | |
return fmt.Sprintf("IP(ipv6=%v)", g.ipv6) | ||
} | ||
|
||
func (*ipGen) type_() reflect.Type { | ||
return ipType | ||
} | ||
|
||
func (g *ipGen) value(t *T) value { | ||
var gen *Generator | ||
func (g *ipGen) value(t *T) net.IP { | ||
var gen *Generator[[]byte] | ||
if g.ipv6 { | ||
gen = ipv6Gen | ||
} else { | ||
gen = ipv4Gen | ||
} | ||
|
||
b := gen.Draw(t, g.String()).([]byte) | ||
b := gen.Draw(t, g.String()) | ||
return net.IP(b) | ||
} | ||
|
||
func IPv4() *Generator { | ||
return newGenerator(&ipGen{ | ||
func IPv4() *Generator[net.IP] { | ||
return newGenerator[net.IP](&ipGen{ | ||
ipv6: false, | ||
}) | ||
} | ||
|
||
func IPv6() *Generator { | ||
return newGenerator(&ipGen{ | ||
func IPv6() *Generator[net.IP] { | ||
return newGenerator[net.IP](&ipGen{ | ||
ipv6: true, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.