How best to construct bytes.Buffer gradually? with fmt.Fprint?This is my code:```func getReqAddons(r Request) string {ret := ""if len(r.RequestPlugins.RequestPlugin) != 0 {for _, v := range r.RequestPlugins.RequestPlugin {ret += fmt.Sprintf(" R: (%s) %s\n", v.Name, minify(v.RuleParameters.Xml))}}if len(r.ExtractionRules.ExtractionRule) != 0 {for _, v := range r.ExtractionRules.ExtractionRule {ret += fmt.Sprintf(" E: (%s: %s) %s\n", v.Name, v.VariableName, minify(v.RuleParameters.Xml))}}if len(r.ValidationRules.ValidationRule) != 0 {for _, v := range r.ValidationRules.ValidationRule {ret += fmt.Sprintf(" V: (%s) %s\n", v.Name, minify(v.RuleParameters.Xml))}}return ret + "\n"}```This is still not efficient right?Having read that in Go, string is a primitive type, it's readonly, every manipulation to it will create a new string, I want to change above to something efficient, and learnt that bytes.Buffer (and fmt.Fprint) should be the way to go,
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
How best to construct bytes.Buffer gradually? with fmt.Fprint?This is my code:
-j
How best to construct bytes.Buffer gradually? with fmt.Fprint?