summaryrefslogtreecommitdiffstats
path: root/lib/xdsconfig/builderconfig.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-11 19:42:00 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-11 19:42:22 +0200
commitec7051e1da665206f594c7616ad381bfeaea333a (patch)
treeecc01ee358794c9d8c5fbb87d2f5b6ce3f60f431 /lib/xdsconfig/builderconfig.go
parentca3e1762832b27dc25cf90125b376c56e24e2db2 (diff)
Initial main commit.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xdsconfig/builderconfig.go')
-rw-r--r--lib/xdsconfig/builderconfig.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/xdsconfig/builderconfig.go b/lib/xdsconfig/builderconfig.go
new file mode 100644
index 0000000..c64fe9c
--- /dev/null
+++ b/lib/xdsconfig/builderconfig.go
@@ -0,0 +1,50 @@
+package xdsconfig
+
+import (
+ "errors"
+ "net"
+)
+
+// BuilderConfig represents the builder container configuration
+type BuilderConfig struct {
+ IP string `json:"ip"`
+ Port string `json:"port"`
+ SyncThingID string `json:"syncThingID"`
+}
+
+// NewBuilderConfig creates a new BuilderConfig instance
+func NewBuilderConfig(stID string) (BuilderConfig, error) {
+ // Do we really need it ? may be not accessible from client side
+ ip, err := getLocalIP()
+ if err != nil {
+ return BuilderConfig{}, err
+ }
+
+ b := BuilderConfig{
+ IP: ip, // TODO currently not used
+ Port: "", // TODO currently not used
+ SyncThingID: stID,
+ }
+ return b, nil
+}
+
+// Copy makes a real copy of BuilderConfig
+func (c *BuilderConfig) Copy(n BuilderConfig) {
+ // TODO
+}
+
+func getLocalIP() (string, error) {
+ addrs, err := net.InterfaceAddrs()
+ if err != nil {
+ return "", err
+ }
+ for _, address := range addrs {
+ // check the address type and if it is not a loopback the display it
+ if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
+ if ipnet.IP.To4() != nil {
+ return ipnet.IP.String(), nil
+ }
+ }
+ }
+ return "", errors.New("Cannot determined local IP")
+}