From 4996042bc936e62bc403c0a420bb46c7f8dd2437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Sterba?= <andre.sterba@stud.h-da.de> Date: Thu, 23 Jun 2022 14:28:38 +0200 Subject: [PATCH] Add basic configuration --- .../ports/configuration/configuration.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 controller/topology/ports/configuration/configuration.go diff --git a/controller/topology/ports/configuration/configuration.go b/controller/topology/ports/configuration/configuration.go new file mode 100644 index 000000000..f97abf526 --- /dev/null +++ b/controller/topology/ports/configuration/configuration.go @@ -0,0 +1,24 @@ +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 +} -- GitLab