I’ve the following structure which I created manually the values like app service runner etc
func Cmr(mPath string) [][]string {
cav := [][]string{
{mPath, "app", "app2"},
{mPath, "service"},
{mPath, "runner1", "runner2", "runner3"},
}
return cav
}
Now I need from this input to create this struct, I mean to return the same structure ‘cav`
Now I’ve other function which returns array of string name cmdList
each line have a space delimiter between values like app app2 appN
0 = app app2
1 = service
2 = runner1 runner2 runner3
How can I take the above array of string and put it as parameter to the function Cmr
And remove the hard-coded value and get them from the cmdList instead of hard-coded them...
Like
func Cmr(mPath string,cmdList []string) [][]string {
cav := [][]string{
{mPath, cmdList[0], "app2"},
{mPath, "service"},
{mPath, "runner1", "runner2", "runner3"},
}
return cav
}
update
at the end it should be something like this except the I dont know how to split the entry of the cmdList with the space delimiter
func Cmr(mPath string, cmdList []string) [][]string {
cav := [][]string{}
cav = append(cav, append([]string{mPath}, cmdList[0]))
cav = append(cav, append([]string{mPath}, cmdList[1]))
cav = append(cav, append([]string{mPath}, cmdList[2]))
return cav
}
This will create something like (since Im not handling the space delimiter)
cav := [][]string{
{mPath, "app app2"},
{mPath, "service"},
{mPath, "runner1 runner2 runner3"},
}
But I need
cav := [][]string{
{mPath, "app", "app2"},
{mPath, "service"},
{mPath, "runner1", "runner2", "runner3"},
}