template / files / internal / core / utils.go
utils.go
| 1 | package core |
| 2 | |
| 3 | import ( |
| 4 | "os/user" |
| 5 | "path/filepath" |
| 6 | "strings" |
| 7 | |
| 8 | "gopkg.in/yaml.v3" |
| 9 | ) |
| 10 | |
| 11 | func 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 | |
| 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 | } |