kairos-sdk/utils/strings.go
Nianyu Shen 851cc01bc9
accept custom cluster config locations (#153)
* accept custom cluster config locations

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

* use yaml.v3

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

* go mod tidy

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

* added custom root and config flag in cluster properties

* remove ClusterRootPath

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

* go mod tidy

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

---------

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>
Co-authored-by: Piyush Kumar <k17piyush@gmail.com>
2024-08-21 09:35:02 +02:00

32 lines
587 B
Go

package utils
import (
"encoding/json"
"gopkg.in/yaml.v3"
"math/rand"
"strings"
)
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func RandStringRunes(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}
func ListOutput(rels []string, output string) []string {
switch strings.ToLower(output) {
case "yaml":
d, _ := yaml.Marshal(rels)
return []string{string(d)}
case "json":
d, _ := json.Marshal(rels)
return []string{string(d)}
default:
return rels
}
}