Refactored, reorganized, fixed issues, and implemented functionality

This commit is contained in:
David Allen 2024-02-24 00:26:51 -07:00
parent 3edc5e1191
commit 5428085fdf
No known key found for this signature in database
GPG key ID: 1D2A29322FBB6FCB
9 changed files with 524 additions and 190 deletions

View file

@ -8,6 +8,8 @@ import (
"os/exec"
"runtime"
"strings"
"github.com/golang-jwt/jwt"
)
func RandomString(n int) string {
@ -50,6 +52,17 @@ func EncodeBase64(s string) string {
return base64.StdEncoding.EncodeToString([]byte(s))
}
func DecodeJwt(encoded string) ([][]byte, error) {
// split the string into 3 segments and decode
segments := strings.Split(encoded, ".")
decoded := [][]byte{}
for _, segment := range segments {
bytes, _ := jwt.DecodeSegment(segment)
decoded = append(decoded, bytes)
}
return decoded, nil
}
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
@ -79,3 +92,11 @@ func OpenUrl(url string) error {
args = append(args, url)
return exec.Command(cmd, args...).Start()
}
func GetCommit() string {
bytes, err := exec.Command("git", "rev --parse HEAD").Output()
if err != nil {
return ""
}
return string(bytes)
}