-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
39 lines (32 loc) · 777 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
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 {
kv := strings.Split(line, "=")
parameter := strings.TrimSpace(kv[0])
value := strings.TrimSpace(kv[1])
m[parameter] = value
}
}
if err := scanner.Err(); err != nil {
fmt.Fprintf(os.Stderr, "Failed to read file: %s", err)
os.Exit(1)
}
return m
}