MCPcopy Create free account
hub / github.com/DoNewsCode/core / provideFactory

Function provideFactory

ots3/dependency.go:67–103  ·  view source on GitHub ↗

provideFactory creates *Factory and *ots3.Manager. It is a valid dependency for package core.

(option *providersOption)

Source from the content-addressed store, hash-verified

65
66// provideFactory creates *Factory and *ots3.Manager. It is a valid dependency for package core.
67func provideFactory(option *providersOption) func(p factoryIn) Factory {
68 if option.ctor == nil {
69 option.ctor = newManager
70 }
71 return func(p factoryIn) Factory {
72 factory := di.NewFactory(func(name string) (di.Pair, error) {
73 var conf S3Config
74
75 if err := p.Conf.Unmarshal(fmt.Sprintf("s3.%s", name), &conf); err != nil {
76 if name != "default" {
77 return di.Pair{}, fmt.Errorf("s3 configuration %s not found", name)
78 }
79 conf = S3Config{}
80 }
81
82 manager, err := option.ctor(ManagerArgs{
83 Name: name,
84 Conf: conf,
85 Populator: p.Populator,
86 })
87 if err != nil {
88 return di.Pair{}, fmt.Errorf("error constructing manager: %w", err)
89 }
90 return di.Pair{
91 Closer: nil,
92 Conn: manager,
93 }, nil
94 })
95
96 s3Factory := Factory{factory}
97 if option.reloadable {
98 s3Factory.SubscribeReloadEventFrom(p.Dispatcher)
99 }
100
101 return s3Factory
102 }
103}
104
105// ManagerArgs are arguments for constructing the s3 manager. When providing custom constructors, take this as input.
106type ManagerArgs struct {

Callers 3

ProvidersFunction · 0.70

Calls 4

NewFactoryFunction · 0.92
UnmarshalMethod · 0.65
SprintfMethod · 0.65