Код: Выделить всё
"File {file} had error {error}".format(file=myfile, error=err)
Код: Выделить всё
"File %(file)s had error %(error)s" % {"file": myfile, "error": err}
Код: Выделить всё
fmt.Sprintf("File %s had error %s", myfile, err)
Код: Выделить всё
package main
import (
"bytes"
"text/template"
"os"
)
func main() {
type Params struct {
File string
Error string
}
var msg bytes.Buffer
params := &Params{
File: "abc",
Error: "def",
}
tmpl, _ := template.New("errmsg").Parse("File {{.File}} has error {{.Error}}")
tmpl.Execute(&msg, params)
msg.WriteTo(os.Stdout)
}
Подробнее здесь: https://stackoverflow.com/questions/408 ... rmat-in-go