Skip to content
Snippets Groups Projects
gnmiSubscriptionConfig.go 936 B
Newer Older
  • Learn to ignore specific revisions
  • package config
    
    import (
    	"bufio"
    	"fmt"
    	"os"
    	"path/filepath"
    	"strings"
    )
    
    const (
    	defaultGnmiSubscriptionFilePath = "controller/configs/gNMISubscriptions.txt"
    )
    
    var gnmiSubscriptionPaths [][]string
    
    // ReadGnmiSubscriptionPaths reads the paths the watcher should subscribe to provided in a file.
    func ReadGnmiSubscriptionPaths() error {
    	currentDir, err := os.Getwd()
    	if err != nil {
    		return err
    	}
    
    	filePath := filepath.Join(currentDir, defaultGnmiSubscriptionFilePath)
    
    	f, err := os.Open(filePath)
    	if err != nil {
    		return err
    	}
    
    	defer f.Close()
    
    	scanner := bufio.NewScanner(f)
    
    	for scanner.Scan() {
    		path := strings.Split(scanner.Text(), "/")
    		gnmiSubscriptionPaths = append(gnmiSubscriptionPaths, path)
    	}
    
    	fmt.Println(gnmiSubscriptionPaths)
    
    	return nil
    }
    
    // GetGnmiSubscriptionPaths returns the paths the watcher should subscribe to.
    func GetGnmiSubscriptionPaths() [][]string {
    	return gnmiSubscriptionPaths
    }