2023-02-15 18:13:58 +01:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2023-02-15 19:30:05 +01:00
|
|
|
"bytes"
|
|
|
|
"encoding/gob"
|
2023-02-15 18:13:58 +01:00
|
|
|
"log"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RootDir() string {
|
|
|
|
cmdOut, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("exec.Command: %s", err)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
rootDir := strings.TrimSpace(string(cmdOut))
|
|
|
|
return rootDir
|
|
|
|
}
|
2023-02-15 19:30:05 +01:00
|
|
|
|
|
|
|
func GetBytes(key interface{}) ([]byte, error) {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
enc := gob.NewEncoder(&buf)
|
|
|
|
err := enc.Encode(key)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return buf.Bytes(), nil
|
|
|
|
}
|