合并常见的前缀子字符串

I have a stream of messages entering a Go channel, most of which look like:

T: added package to graph: acl-devel/2.2.52_4/armv6l-musl T: added package to graph: rofs-filtered/1.7_1/x86_64-musl T: added package to graph: rofs-filtered/1.7_1/HOST T: added package to graph: libshout/2.4.1_1/i686 T: added package to graph: mate-terminal/1.18.1_1/armv6l T: added package to graph: bullet-devel/2.86.1_1/x86_64-musl T: added package to graph: bullet-devel/2.86.1_1/HOST T: added package to graph: cubietruck-uboot/2016.11_1/armv6l-musl T: added package to graph: libfontenc/1.1.3_1/i686-musl T: added package to graph: apk-tools/2.8.1_1/x86_64 T: added package to graph: virtualbox-ose/5.1.28_1/armv7l-musl T: added package to graph: acl-devel/2.2.52_4/armv7l T: added package to graph: apk-tools/2.8.1_1/x86_64-musl T: added package to graph: tzutils/2017c_1/x86_64-musl T: added package to graph: python-argh/0.26.2_1/noarch T: added package to graph: tzutils/2017c_1/HOST

I wish to be able to efficiently combine the above strings, line by line, but lose no information. This is for printing to an IRC channel, so I don't want to trigger flood warnings. To do that, I want to massage the above to be similar to the below:

T: added package to graph: rofs-filtered/1.7_1/{x86_64-musl,HOST} T: added package to graph: libshout/2.4.1_1/i686 T: added package to graph: mate-terminal/1.18.1_1/armv6l T: added package to graph: bullet-devel/2.86.1_1/{x86_64-musl,HOST} T: added package to graph: cubietruck-uboot/2016.11_1/armv6l-musl T: added package to graph: libfontenc/1.1.3_1/i686-musl T: added package to graph: apk-tools/2.8.1_1/{x86_64,x86_64-musl} T: added package to graph: virtualbox-ose/5.1.28_1/armv7l-musl T: added package to graph: acl-devel/2.2.52_4/{armv6l-musl,armv7l} T: added package to graph: tzutils/2017c_1/{x86_64-musl,HOST} T: added package to graph: python-argh/0.26.2_1/noarch

While still a lot of output and messages, the bulk of the reporting is about 10-12 lines with common prefixes as above, interspersed with the output of multiple threads doing the above (hence the low number of duplicates in the above data, lots of threads and the data is a snapshot of about 2 seconds).

How might I condense multiple lines to join along their common prefix in Go?

Here's one possible solution. You can check for duplicates before the append() command if you need to.

https://play.golang.org/p/XodCgl1fa5

package main

import (
    "bufio"
    "fmt"
    "strings"
)

func main() {
    input := `T: added package to graph: acl-devel/2.2.52_4/armv6l-musl
T: added package to graph: rofs-filtered/1.7_1/x86_64-musl
T: added package to graph: rofs-filtered/1.7_1/HOST
T: added package to graph: libshout/2.4.1_1/i686
T: added package to graph: mate-terminal/1.18.1_1/armv6l
T: added package to graph: bullet-devel/2.86.1_1/x86_64-musl
T: added package to graph: bullet-devel/2.86.1_1/HOST
T: added package to graph: cubietruck-uboot/2016.11_1/armv6l-musl`

    m := make(map[string][]string)
    s := bufio.NewScanner(strings.NewReader(input))
    for s.Scan() {
        t := s.Text()
        i := strings.LastIndex(t, "/")
        p := t[:i+1]
        last := t[i+1 : len(t)]
        m[p] = append(m[p], last)
    }
    for k, v := range m {
        fmt.Print(k, "{", strings.Join(v, ","), "}", "
")
    }
}