fuzzyworld

template / windows / files / utils.go

Branch windows · default branch · all branches

utils.go

494 B · history · blame

1package main
2
3import (
4 "os/user"
5 "path/filepath"
6 "strings"
7
8 "gopkg.in/yaml.v3"
9)
10
11func getFullPath(path string, usr user.User) string {
12 dir := usr.HomeDir
13 var newPath string
14 if path == "~" {
15 newPath = dir
16 } else if strings.HasPrefix(path, "~/") {
17 newPath = filepath.Join(dir, path[2:])
18 } else {
19 newPath = path
20 }
21 return newPath
22}
23
24func getYaml(data interface{}) (string, error) {
25 yaml, err := yaml.Marshal(data)
26 if err != nil {
27 return "", err
28 }
29 return string(yaml), nil
30}