misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
Simone Margaritelli 2024-09-19 21:49:02 +02:00
parent 91d360327a
commit 51a5b4ad6e
17 changed files with 1375 additions and 239 deletions

View file

@ -0,0 +1,35 @@
package zerogod
import (
"fmt"
"io/ioutil"
yaml "gopkg.in/yaml.v3"
)
func (mod *ZeroGod) save(address, filename string) error {
if address == "" {
return fmt.Errorf("address cannot be empty")
}
if filename == "" {
return fmt.Errorf("filename cannot be empty")
}
if ipServices, found := mod.mapping[address]; found {
data, err := yaml.Marshal(ipServices)
if err != nil {
return err
}
err = ioutil.WriteFile(filename, data, 0644)
if err != nil {
return err
}
mod.Info("mDNS information saved to %s", filename)
} else {
return fmt.Errorf("no mDNS information found for address %s", address)
}
return nil
}