Initial scaffold: project structure, .gitignore, go.mod
This commit is contained in:
27
internal/syncthing/config_xml.go
Normal file
27
internal/syncthing/config_xml.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package syncthing
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"os"
|
||||
|
||||
"git.davoryn.de/calic/syncwarden/internal/config"
|
||||
)
|
||||
|
||||
type syncthingConfig struct {
|
||||
GUI struct {
|
||||
APIKey string `xml:"apikey"`
|
||||
} `xml:"gui"`
|
||||
}
|
||||
|
||||
// DiscoverAPIKey reads the Syncthing config.xml and extracts the API key.
|
||||
func DiscoverAPIKey() (string, error) {
|
||||
data, err := os.ReadFile(config.SyncthingConfigPath())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var cfg syncthingConfig
|
||||
if err := xml.Unmarshal(data, &cfg); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return cfg.GUI.APIKey, nil
|
||||
}
|
||||
Reference in New Issue
Block a user