I am trying to declare to constant in Go, but it is throwing an error. Could anyone please help me with the syntax of declaring a constant in Go?
This is my code:
Your syntax is incorrect. To make a literal map (as a pseudo-constant), you can do:
var romanNumeralDict = map[int]string{
1000: "M",
900 : "CM",
500 : "D",
400 : "CD",
100 : "C",
90 : "XC",
50 : "L",
40 : "XL",
10 : "X",
9 : "IX",
5 : "V",
4 : "IV",
1 : "I",
}
Inside a func
you can declare it like:
romanNumeralDict := map[int]string{
...
And in Go there is no such thing as a constant map. More information can be found here.
Try it out on the Go playground.