template / windows / files / utils.go
Branch windows · default branch · all branches
utils.go
4a7361b0 2022-09-21 Pavel Safronov | 1 | package main |
| 2 | ||
| 3 | import ( | |
319b8b3f 2022-09-22 Pavel Safronov | 4 | "os/user" |
| 5 | "path/filepath" | |
| 6 | "strings" | |
e86c26ae 2022-11-02 Pavel Safronov | 7 | |
| 8 | "gopkg.in/yaml.v3" | |
4a7361b0 2022-09-21 Pavel Safronov | 9 | ) |
| 10 | ||
05f9e8ef 2022-10-06 Pavel Safronov | 11 | func getFullPath(path string, usr user.User) string { |
319b8b3f 2022-09-22 Pavel Safronov | 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 | } | |
05f9e8ef 2022-10-06 Pavel Safronov | 21 | return newPath |
319b8b3f 2022-09-22 Pavel Safronov | 22 | } |
e86c26ae 2022-11-02 Pavel Safronov | 23 | |
| 24 | func 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 | } |