Skip to content
Snippets Groups Projects
configuration.go 479 B
Newer Older
  • Learn to ignore specific revisions
  • André Sterba's avatar
    André Sterba committed
    package configuration
    
    import (
    	"fmt"
    	"net"
    )
    
    type IPConfig struct {
    	IP           net.IP `json:"ip,omitempty"`
    	PrefixLength int    `json:"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
    }