I was watching this video where all this guy did was declare a global variable outside his main function and was able to access that anywhere. I'm doing the exact same thing and it's not working. Maybe there is something underlying im missing?
#Access global vars in main from seperate packages?
16 messages · Page 1 of 1 (latest)
im not sure how that guy was able to do it then; what would you suggest instead?
ill look into that, thank you!
Names that start with a capital letter are exported
even with capital it did not work
and in his video it wasnt even capitalized and worked
maybe because all of it is in the same package?
if that's the case you can access it freely
if the whole thing is main you could had accessed global vars from anywhere
but in this case it's all fragmented so you cant
consider creating a struct instead of using package level functions,
where the struct holds the redis client, so by holding the struct you can call struct.func instead
Three Fallacies of Dependencies, https://www.youtube.com/watch?v=yi5A3cK1LNA - Skippy
Dependency Injection, https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/dependency-injection - evandocarmo
DI in http handlers, https://medium.com/@michael_epps/context-less-go-854db3e5510 - Madxmike
Last one here goes over a few ways you can do this