How to Make Global Constant Maps and Slices in Go

Written by wagslane | Published 2020/07/03
Tech Story Tags: golang | programming | tutorial | constants | globals | go | initialization | global-constant-maps

TLDR 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()via the TL;DR App

no story

Written by wagslane | Founder of Boot.dev. Whining about coding sins since 2011. Committing coding sins for the same.
Published by HackerNoon on 2020/07/03