Newer
Older
package configuration
import (
"fmt"
"net"
)
// IPConfig represents an interface configuration for a cEOS instance
IP net.IP `bson:"ip,omitempty"`
PrefixLength int `bson:"prefix_length,omitempty"`
func New(ip string, prefixLength int) (IPConfig, error) {
newIPConfig := IPConfig{}
parsedIP := net.ParseIP(ip)
if parsedIP == nil {
return newIPConfig, fmt.Errorf("%s can not be parsed to an IP", ip)
}
newIPConfig.IP = parsedIP
newIPConfig.PrefixLength = prefixLength
return newIPConfig, nil
}