How to Make Global Constant Maps and Slices in Goby@wagslane
6,545 reads

How to Make Global Constant Maps and Slices in Go

July 3rd 2020
2m
by @wagslane 6,545 reads
tldt arrow
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

Go developers are pretty good about using constants for global configuration, rather than global variables. When setting configuration globals, which should be read-only, there is no reason to use a global variable. The go compiler doesn't allow complex types like slices and maps to be constant. In this article we will explore a better option to use an initializer function instead of a constant. An initializer is a function that simply declares something and returns it. The better solution to this problem would be as follows: getSupportedNetworks()

People Mentioned

Mention Thumbnail

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - How to Make Global Constant Maps and Slices in Go
Lane Wagner HackerNoon profile picture

@wagslane

Lane Wagner

Founder of Boot.dev. Whining about coding sins since 2011. Committing coding sins for the same.


Receive Stories from @wagslane

react to story with heart

RELATED STORIES

L O A D I N G
. . . comments & more!