implement api cleanup
This commit is contained in:
parent
f7c2c51812
commit
b7290c54c9
|
@ -27,20 +27,23 @@ func NewAliases (config *models.Config, router *httprouter.Router,prefix string,
|
||||||
router.GET(prefix+"/alias/:nodeid", api.GetOne)
|
router.GET(prefix+"/alias/:nodeid", api.GetOne)
|
||||||
router.POST(prefix+"/alias/:nodeid", BasicAuth(api.SaveOne,[]byte(config.Webserver.Api.Passphrase)))
|
router.POST(prefix+"/alias/:nodeid", BasicAuth(api.SaveOne,[]byte(config.Webserver.Api.Passphrase)))
|
||||||
}
|
}
|
||||||
|
// clean up the aliases by correct values in nodes
|
||||||
func (api *ApiAliases) cleaner(){
|
func (api *ApiAliases) cleaner(){
|
||||||
var count int
|
|
||||||
for key,alias := range api.aliases.List {
|
for key,alias := range api.aliases.List {
|
||||||
//counter for the diffrent attribute
|
if node := api.nodes.List[key]; node !=nil {
|
||||||
count = 1
|
if nodeinfo := node.Nodeinfo; nodeinfo !=nil {
|
||||||
if alias.Hostname == api.nodes.List[key].Nodeinfo.Hostname {
|
//counter for the diffrent attribute
|
||||||
count -= 0
|
count := 1
|
||||||
}
|
if alias.Hostname == nodeinfo.Hostname {
|
||||||
//delete element
|
count -= 0
|
||||||
if count <= 0 {
|
}
|
||||||
delete(api.aliases.List,key)
|
//delete element
|
||||||
|
if count <= 0 {
|
||||||
|
delete(api.aliases.List,key)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// clean up the aliases by correct values in nodes
|
|
||||||
}
|
}
|
||||||
func (api *ApiAliases) GetAll(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func (api *ApiAliases) GetAll(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||||
jsonOutput(w,api.aliases.List)
|
jsonOutput(w,api.aliases.List)
|
||||||
|
|
Loading…
Reference in New Issue