-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetsetting.go
More file actions
42 lines (37 loc) · 1.04 KB
/
getsetting.go
File metadata and controls
42 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package PluginLib
import (
"fmt"
"log"
)
// GetSetting retrieves the value of a specific setting by name from the /api/v2/settings endpoint.
func GetSetting(name string) (any, error) {
if name == "" {
return nil, fmt.Errorf("setting name must not be empty")
}
var settings map[string][]map[string]any
_, err := Get("/api/v2/settings", &settings)
if err != nil {
return nil, fmt.Errorf("failed to get settings: %v", err)
}
data, ok := settings["data"]
if !ok {
return nil, fmt.Errorf("no 'data' key in settings response")
}
for _, setting := range data {
if settingName, ok := setting["name"].(string); ok && settingName == name {
value, exists := setting["value"]
if !exists {
return nil, fmt.Errorf("setting '%s' has no 'value' field", name)
}
return value, nil
}
}
return nil, fmt.Errorf("setting '%s' not found", name)
}
func GetAllSettings() (settings map[string][]map[string]any) {
_, err := Get("/api/v2/settings", &settings)
if err != nil {
log.Fatalf("Failed to get settings: %v", err)
}
return settings
}