执行:在循环中附加字节片[重复]

This question already has an answer here:

I'm new to Go, so I apologise if this has already been answered, I'm trying to append a byte slice in Go and I am not having any luck finding a solution. I need to split off the first line of the file, which I've done; And write the rest into a byte slice to be parsed after the fact. So far the code looks like this:

// Here we extract the first line to name our title and category
var title, category string
var content []byte
in, err := os.Open(file)
utils.CheckErr(err, "could not open file: "+file)
defer in.Close()
// open file
scanner := bufio.NewScanner(in)
lineCount := 1
for scanner.Scan() {
    if lineCount == 1 {
        // assign title and category
        splitString := strings.Split(scanner.Text(), "::")
        title = splitString[0]
        category = splitString[1]
        fmt.Println("title: " + title + "category" + category) // usage to prevent compiler whine
    } else {
        // push the rest into an array to be parsed as jade
        line := scanner.Bytes()
        content = append(content, line) // The question is what goes here?
    }
    lineCount++
}

I've tried using append but that only gives me the error that cannot use line (type []byte) as type byte in append

</div>

I believe you're simply looking for; content = append(content, line...)

See https://golang.org/ref/spec#Appending_and_copying_slices

There is probably a duplicate but until I find it...

Your problem is solved by adding "..." to the end of line so it looks like:

content = append(content, line...)