user3918985
user3918985

Reputation: 4439

Go: multiple keys to single value in map

Is it possible to include an OR operator in the key of a map? Eg.

Go:

var a = map[string]int{
    "A1"|| "B1": 1,
    "A2": 2,
}

Error:

invalid operation: "A1" || "B1" (operator || not defined on string)

Upvotes: 3

Views: 4241

Answers (1)

Evan
Evan

Reputation: 6555

No, you cannot. The grammar is defined at http://golang.org/ref/spec#Composite_literals and does not include this feature. You will have to specify each key distinctly.

Upvotes: 8

Related Questions