From a457621e444b4e0719c076a172a62d823616a122 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 7 Feb 2024 19:14:47 +0100 Subject: wip --- go/util/util.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 go/util/util.go (limited to 'go/util') diff --git a/go/util/util.go b/go/util/util.go new file mode 100644 index 0000000..d56f662 --- /dev/null +++ b/go/util/util.go @@ -0,0 +1,41 @@ +package util + +import ( + "bufio" + "fmt" + "os" + "strings" + + "github.com/confluentinc/confluent-kafka-go/v2/kafka" +) + +func ReadConfig(configFile string) kafka.ConfigMap { + m := make(map[string]kafka.ConfigValue) + + file, err := os.Open(configFile) + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to open file: %s", err) + os.Exit(1) + } + defer file.Close() + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + if !strings.HasPrefix(line, "#") && len(line) != 0 { + before, after, found := strings.Cut(line, "=") + if found { + parameter := strings.TrimSpace(before) + value := strings.TrimSpace(after) + m[parameter] = value + } + } + } + + if err := scanner.Err(); err != nil { + fmt.Printf("Failed to read file: %s", err) + os.Exit(1) + } + + return m +} -- cgit v1.2.3