3 ms·
Uh no. You would typically retrieve the data in a function and assign it to a variable scoped to the function. The struct or array then gets passed through a pi
by curioussavage 2y ago
Uh no. You would typically retrieve the data in a function and assign it to a variable scoped to the function. The struct or array then gets passed through a pipeline of functions to do something possibly writing the data back to disk or the db.
Even if there is some data I want to keep in memory there is no need for a global usually. In go I may just keep it in a var in a goroutine that doesn’t exit until the process does.
- interlocutor 2y agoIn go you mix state with logic (example below), which apparently is a "major catastrophe" according to some on this thread. type Engine struct { HorsePower int } func (e Engine) Start() { fmt.Println("Engine is starting with", e.HorsePower, "horsepower.") }