How do routers implement spanning trees ? Is there any Golang version?

For the IP protocol, each router/swtich in a network needs to have a spanning tree of the whole graph of that network.

Any idea how this spanning tree is computed ? Is it a distributed computation ?