mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
p2p/netutil: make Netlist decodable from TOML
This commit is contained in:
parent
3b48a35f96
commit
2a69d5a470
1 changed files with 25 additions and 0 deletions
|
|
@ -84,6 +84,31 @@ func ParseNetlist(s string) (*Netlist, error) {
|
|||
return &l, nil
|
||||
}
|
||||
|
||||
// MarshalTOML implements toml.MarshalerRec.
|
||||
func (l Netlist) MarshalTOML() interface{} {
|
||||
list := make([]string, 0, len(l))
|
||||
for _, net := range l {
|
||||
list = append(list, net.String())
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// UnmarshalTOML implements toml.UnmarshalerRec.
|
||||
func (l *Netlist) UnmarshalTOML(fn func(interface{}) error) error {
|
||||
var masks []string
|
||||
if err := fn(&masks); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, mask := range masks {
|
||||
_, n, err := net.ParseCIDR(mask)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*l = append(*l, *n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Add parses a CIDR mask and appends it to the list. It panics for invalid masks and is
|
||||
// intended to be used for setting up static lists.
|
||||
func (l *Netlist) Add(cidr string) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue