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

How to Make Global Constant Maps and Slices in Go

by Lane Wagner2mJuly 3rd, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

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
Lane Wagner

Lane Wagner

@wagslane

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

About @wagslane
LEARN MORE ABOUT @WAGSLANE'S
EXPERTISE AND PLACE ON THE INTERNET.

Share Your Thoughts

About Author

Lane Wagner HackerNoon profile picture
Lane Wagner@wagslane
Founder of Boot.dev. Whining about coding sins since 2011. Committing coding sins for the same.

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Also published here
L O A D I N G
. . . comments & more!