Add Config API Calls

This commit is contained in:
Samuel Lorch 2023-04-01 18:17:08 +02:00
parent 390990af21
commit 081aeec142
2 changed files with 39 additions and 0 deletions

View file

@ -0,0 +1,7 @@
package config
import "nfsense.net/nfsense/internal/config"
type Config struct {
ConfigManager *config.ConfigManager
}

View file

@ -0,0 +1,32 @@
package config
import (
"context"
"fmt"
"github.com/r3labs/diff/v3"
)
type GetPendingStatusResult struct {
Changed bool
}
func (c *Config) GetPendingStatus(ctx context.Context, params struct{}) (GetPendingStatusResult, error) {
return GetPendingStatusResult{
Changed: c.ConfigManager.AreChangesPending(),
}, nil
}
type GetPendingChangelogResult struct {
Changelog diff.Changelog
}
func (c *Config) GetPendingChangelog(ctx context.Context, params struct{}) (GetPendingChangelogResult, error) {
log, err := c.ConfigManager.GetPendingChangelog()
if err != nil {
return GetPendingChangelogResult{}, fmt.Errorf("Get Pending changelog %w", err)
}
return GetPendingChangelogResult{
Changelog: log,
}, nil
}