I've got a common project and small projects which act such as connectors in the common project.
I want to create a common project such that when a new connector is developed I don’t have to modify code in the common project. Is it possible to dynamically load the structures in Go, only knowing the path (by putting this path in a file in common project and at runtime load that struct) of the struct and its folders?
connector1
connector1.go
/util
/domain
connectorN
connectorN.go
/domain
commonProject
main.go
config.ini
Structure config.ini
Conector
name = connector1
path = ..../connector1/connector1.go
Conector
name = connectorN
path = ..../connectorN/connectorN.go
I know that this is possible to do this in Java with code like this, but I am trying to do this in Go. Any ideas?
Class.forName(String)
or
ClassLoader.loadClass(String):
I can see two ways to achieve what you describe, but keep in mind, as @icza pointed out, that go produces static binaries, so you can't load external libraries dynamically.
You can, however:
cgonet/rpc
这篇关于在Golang中动态加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!