-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opts.IpOpt: a helper to parse IP addressed from the command line
Signed-off-by: Solomon Hykes <[email protected]>
- Loading branch information
Solomon Hykes
committed
Aug 13, 2014
1 parent
a4befff
commit 6d59a56
Showing
1 changed file
with
28 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package opts | ||
|
||
import ( | ||
"net" | ||
) | ||
|
||
type IpOpt struct { | ||
*net.IP | ||
} | ||
|
||
func NewIpOpt(ref *net.IP, defaultVal string) *IpOpt { | ||
o := &IpOpt{ | ||
IP: ref, | ||
} | ||
o.Set(defaultVal) | ||
return o | ||
} | ||
|
||
func (o *IpOpt) Set(val string) error { | ||
// FIXME: return a parse error if the value is not a valid IP? | ||
// We are not changing this now to preserve behavior while refactoring. | ||
(*o.IP) = net.ParseIP(val) | ||
return nil | ||
} | ||
|
||
func (o *IpOpt) String() string { | ||
return (*o.IP).String() | ||
} |