go-cert-gen/pkg/util/path.go

31 lines
506 B
Go
Raw Normal View History

2023-02-15 18:13:58 +01:00
package util
import (
"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
}
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
}