@@ -5,8 +5,39 @@ import (
55 "github.com/ankorstore/yokai/log"
66 "github.com/ankorstore/yokai/trace"
77 "github.com/rs/zerolog"
8+ "go.uber.org/fx"
89)
910
11+ // FxExtraInfo is the struct used by modules or apps to provide their extra info to fxcore.
12+ type FxExtraInfo interface {
13+ Name () string
14+ Value () string
15+ }
16+
17+ // fxExtraInfo is the default [FxExtraInfo] implementation.
18+ type fxExtraInfo struct {
19+ name string
20+ value string
21+ }
22+
23+ // NewFxExtraInfo returns a new FxExtraInfo.
24+ func NewFxExtraInfo (name string , value string ) FxExtraInfo {
25+ return & fxExtraInfo {
26+ name : name ,
27+ value : value ,
28+ }
29+ }
30+
31+ // Name returns the name of the [fxExtraInfo].
32+ func (i * fxExtraInfo ) Name () string {
33+ return i .name
34+ }
35+
36+ // Value returns the value of the [fxExtraInfo].
37+ func (i * fxExtraInfo ) Value () string {
38+ return i .value
39+ }
40+
1041// FxModuleInfo is the interface to implement by modules to provide their info to fxcore.
1142type FxModuleInfo interface {
1243 Name () string
@@ -23,36 +54,50 @@ type FxCoreModuleInfo struct {
2354 LogOutput string
2455 TraceProcessor string
2556 TraceSampler string
57+ ExtraInfos map [string ]string
58+ }
59+
60+ // FxCoreModuleInfoParam allows injection of the required dependencies in [NewFxCoreModuleInfo].
61+ type FxCoreModuleInfoParam struct {
62+ fx.In
63+ Config * config.Config
64+ ExtraInfos []FxExtraInfo `group:"core-extra-infos"`
2665}
2766
2867// NewFxCoreModuleInfo returns a new [FxCoreModuleInfo].
29- func NewFxCoreModuleInfo (cfg * config. Config ) * FxCoreModuleInfo {
68+ func NewFxCoreModuleInfo (p FxCoreModuleInfoParam ) * FxCoreModuleInfo {
3069 logLevel , logOutput := "" , ""
31- if cfg .IsTestEnv () {
70+ if p . Config .IsTestEnv () {
3271 logLevel = zerolog .DebugLevel .String ()
3372 logOutput = log .TestOutputWriter .String ()
3473 } else {
35- logLevel = log .FetchLogLevel (cfg .GetString ("modules.log.level" )).String ()
36- logOutput = log .FetchLogOutputWriter (cfg .GetString ("modules.log.output" )).String ()
74+ logLevel = log .FetchLogLevel (p . Config .GetString ("modules.log.level" )).String ()
75+ logOutput = log .FetchLogOutputWriter (p . Config .GetString ("modules.log.output" )).String ()
3776 }
3877
3978 traceProcessor := ""
40- traceSampler := trace .FetchSampler (cfg .GetString ("modules.trace.sampler.type" )).String ()
41- if cfg .IsTestEnv () {
79+ traceSampler := trace .FetchSampler (p . Config .GetString ("modules.trace.sampler.type" )).String ()
80+ if p . Config .IsTestEnv () {
4281 traceProcessor = trace .TestSpanProcessor .String ()
4382 } else {
44- traceProcessor = trace .FetchSpanProcessor (cfg .GetString ("modules.trace.processor.type" )).String ()
83+ traceProcessor = trace .FetchSpanProcessor (p .Config .GetString ("modules.trace.processor.type" )).String ()
84+ }
85+
86+ extraInfos := make (map [string ]string )
87+ for _ , info := range p .ExtraInfos {
88+ extraInfos [info .Name ()] = info .Value ()
4589 }
4690
4791 return & FxCoreModuleInfo {
48- AppName : cfg .AppName (),
49- AppEnv : cfg .AppEnv (),
50- AppDebug : cfg .AppDebug (),
51- AppVersion : cfg .AppVersion (),
92+ AppName : p . Config .AppName (),
93+ AppEnv : p . Config .AppEnv (),
94+ AppDebug : p . Config .AppDebug (),
95+ AppVersion : p . Config .AppVersion (),
5296 LogLevel : logLevel ,
5397 LogOutput : logOutput ,
5498 TraceProcessor : traceProcessor ,
5599 TraceSampler : traceSampler ,
100+ ExtraInfos : extraInfos ,
56101 }
57102}
58103
@@ -78,5 +123,6 @@ func (i *FxCoreModuleInfo) Data() map[string]interface{} {
78123 "processor" : i .TraceProcessor ,
79124 "sampler" : i .TraceSampler ,
80125 },
126+ "extra" : i .ExtraInfos ,
81127 }
82128}
0 commit comments