You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi everyone. I'm just getting started with the library and it feels like I'm hitting a wall on a pretty simple and core feature... parameter objects. I've set up a parameter struct as in the help docs...
typeServerParamsstruct {
fx.InPortint
}
I have a NewHTTPServer function that requires a port int.
I'm trying to figure out how to simply pass the port parameter to the NewHTTPServer function. It's not clear how invoke knows that I'm invoking NewHTTPServer. It's also not clear to me how to pass the parameter. ChatGPT got me one working method, (the uncommented code above) but it feels wrong to pass it with fx.Supply(port). I tried the commented code with fx.In and also with fx.Provide and I get errors about the missing port.
Eventually I'll be getting this port from a flag using ff and trying to use fx to make that work. I'd like to be able to parse the flags, and then have those values injected into things like server, database, logger, etc. This feels right in line with the problems this library is trying to solve, but after a few hours with the docs I can't find even basic examples of passing parameters in either manually or through fx properly.
I took a stab at better documentation, but I highly doubt it's the right style or the right content.
Appreciate any help or examples. I'll be using echo, sqlite, zerolog, and ff in case that matters... but don't feel like you have to tailor the examples to my stack. Thanks!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi everyone. I'm just getting started with the library and it feels like I'm hitting a wall on a pretty simple and core feature... parameter objects. I've set up a parameter struct as in the help docs...
I have a
NewHTTPServer
function that requires aport int
.Finally, I have the function in main.
I'm trying to figure out how to simply pass the port parameter to the
NewHTTPServer
function. It's not clear how invoke knows that I'm invokingNewHTTPServer
. It's also not clear to me how to pass the parameter. ChatGPT got me one working method, (the uncommented code above) but it feels wrong to pass it withfx.Supply(port)
. I tried the commented code withfx.In
and also withfx.Provide
and I get errors about the missing port.Eventually I'll be getting this port from a flag using ff and trying to use fx to make that work. I'd like to be able to parse the flags, and then have those values injected into things like server, database, logger, etc. This feels right in line with the problems this library is trying to solve, but after a few hours with the docs I can't find even basic examples of passing parameters in either manually or through fx properly.
I took a stab at better documentation, but I highly doubt it's the right style or the right content.
First Attempt
Appreciate any help or examples. I'll be using echo, sqlite, zerolog, and ff in case that matters... but don't feel like you have to tailor the examples to my stack. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions