ludat / conferer

Configuration managment for haskell
https://conferer.ludat.io
Mozilla Public License 2.0
21 stars 4 forks source link

Specification of Generic-based instance of FromConfig #113

Closed debug-ito closed 1 year ago

debug-ito commented 1 year ago

Is there any specification or documents on how the Generic-based instance of FromConfig is implemented? Specifically, what is the mapping between the record field names and Keys?

For example, in the Multiple configs and generics tutorial, FromConfig instance for AppConfig is given by the library based on the Generic.

data AppConfig = AppConfig
  { appConfigWarp :: Warp.Settings
  , appConfigRedis :: Hedis.ConnectionInfo
  , appConfigSecret :: Text
  } deriving (Show, Generic)

instance FromConfig AppConfig

How does that FromConfig instance map the field names to Keys? Does it automatically remove appConfig prefix? If so, can I customize that mapping rule?

In addition, the later part of the tutorial says that server.port key maps to the warp's listening port parameter. However, I cannot understand where the server prefix comes.

ludat commented 1 year ago

On the documentation of Generic instances: sadly it's not documented on the site right now, at least not directly, it's mostly on that page that you mention. You can look at the tests which I think are fairly easy to read but I agree that we should have that documented in the site.

The logic for the field to key transformation is stripping the name of the constructor from the field. so if the field is named MyRecordSomethig and the field is myRecordSomethigField will result in the key field.

NOTES:

On the server.port thing, yes! that's a typo, it should be warp.port. Thanks a lot for pointing that out!

debug-ito commented 1 year ago

Thanks for clarification!