grafana_gen/template.go
2026-02-24 12:45:35 +03:00

31 lines
668 B
Go

package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
)
func loadTemplate(templatesPath string) (*DashboardTemplate, error) {
templateFile := filepath.Join(templatesPath, "dashboard_template.json")
data, err := os.ReadFile(templateFile)
if err != nil {
return nil, fmt.Errorf("failed to read template file: %w", err)
}
var template DashboardTemplate
if err := json.Unmarshal(data, &template); err != nil {
return nil, fmt.Errorf("failed to parse template JSON: %w", err)
}
return &template, nil
}
func deepCopy(src interface{}) interface{} {
data, _ := json.Marshal(src)
var dst interface{}
json.Unmarshal(data, &dst)
return dst
}