I am sort of new to golang, and also kind of new to programming. And go has been very hard for me. This is one thing that always confuses me: data types. If you run this(not on the playground) then it will spit out:
./main.go:40: cannot use recorded (type string) as type SVC in append
and if I reverse the values in the append call, it will spit out:
./main.go:40: first argument to append must be slice; have string
What I am trying to do is grab all of the stuff in the home directory, append all of the values with the modifications to an array, then put the array into a file using ioutil. All I want(as of now) is to append the values to the slice in func record. Can anybody help?
package main
import "os"
import "io/ioutil"
import "fmt"
type SVC struct {
key string
val string
}
func main() {
os.Chdir("../../../../../../..")
var data, err = ioutil.ReadDir("home")
checkerr(err)
for _, data := range data {
fmt.Println(data.Name())
}
os.Chdir("home/beanboybunny/repos/bux/go/src/bux")
}
func checkerr(err1 error) {
if err1 != nil {
fmt.Println("error")
}
}
func writer(dataname string) {
f := "var "
uname := dataname
q := " = VVC{
"
w := " bux: 1,
"
e := " op: true,
"
c := "}"
b2 := f + uname + q + w + e + c
record(b2)
}
func record(recorded string) {
cache := []SVC{}
record SVC := recorded
appenda := append(cache, recorded)
}