func loadGrafanaTemplates(c *GrafanaConfig) (map[string]string, error) {
	data := make(map[string]string)

	templateDir := filepath.Join(getGrafanaConfigPath(), "templates")
	entries, err := ioutil.ReadDir(templateDir)
	if err != nil {
		return nil, err
	}

	for _, entry := range entries {
		if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".tmpl") {
			continue // Ignore directories and anything that doesn't end with '.tmpl'
		}

		filename := entry.Name()
		path := filepath.Join(templateDir, filename)
		tmpl, err := template.ParseFiles(path)
		if err != nil {
			return nil, err
		}

		buf := new(bytes.Buffer)
		err = tmpl.Execute(buf, c)
		if err != nil {
			return nil, err
		}

		parts := strings.Split(filename, ".tmpl")
		if len(parts) <= 1 {
			return nil, fmt.Errorf("invalid template name: %s", filename)
		}

		key := parts[0]
		data[key] = buf.String()
	}

	return data, nil
}
// loadGrafanaTemplates will scan the template directory and parse/execute any files ending with '.tmpl'
loadGrafanaTemplates will scan the template directory and parse/execute any files ending with '.tmpl'
// loadGrafanaTemplates will scan the template directory and parse / execute any files ending with ' . tmpl '
func loadGrafanaTemplates(c *GrafanaConfig) (map[string]string, error) {
	data := make(map[string]string)
	templateDir := filepath.Join(getGrafanaConfigPath(), "templates")
	entries, err := ioutil.ReadDir(templateDir)
	if err != nil {
		return nil, err
	}
	for _, entry := range entries {
		if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".tmpl") {
			continue 
		}
		filename := entry.Name()
		path := filepath.Join(templateDir, filename)
		tmpl, err := template.ParseFiles(path)
		if err != nil {
			return nil, err
		}
		buf := new(bytes.Buffer)
		err = tmpl.Execute(buf, c)
		if err != nil {
			return nil, err
		}
		parts := strings.Split(filename, ".tmpl")
		if len(parts) <= 1 {
			return nil, fmt.Errorf("invalid template name: %s", filename)
		}
		key := parts[0]
		data[key] = buf.String()
	}
	return data, nil
}
func loadGrafanaTemplates ( c * GrafanaConfig ) ( map [ string ] string , error ) { data := make ( map [ string ] string ) templateDir := filepath . Join ( getGrafanaConfigPath ( ) , " " ) entries , err := ioutil . ReadDir ( templateDir ) if err != nil { return nil , err } for _ , entry := range entries { if entry . IsDir ( ) || ! strings . HasSuffix ( entry . Name ( ) , " " ) { continue } filename := entry . Name ( ) path := filepath . Join ( templateDir , filename ) tmpl , err := template . ParseFiles ( path ) if err != nil { return nil , err } buf := new ( bytes . Buffer ) err = tmpl . Execute ( buf , c ) if err != nil { return nil , err } parts := strings . Split ( filename , " " ) if len ( parts ) <= 1 { return nil , fmt . Errorf ( " " , filename ) } key := parts [ 0 ] data [ key ] = buf . String ( ) } return data , nil }
loadGrafanaTemplates will scan the template directory and parse/execute any files ending with '.tmpl'
loadGrafanaTemplates will scan the template directory and parse / execute any files ending with ' . tmpl '
// Ignore directories and anything that doesn't end with '.tmpl'