saving changes

This commit is contained in:
2021-10-09 17:34:15 +04:00
parent a06e1be2bc
commit 56be275759
4 changed files with 78 additions and 2 deletions

View File

@@ -146,6 +146,8 @@ func ReadTrackContainers(filename string) (*TrackContainers, error) {
return c, nil
}
//func ModifyTrackContainers()
// GetContainerInformation gets information about container based on
// container ID provided
func GetContainerInformation(ID string) (*TrackContainer, error) {
@@ -164,6 +166,48 @@ func GetContainerInformation(ID string) (*TrackContainer, error) {
return nil, errors.New("Container not found. ")
}
// ModifyContainerInformation Modifies information inside the container
func (TC *TrackContainer)ModifyContainerInformation() error {
// Gets all the information of tracker containers
err, t := ViewTrackedContainers()
if err != nil {
return err
}
// Find the element where the containers match and
// change them
for i, container := range t.TrackContainerList {
if TC.Id == container.Id {
t.TrackContainerList[i] = *TC
break
}
}
// Write the modified information to the file
// write modified information to the tracked json file
err = t.WriteContainers()
if err != nil {
return err
}
return nil
}
// WriteContainers Write information back to the config file
func (TC *TrackContainers)WriteContainers() error {
// Initialize config file
config,err := config.ConfigInit()
// write modified information to the tracked json file
data,err := json.MarshalIndent(TC, "", "\t")
if err != nil {
return err
}
err = ioutil.WriteFile(config.TrackContainersPath,data,0777)
if err != nil {
return err
}
return nil
}
// CheckID Checks if the ID belongs to a group or a single container
func CheckID(ID string) (string,error) {
// For group checks if the 1st characters is "grp"