diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2024-02-07 11:20:43 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2024-02-07 11:20:43 +0100 |
commit | fc9414a56dbcbf7956e1c6fdf7bd7b4a5df2be15 (patch) | |
tree | dcd8ddb7e32183ee3d0f52e0110c75b182f0bc1f /util | |
download | kafka-sandbox-fc9414a56dbcbf7956e1c6fdf7bd7b4a5df2be15.tar.gz kafka-sandbox-fc9414a56dbcbf7956e1c6fdf7bd7b4a5df2be15.tar.bz2 kafka-sandbox-fc9414a56dbcbf7956e1c6fdf7bd7b4a5df2be15.tar.xz kafka-sandbox-fc9414a56dbcbf7956e1c6fdf7bd7b4a5df2be15.zip |
wip
Diffstat (limited to 'util')
-rw-r--r-- | util/util.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/util/util.go b/util/util.go new file mode 100644 index 0000000..57c8246 --- /dev/null +++ b/util/util.go @@ -0,0 +1,43 @@ +package util + +import ( + "bufio" + "fmt" + "os" + "strings" + + "github.com/confluentinc/confluent-kafka-go/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 + +} |