Description
Hi everyone! I've got a Spring Boot config file I'm parsing. Values don't really matter:
server.port: 8000
spring.application.name: some application
spring.datasource.driver-class-name: org.whatever.Driver
spring.datasource.password: some_password
spring.datasource.platform: postgres
spring.datasource.url: jdbc:postgresql:does_not_matter
spring.datasource.username: some_username
spring.jpa.database: POSTGRESQL
some.service.endpoint: http://whatever
some.other.service.endpoint: http://something_else
I'm trying to extract / group different parts of that file, and I'm looking for what the suggested / idiomatic way of doing this is. I'm trying to follow the "data > functions > macros" idiom and the "better 100 functions for one data structure".
Specifically, I'm looking to parse / group the web endpoints, and then the database properties, in order to validate them using some business logic.
I've already parsed the file using java.util.Properties
, so that's not of interest here. The file above is converted to a map.
Solution 1
Create a separate function for each "grouping" I want that parses what I want and returns a new map with just the data I want.
defn get-endpoints [props]
returns
`
{
"some.service.endpoint" "http://whatever",
"some.other.service.endpoint" "http://something_else"
}
`
defn get-database-properties [props]
etc.
Solution 2
Add additional keys to the original map to group what I want.
defn parse-groupings [props]
returns
{
"server.port" "8000",
"spring.application.name" "some application",
"spring.datasource.driver-class-name" "org.whatever.Driver",
;; the rest of the original properties
:groupings {
:web-endpoints {
;; web endpoints go here
},
:database-props {
;; database properties get embedded here
}
}
Solution ???
There's a lot more solutions, of course, but I'm wondering what the community recommends.
Thank you!