userver: Codegen overview
Loading...
Searching...
No Matches
Codegen overview

Developing a good service requires many routine code and types to be written. Sometimes it is handy to define types (and code) in declarative way out-of-code in external contracts and generate types/code from that. It allows one to separate external contracts and business logic, and to define these contracts in language agnostic way.

You may use code generators for the following activity:

userver_embed_file and embedding files

For embedding arbitrary data there is a userver_embed_file CMake function:

userver_embed_file(${PROJECT_NAME}_config NAME static_config_yaml FILEPATH static_config.yaml)
target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_config)

To use the embedded file from C++ just include the generated header and call utils::FindResource() function to get the embedded file contents:

int main(int, char*[]) {
auto component_list = components::MinimalServerComponentList().Append<samples::hello::HelloHandler>();
return utils::DaemonMain(components::InMemoryConfig{utils::FindResource("static_config_yaml")}, component_list);
}