func extractMetadataFromFile(metadata string, file string) string {
	line, err := findLineInFile(file, "# "+metadata)
	if err == nil {
		return strings.TrimSpace(strings.Split(line, "# "+metadata)[1])
	}
	log.Errorf("Failed to retrieve %s from file %s", metadata, file)
	return ""
}
Extract metadata information from a script.
Metadata can be added using e.g. # TYPE
package main
import (
	"bufio"
	"errors"
	"fmt"
	"math/rand"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"time"
	log "github.com/sirupsen/logrus"
)
type Check struct {
	Name          string
	File          string
	Interval      int
	Active        bool
	MetricType    string
	Help          string
	metric        interface{}
	resultLast    []map[string]string  
	resultCurrent []map[string]string  
	stoppedchan   chan struct{}
	Offset        int64
	Nextrun       int64
	Success       int
}
const metaActive = "ACTIVE"
const metaType = "TYPE"
const metaHelp = "HELP"
const metaInterval = "INTERVAL"
func (app *application) buildMetrics() {
	for k := range app.checkList {
		delete(app.checkList, k)
	}
	err := filepath.Walk(app.scriptBase, func(path string, info os.FileInfo, err error) error {
		if info != nil && !info.IsDir() {
			if !strings.Contains(path, "..") {
				active, _ := strconv.ParseBool(extractMetadataFromFile(metaActive, path))
				interval, _ := strconv.Atoi(extractMetadataFromFile(metaInterval, path))
				offset := int64(rand.Intn(interval - 1))  
				check := &Check{
					Name:          app.metricsPrefix + "_" + strings.Split(info.Name(), ".")[0],  
					File:          path,
					Interval:      interval,
					Active:        active,
					MetricType:    extractMetadataFromFile(metaType, path),
					Help:          extractMetadataFromFile(metaHelp, path),
					resultLast:    []map[string]string{},
					resultCurrent: []map[string]string{},
					stoppedchan:   make(chan struct{}),
					Offset:        offset,
					Nextrun:       time.Now().Unix() + offset,
					Success:       -1,  
				}
				app.checkList[check.Name] = check
				log.Infof("Add check %s and schedule first run for %s", check.Name, time.Unix(check.Nextrun, 0))
				log.Debugf("Check details: %s", check.String())
			}
		}
		return nil
	})
	if err != nil {
		log.Errorf("Failed to read the scripts: %v", err)
	}
}