parent
b333ed9208
commit
c84446ba7f
|
@ -1,6 +1,7 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -80,6 +81,7 @@ func validPort(port string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadConfigFile takes two argument: folder and fileName.
|
// ReadConfigFile takes two argument: folder and fileName.
|
||||||
|
// Create if not exist
|
||||||
// It reads its content, trims\n and \r, and return []byte
|
// It reads its content, trims\n and \r, and return []byte
|
||||||
// All errors are Fatal.
|
// All errors are Fatal.
|
||||||
func ReadConfigFile(folder string, fileName string) []byte {
|
func ReadConfigFile(folder string, fileName string) []byte {
|
||||||
|
@ -103,3 +105,25 @@ func ReadConfigFile(folder string, fileName string) []byte {
|
||||||
r := bytes.TrimSuffix(data[:count], []byte("\n"))
|
r := bytes.TrimSuffix(data[:count], []byte("\n"))
|
||||||
return bytes.TrimSuffix(r, []byte("\r"))
|
return bytes.TrimSuffix(r, []byte("\r"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadConfigFileLines takes two argument: folder and fileName.
|
||||||
|
// It reads its content line by line, trims\n and \r,
|
||||||
|
// and return [][]byte
|
||||||
|
// All errors are Fatal.
|
||||||
|
func ReadConfigFileLines(folder string, fileName string) [][]byte {
|
||||||
|
res := [][]byte{}
|
||||||
|
f, err := os.Open(folder+"/"+fileName)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
for scanner.Scan() {
|
||||||
|
res = append(res, []byte(scanner.Text()))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue