Is there a way to use some `env` values with multi...
# multiplatform
v
Is there a way to use some
env
values with multiplatform? I’ll try to describe my problem: My
api
needs to receive some headers based on application:
platform, version, language.
This info is platform-client dependent. How can I achieve it?
z
Just create expect/actual wrapper?
v
no.. expect-actual is for library code.. i need something to configure it in client code (the app, not the library)
b
epect/actual is for anything, not just libs...
v
my lib can expose expect via swift framework lib? (I think it’s incompatible/impossible)
t
can you just expose an interface and put it as a required param in the constructor for whatever needs those values
or a class/data class that holds those values and then pass the constructed object in
v
@Trevor Stone is DI a good idea to expose the values?
j
Why not expect/actual?
t
It looks like you have a project that will be packaged as a library for more than one consumer
you need information based on which consumer is using the library at the time
so you will either need to build a specific library for each consumer, or you will need to have the consumer provide the information to your library
j
I think you are going to get the same thing using DI or expect/actual
But expect actual should be easier
t
expect/actual is provided at compile time. If you are a library that needs config based on how it is being consumed that needs to be at runtime
🙌 1
I might be misunderstanding @Vitor Prado's request, but it seems like the consumers are in a separate code-base and are the owners of the configuration
b
Use expect actual to hook in native apis for each platform to load those env variables...
🙌 1
j
Then passing a simple data class with the data in a constructor should be enough
v
@Big Chungus good solution. thanks!
@Trevor Stone yeah.. you’re right.. but I think what Martynas said is a good solution. (don’t expose an object/api to client but is a simple solution)
b
Bonus tip - model your expect api after one of the platforms apis. That way you can just typealias the actual on that platform
v
do you have an example?