indexing logic
This commit is contained in:
parent
81dbb99017
commit
42513feedf
15
main.go
15
main.go
@ -36,15 +36,20 @@ func indexInstances(config state.Config) state.Config {
|
|||||||
fmt.Println("Error converting ip:", err)
|
fmt.Println("Error converting ip:", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
config = indexInstance(config, cloudID, ip)
|
newService, found := indexInstance(config, cloudID, ip)
|
||||||
|
if !found {
|
||||||
|
config.MTD.Services = append(config.MTD.Services, newService)
|
||||||
|
state.SaveConf(ConfigPath, config)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) state.Config {
|
func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (state.Service, bool) {
|
||||||
|
found := false
|
||||||
for _, service := range config.MTD.Services {
|
for _, service := range config.MTD.Services {
|
||||||
if service.CloudID == cloudID {
|
if service.CloudID == cloudID {
|
||||||
return config
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
u := uuid.New()
|
u := uuid.New()
|
||||||
@ -52,7 +57,5 @@ func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) st
|
|||||||
ID: state.CustomUUID(u),
|
ID: state.CustomUUID(u),
|
||||||
CloudID: cloudID,
|
CloudID: cloudID,
|
||||||
ServiceIP: serviceIP}
|
ServiceIP: serviceIP}
|
||||||
config.MTD.Services = append(config.MTD.Services, newService)
|
return newService, found
|
||||||
state.SaveConf(ConfigPath, config)
|
|
||||||
return config
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user