Answer the question
In order to leave comments, you need to log in
How in GO to beat the moment with the creation of a global constant []string / map[string]string?
Good day.
I just took up GO, so I would like to know how to properly beat this moment in the GO way style t.s.
The Golang spec says that constants can only be - "numbers, strings or Booleans".
Then tell me how to do this option:
package main
...
const (
...
SOME_PARAMS = []string {"param1", "param2"}
// либо
SOME_PARAMS = map[string]string {
"key1": "val1",
"key2": "val2",
}
)
...
func main() {
}
Answer the question
In order to leave comments, you need to log in
Slice and map are dynamic by definition, i.e. operate on the heap unless the compiler optimizes them. They cannot be constants, the creators have about the same ideology.
And you can create without just using PS instead of slice init()
in your code
To use a regular array instead of slice (our speed is everything), then writeconst
var
[...]string {"param1", "param2"}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question