this lib can be used to dynamically inject a dependency from a dynamic lib.
for detail, check out this blog (Chinese)
this lib combines
- golang plugin mechanism
- and a tricky reflection mechanism to implement dynamic dependency injection in golang.
check example code.
we use example/build.sh to build 2 plugins, one is Chinese Greeter and the other is English Greeter.
the both plugins implements Greeter interface.
we can run the main with 2 args.
- first is the
so
file path,./en/so
- second is the package path,
github.com/titanxxh/di/example/en.english
, if your package name is same as your folder name.*github.com/titanxxh/di/example/cn/v1.(cn).Chinese
, if your package name is different from your folder name.