new: api.rest is now on HTTPS (closes #5)

This commit is contained in:
evilsocket 2018-01-08 07:37:29 +01:00
parent be570432ef
commit 47e814c9a9
4 changed files with 143 additions and 12 deletions

View file

@ -2,7 +2,10 @@ package core
import (
"fmt"
"os"
"os/exec"
"os/user"
"path/filepath"
"strings"
)
@ -20,3 +23,26 @@ func Exec(executable string, args []string) (string, error) {
return strings.Trim(string(raw), "\r\n\t "), nil
}
}
func Exists(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return false
}
return true
}
func ExpandPath(path string) (string, error) {
// Check if path is empty
if path != "" {
if strings.HasPrefix(path, "~") {
usr, err := user.Current()
if err != nil {
return "", err
}
// Replace only the first occurence of ~
path = strings.Replace(path, "~", usr.HomeDir, 1)
}
return filepath.Abs(path)
}
return "", nil
}