fuzzyworld

template / ci-testing / files / utils.go

Branch ci-testing · default branch · all branches

utils.go

Blame: the commit that last changed each line · file · history

4a7361b0 2022-09-21 Pavel Safronov1package main
2
3import (
319b8b3f 2022-09-22 Pavel Safronov4 "os/user"
5 "path/filepath"
6 "strings"
e86c26ae 2022-11-02 Pavel Safronov7
8 "gopkg.in/yaml.v3"
4a7361b0 2022-09-21 Pavel Safronov9)
10
05f9e8ef 2022-10-06 Pavel Safronov11func getFullPath(path string, usr user.User) string {
319b8b3f 2022-09-22 Pavel Safronov12 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 Safronov21 return newPath
319b8b3f 2022-09-22 Pavel Safronov22}
e86c26ae 2022-11-02 Pavel Safronov23
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}