如何在Golang中的测试中像在String中那样引用变量?

The following works in tests:

if actualKey != expectedKey {
    t.Fatalf("Failed. Actual: %q. Expected: %q", actualKey, expectedKey)
}

In the main code:

m["Keyword "+kw+" found on "+url] = 0

, but this fails:

m["Keyword %q found on %q", kw, url] = 0

As suggested by @JimB fmt.Sprintf could be used. The following works:

msg := fmt.Sprintf("Keyword %q found on %q", kw, url)
m[msg] = 0

Questions

  • Is it correct to call this approach variable referencing? If false, what is it called?
  • Is this the most concise way of implementing it?

I think a better way to do it is by defining a struct type:

type Result struct {
    Keyword, URL string
}

and use it like this:

m := make(map[Result]int)
m[{"keyword1", "url1"}] = 0