package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func readJsonFile(filePath string) (jsonBytes []byte, err error) {
|
|
jsonFile, err := os.Open(filePath)
|
|
if err != nil {
|
|
log.Println("Could not open JSON file: " + filePath + "\n" + err.Error())
|
|
return jsonBytes, err
|
|
}
|
|
defer jsonFile.Close()
|
|
fileBytes, _ := ioutil.ReadAll(jsonFile)
|
|
|
|
//strip out // comments from file:
|
|
re := regexp.MustCompile(`([\s]//.*)|(^//.*)`)
|
|
fileCleanedBytes := re.ReplaceAll(fileBytes, nil)
|
|
|
|
return fileCleanedBytes, err
|
|
}
|
|
|
|
func generateUUID() string {
|
|
return strings.Replace(uuid.New().String(), "-", "", -1)
|
|
}
|
|
|
|
func fileExists(filename string) bool {
|
|
info, err := os.Stat(filename)
|
|
if os.IsNotExist(err) {
|
|
return false
|
|
}
|
|
return !info.IsDir()
|
|
}
|
|
|
|
func logit(level int, message string) {
|
|
if appconf.LogLevel >= int(level) {
|
|
log.Println(message)
|
|
}
|
|
if appconf.LogLevel >= 8 {
|
|
fmt.Println(message)
|
|
}
|
|
}
|