-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparse_config.go
58 lines (51 loc) · 1.59 KB
/
parse_config.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"bufio"
"os"
"strings"
"log"
"regexp"
)
func parse_config(config string) (string, string, string, string) {
var cfglines []string
var cfgrecord []string
var cfgvalues []string
var s string
var u string
var p string
var connect []string
file, err := os.Open(config)
if err != nil {
log.Fatal(err)
}
defer file.Close()
parser:= bufio.NewScanner(file)
for parser.Scan() {
matched, _ := regexp.MatchString("#.*", parser.Text())
if (matched) {
continue
}
cfglines = append(cfglines, parser.Text())
}
for f := 0; f <= (len(cfglines)-1); f++ {
cfgrecord = strings.SplitN(cfglines[f], ":", -1)
cfgvalues = append(cfgvalues, cfgrecord[1])
}
s = strings.Replace(cfgvalues[0], " ", "", -1)
u = strings.Replace(cfgvalues[1], " ", "", -1)
p = strings.Replace(cfgvalues[2], " ", "", -1)
if (debug) {
fmt.Println(s,"\n",u,"\n",p,"\n")
}
file.Close()
connect = []string{u,p}
constring := strings.Join(connect,":")
more := []string{constring,s}
constring = strings.Join(more,"@tcp(")
constring = (constring+")/kea?tls=true")
//if (debug) {
// fmt.Println("In parse_config() function!!",constring)
//}
return s, u, p, constring
}