### Initializing Userver Application Components in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/dd/dd2/samples_2postgres_service_2postgres_service_8cpp-example.html This `main` function illustrates the setup of a userver application by constructing a `ComponentList`. It includes essential components like `MinimalServerComponentList`, a custom `KeyValue` service, `Postgres` database integration, `TestsuiteSupport`, and a DNS client. The application is then started using `utils::DaemonMain`. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList() .Append() .Append("key-value-database") .Append() .Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Starting userver Postgres Service Sample (Bash) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d4/d31/md_en_2userver_2tutorial_2postgres__service.html This Bash command demonstrates how to start the userver Postgres service sample using the `make start-userver-samples-postgres_service` target. This command leverages the testsuite's start mechanism, which handles configuration paths, database setup, and service initiation automatically. ```bash make start-userver-samples-postgres_service ``` -------------------------------- ### Initializing userver Daemon with DNS Component (C++) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d6/d35/samples_2postgres_auth_2postgres_service_8cpp-example.html This snippet demonstrates how to append a 'clients::dns::Component' to a component list and then start the 'userver' daemon using 'utils::DaemonMain'. It shows the basic setup for a 'userver' application, integrating a caching DNS resolver. ```C++ Append(); return utils::DaemonMain(argc, argv, component_list); ``` -------------------------------- ### Registering userver Components for FlatBuffers Example in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d8/dea/samples_2flatbuf_service_2flatbuf_service_8cpp-example.html The `main` function sets up the userver application by creating a component list. It appends essential components like `MinimalServerComponentList`, `FbsSumEcho`, `clients::dns::Component`, `HttpClient`, and the custom `FbsRequest` component, then starts the daemon. ```C++ int main(int argc, char* argv[]) { auto component_list = components::MinimalServerComponentList() // .Append() // .Append() // .Append() // .Append(); // return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Main Function for userver Daemon (C++) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d9/d85/samples_2websocket_service_2websocket_service_8cpp-example.html This C++ `main` function initializes and runs the userver daemon. It creates a component list starting with `MinimalServerComponentList` and appends the custom `WebsocketsHandler`, then passes this list to `utils::DaemonMain` to start the application, setting up the server for operation. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList() .Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Configuring uServer Components and Starting Daemon (C++) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d9/d90/samples_2tcp_full_duplex_service_2tcp_full_duplex_service_8cpp-example.html This C++ snippet illustrates the process of configuring a uServer application by appending essential components like `clients::dns::Component` for DNS resolution and `components::HttpClient` for HTTP requests. It concludes by showing how to start the main application daemon using `utils::DaemonMain` with the configured component list. ```C++ .Append() .Append(); return utils::DaemonMain(argc, argv, component_list); ``` -------------------------------- ### Initializing userver Application in C++ Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d8/d26/samples_2config_service_2config_service_8cpp-example.html This C++ `main` function initializes a userver application. It constructs a minimal server component list and appends a custom `ConfigDistributor` component, then starts the daemon using `utils::DaemonMain`. This is the entry point for the userver service. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList() .Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Running userver Daemon Main (C++) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/da/de2/samples_2hello_service_2hello_service_8cpp-example.html This C++ snippet defines the `main` function, the entry point of the `userver` application. It constructs a `MinimalServerComponentList`, appends the custom `Hello` handler, and then starts the `userver` daemon using `utils::DaemonMain` with the configured component list. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList().Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Registering Core Components and Starting Daemon in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/db/d69/md_en_2userver_2tutorial_2production__service.html This C++ snippet demonstrates how to register essential components like `Secdist`, `DefaultSecdistProvider`, `Ping` handler, and `alerts::Handler` to a `ComponentList`. It then initializes and starts the userver daemon using `utils::DaemonMain`, passing command-line arguments and the configured component list. This setup is crucial for defining the service's core functionalities and lifecycle. ```cpp .Append() .Append() .Append() .Append() // Put your handlers and components here ; return utils::DaemonMain(argc, argv, component_list); ``` -------------------------------- ### Running userver WebSocket Service as Daemon - C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d9/d85/samples_2websocket_service_2websocket_service_8cpp-example.html This C++ `main` function initializes and runs the `userver` application as a daemon. It creates a component list starting with a minimal HTTP server configuration and appends the custom `WebsocketsHandler` component, then passes this list to `utils::DaemonMain` to start the service. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList() .Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Including userver Framework Headers (C++) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/da/de2/samples_2hello_service_2hello_service_8cpp-example.html This C++ snippet includes essential headers from the `userver` framework. These headers provide necessary components for testing utilities, a minimal HTTP server setup, base classes for HTTP handlers, and functions to run the application as a daemon. ```C++ #include #include #include #include ``` -------------------------------- ### Initializing Userver Application with ConfigDistributor (C++) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d8/d26/samples_2config_service_2config_service_8cpp-example.html This C++ 'main' function initializes a userver application. It creates a minimal server component list and appends a custom 'samples::ConfigDistributor' component, then starts the daemon. This demonstrates how to integrate custom components into the userver framework. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList() .Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Example Usage of HttpHandlerStatic in userver main - C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/dd/d88/classserver_1_1handlers_1_1HttpHandlerStatic.html This C++ example demonstrates how to integrate `server::handlers::HttpHandlerStatic` into a userver application's main function. It appends `HttpHandlerStatic` and `FsCache` components to the minimal server component list, then starts the daemon. This setup allows the server to serve static files using the `HttpHandlerStatic` handler, leveraging `FsCache` for efficient file caching. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList() .Append("fs-cache-main") .Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Running userver-pg Docker Container (Ubuntu 22.04) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d3/da9/md_en_2userver_2tutorial_2build.html This command starts an interactive Docker container based on `ubuntu-22.04-userver-pg:latest`, which includes userver and PostgreSQL preinstalled. It uses `ip6net` for networking and enters the container's bash shell. ```bash docker run --rm -it --network ip6net --entrypoint bash ghcr.io/userver-framework/ubuntu-22.04-userver-pg:latest ``` -------------------------------- ### Initializing userver Multipart Service in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/df/d0f/md_en_2userver_2tutorial_2multipart__service.html This C++ snippet demonstrates the main function setup for a userver service. It initializes a minimal server component list and appends the samples::Multipart component, then starts the daemon using utils::DaemonMain to handle service lifecycle. ```C++ components::MinimalServerComponentList().Append(); return utils::DaemonMain(argc, argv, component_list); ``` -------------------------------- ### Getting Span Start System Time in C++ Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d2/d68/core_2include_2userver_2tracing_2span_8hpp_source.html Retrieves the system clock time point when the span was started. ```C++ std::chrono::system_clock::time_point GetStartSystemTime() const; ``` -------------------------------- ### Get Start System Time of Tracing Span (C++) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d2/d68/core_2include_2userver_2tracing_2span_8hpp_source.html Retrieves the system clock time point when the span was started. This provides the absolute start time of the span's operation. ```C++ std::chrono::system_clock::time_point GetStartSystemTime() const; ``` -------------------------------- ### Starting userver gRPC Middleware Service via Testsuite Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d5/db9/md_en_2userver_2tutorial_2grpc__middleware__service.html This command initiates the userver gRPC middleware service using the testsuite's start target. This method automatically configures necessary paths and starts the service, simplifying the setup for testing. ```Shell make start-userver-samples-grpc_middleware_service ``` -------------------------------- ### Initializing userver Service with Custom Component (C++) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/da/d16/md_en_2userver_2tutorial_2hello__service.html This C++ main function initializes the userver application. It appends the custom 'samples::hello::Hello' component to the minimal server component list, which provides a basic HTTP server setup. The `utils::DaemonMain` function then starts the server, typically loading configuration from a file passed via command line arguments. ```cpp int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList().Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Getting HTTP Request Start Time in C++ Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d2/d45/http__request_8hpp_source.html Returns the start time of the HTTP request as a `std::chrono::steady_clock::time_point`. This can be used for timing and performance monitoring. ```C++ std::chrono::steady_clock::time_point GetStartTime() const; ``` -------------------------------- ### Initializing Doxygen Search and Navigation - JavaScript Source: https://github.com/userver-framework/docs/blob/develop/v2.0/dd/dd2/samples_2postgres_service_2postgres_service_8cpp-example.html This JavaScript snippet sets up the search box, navigation menu, and resizable elements for Doxygen-generated documentation. It initializes the search functionality, configures the main menu, and sets up the navigation tree for the specific C++ example file, improving documentation navigability. ```JavaScript var searchBox = new SearchBox("searchBox", "../../search/",'.html'); $(function() { initMenu('../../',true,false,'search.php','Search'); $(function() { init_search(); }); }); $(function(){initNavTree('dd/dd2/samples_2postgres_service_2postgres_service_8cpp-example.html','../../'); initResizable(); }); ``` -------------------------------- ### Starting userver TCP Full-Duplex Service Sample (Makefile) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/db/db9/md_en_2userver_2tutorial_2tcp__full.html This command starts the TCP full-duplex service sample using a Makefile target. It leverages the testsuite's start mechanism to automatically configure paths and launch the service, simplifying the setup process. ```Bash make start-userver-samples-tcp_full_duplex_service ``` -------------------------------- ### Building and Running Userver Sample Services - Bash Source: https://github.com/userver-framework/docs/blob/develop/v2.0/db/d69/md_en_2userver_2tutorial_2production__service.html This bash script outlines the steps to build and run userver sample services. It first creates a release build directory, configures the project with CMake, then builds and starts a `config_service`. Subsequently, it builds a `production_service`, prepares its configurations using a Python script, and finally runs the production service with a specified static configuration file. ```bash mkdir build_release cd build_release cmake -DCMAKE_BUILD_TYPE=Release .. make userver-samples-config_service ./samples/userver-samples-config_service & make userver-samples-production_service python3 ../samples/tests/prepare_production_configs.py ./samples/userver-samples-production_service --config /tmp/userver/production_service/static_config.yaml ``` -------------------------------- ### Getting Start System Time of Span in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d7/d1a/classtracing_1_1Span.html Retrieves the system clock time point when the span was started. This provides a timestamp for the beginning of the span's execution. ```C++ std::chrono::system_clock::time_point GetStartSystemTime () const ``` -------------------------------- ### Defining userver Service Entry Point and Component List (C++) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d8/d8a/samples_2production_service_2production_service_8cpp-example.html This C++ `main` function defines the entry point for a `userver` service. It constructs a `ComponentList` by appending common components, server components, `Secdist`, `DefaultSecdistProvider`, and a `Ping` handler, then starts the service using `utils::DaemonMain`. ```C++ int main(int argc, char* argv[]) {\nconst auto component_list =\ncomponents::ComponentList()\n.AppendComponentList(components::CommonComponentList())\n.AppendComponentList(components::CommonServerComponentList())\n.Append()\n.Append()\n.Append()\n// Put your handlers and components here\n;\nreturn utils::DaemonMain(argc, argv, component_list);\n} ``` -------------------------------- ### Starting userver PostgreSQL Auth Service via Testsuite (Bash) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/da/d24/md_en_2userver_2tutorial_2auth__postgres.html This Bash command starts the `userver` PostgreSQL authentication service using the testsuite's start target. This method automatically handles configuration, database setup, and service initiation, simplifying the startup process for testing and development. ```Bash make start-userver-samples-postgres_auth ``` -------------------------------- ### Getting Request Start Time in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d2/d45/http__request_8hpp_source.html This method returns a `std::chrono::steady_clock::time_point` representing the time when the HTTP request processing started. It is useful for measuring request latency and performance. ```C++ std::chrono::steady_clock::time_point GetStartTime() const; ``` -------------------------------- ### Configuring Userver Components in C++ Main Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d9/d90/samples_2tcp_full_duplex_service_2tcp_full_duplex_service_8cpp-example.html This `main` function snippet demonstrates how to build a `userver` component list for application startup. It initializes with a minimal server component list and appends essential components like `ServerMonitor`, the `samples::tcp::echo::Echo` component, and testsuite support components. ```C++ int main(int argc, const char* const argv[]) { const auto component_list = [components::MinimalServerComponentList](../../dd/d1c/group__userver__components.html#ga44510c5120b67bd36f0ff9f845c68280 "Returns a list of components to start a basic HTTP server.")() .[Append](../../dc/df0/classcomponents_1_1ComponentList.html#aac1091016f393791732a7da6aaf27f48 "Appends a component with default component name Component::kName.")<[server::handlers::ServerMonitor](../../dc/d10/classserver_1_1handlers_1_1ServerMonitor.html "Handler that returns statistics data.")>() .Append() // Testuite components: .Append<[server::handlers::TestsControl](../../d5/ded/classserver_1_1handlers_1_1TestsControl.html "Handler that allows to control the behavior of server from tests, and functional tests with testsuite...")>() .Append() } ``` -------------------------------- ### Running userver-base Docker Container (Ubuntu 22.04) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d3/da9/md_en_2userver_2tutorial_2build.html This command starts an interactive Docker container using the `ubuntu-22.04-userver-base:latest` image, which includes only the build dependencies for userver. It's suitable for custom installations and development. ```bash docker run --rm -it --network ip6net --entrypoint bash ghcr.io/userver-framework/ubuntu-22.04-userver-base:latest ``` -------------------------------- ### Initializing userver Components for MongoDB Service in C++ Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d0/d43/samples_2mongo_service_2mongo_service_8cpp-example.html This `main` function initializes and runs a userver application. It sets up a component list including essential server components, a DNS resolver, a MongoDB component named 'mongo-tr', and the custom `samples::mongodb::Translations` component, then starts the daemon. ```C++ int main(int argc, char* argv[]) { const auto component_list = [components::MinimalServerComponentList](../../dd/d1c/group__userver__components.html#ga44510c5120b67bd36f0ff9f845c68280 "Returns a list of components to start a basic HTTP server.")() .[Append](../../dc/df0/classcomponents_1_1ComponentList.html#aac1091016f393791732a7da6aaf27f48 "Appends a component with default component name Component::kName.")<[clients::dns::Component](../../d0/d1e/classclients_1_1dns_1_1Component.html "Caching DNS resolver component.")>() .Append("mongo-tr") .Append(); return [utils::DaemonMain](../../d6/d84/namespaceutils.html#a5047c1275f53e699e26869c045ad3697)(argc, argv, component_list); } ``` -------------------------------- ### Configuring userver Components for Redis Service (C++) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d0/d6c/samples_2redis_service_2redis_service_8cpp-example.html This `main` function snippet illustrates the setup of a userver application's component list. It starts with a base `MinimalServerComponentList` and chains `Append` calls to register various components, including custom Redis-related handlers (`KeyValue`, `EvalSha`), security components (`Secdist`, `DefaultSecdistProvider`), the main `Redis` client component, and `TestsuiteSupport` for testing. This defines the service's dependencies and available functionalities. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList() .Append() .Append() .Append() .Append() .Append("key-value-database") .Append(); ``` -------------------------------- ### Initializing Doxygen Navigation and Search - JavaScript Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d8/d26/samples_2config_service_2config_service_8cpp-example.html This jQuery-based snippet initializes the Doxygen navigation menu and search functionality upon document readiness. `initMenu` sets up the navigation tree with specified parameters, while `init_search` prepares the search interface, enabling users to navigate and search the documentation. ```JavaScript $(function() { initMenu('../../',true,false,'search.php','Search'); $(function() { init_search(); }); }); ``` -------------------------------- ### Static Configuration Example for DynamicDebugLog Handler (YAML) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/dd/dea/classserver_1_1handlers_1_1DynamicDebugLog.html This YAML snippet provides an example of static configuration for the `handler-dynamic-debug-log` component. It defines the HTTP path, allowed methods (GET, PUT, DELETE), and the task processor responsible for handling requests to this endpoint. ```YAML handler-dynamic-debug-log: path: /service/log/dynamic-debug method: GET,PUT,DELETE task_processor: monitor-task-processor ``` -------------------------------- ### Initializing userver Components in C++ Main Function Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d8/dea/samples_2flatbuf_service_2flatbuf_service_8cpp-example.html This C++ main function demonstrates how to initialize and run a userver service. It creates a component list, appending necessary components like a minimal HTTP server, a FlatBuffers handler, a DNS client, an HTTP client, and the custom FbsRequest component, then starts the daemon. ```C++ int main(int argc, char* argv[]) { auto component_list = [components::MinimalServerComponentList](../../dd/d1c/group__userver__components.html#ga44510c5120b67bd36f0ff9f845c68280 "Returns a list of components to start a basic HTTP server.")() // .[Append](../../dc/df0/classcomponents_1_1ComponentList.html#aac1091016f393791732a7da6aaf27f48 "Appends a component with default component name Component::kName.")() // .Append() // .[Append](../../dc/df0/classcomponents_1_1ComponentList.html#aac1091016f393791732a7da6aaf27f48 "Appends a component with default component name Component::kName.")<[components::HttpClient](../../dd/d5a/classcomponents_1_1HttpClient.html "Component that manages clients::http::Client.")>() // .Append(); // return [utils::DaemonMain](../../d6/d84/namespaceutils.html#a5047c1275f53e699e26869c045ad3697)(argc, argv, component_list); } ``` -------------------------------- ### Parsing Runtime Configuration Example - C++ Source: https://github.com/userver-framework/docs/blob/develop/v1.0/de/d96/classdynamic__config_1_1Snapshot.html This C++ example demonstrates how to parse a runtime configuration value from a `dynamic_config::DocsMap`. The `ParseRuntimeCfg` function extracts an integer value using `Get` and `As()`. It also shows the definition of a `dynamic_config::Key` for this specific configuration. ```C++ namespace myservice::smth {\n\nnamespace {\n\nint ParseRuntimeCfg(const dynamic_config::DocsMap& docs_map) {\n\nreturn docs_map.Get("SAMPLE_INTEGER_FROM_RUNTIME_CONFIG").As();\n\n}\n\nconstexpr dynamic_config::Key kMyConfig{}; ``` -------------------------------- ### Initializing Doxygen Navigation Tree and Resizable Panels (JavaScript) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/da/de2/samples_2hello_service_2hello_service_8cpp-example.html This JavaScript code initializes the navigation tree and resizable panels within Doxygen-generated documentation. It sets the current navigation tree context to the `hello_service.cpp` example page and enables the resizing functionality for various UI elements. ```JavaScript $(function(){initNavTree('da/de2/samples_2hello_service_2hello_service_8cpp-example.html','../../'); initResizable(); }); ``` -------------------------------- ### Building userver Sample Application with CMake Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d4/d31/md_en_2userver_2tutorial_2postgres__service.html These shell commands outline the standard procedure for building a userver sample application. It involves creating a release build directory, navigating into it, configuring the build with CMake, and compiling the specific sample using Make. ```Bash mkdir build_release cd build_release cmake -DCMAKE_BUILD_TYPE=Release .. make userver-samples-postgres_service ``` -------------------------------- ### Running userver Mongo Service Sample (Bash) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d5/d81/md_en_2userver_2tutorial_2mongo__service.html This snippet provides Bash commands to start the userver mongo service sample. It shows how to use the testsuite's start target for automated setup or how to manually run the service by specifying the path to the static configuration file. ```Bash make start-userver-samples-mongo_service ./samples/mongo_service/userver-samples-mongo_service -c ``` -------------------------------- ### Appending DNS Component and Running Daemon Main (C++) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d6/d35/samples_2postgres_auth_2postgres_service_8cpp-example.html This C++ snippet demonstrates how to append a 'clients::dns::Component' to a 'ComponentList' and then initiate the application's main loop using 'utils::DaemonMain'. It showcases the setup of a userver application's core components and entry point. ```C++ .[Append](../../dc/df0/classcomponents_1_1ComponentList.html#aac1091016f393791732a7da6aaf27f48 "Appends a component with default component name Component::kName.")<[clients::dns::Component](../../d0/d1e/classclients_1_1dns_1_1Component.html "Caching DNS resolver component.")\>(); return [utils::DaemonMain](../../d6/d84/namespaceutils.html#a5047c1275f53e699e26869c045ad3697)(argc, argv, component\_list); ``` -------------------------------- ### Initializing Userver Components in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d3/ddd/samples_2tcp_service_2tcp_service_8cpp-example.html This C++ snippet demonstrates how to initialize a minimal list of userver components and append a custom component (`samples::tcp::Hello`). It then uses `utils::DaemonMain` to start the application with the configured component list. This is typical for setting up a userver service. ```C++ components::MinimalComponentList().Append(); return utils::DaemonMain(argc, argv, component_list); ``` -------------------------------- ### Getting Handler Configuration in HandlerBase C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/dc/d10/classserver_1_1handlers_1_1ServerMonitor.html Returns the configuration of the handler as a constant reference to `HandlerConfig`. ```C++ const HandlerConfig & GetConfig () const ``` -------------------------------- ### Example Configuration for Log Level Handler Source: https://github.com/userver-framework/docs/blob/develop/v2.0/dc/dde/classserver_1_1handlers_1_1OnLogRotate.html This YAML snippet provides a static configuration example for a `handler-log-level` component. It defines the HTTP path (`/service/log-level/{level}`), allowed methods (`GET`, `PUT`), and the task processor (`monitor-task-processor`) responsible for handling requests to control logging levels. ```YAML # yaml handler-log-level: path: /service/log-level/{level} method: GET,PUT task_processor: monitor-task-processor ``` -------------------------------- ### Initializing Doxygen Navigation Tree (JavaScript) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/da/de2/samples_2hello_service_2hello_service_8cpp-example.html This JavaScript snippet initializes the Doxygen navigation tree and resizable panels. It ensures the navigation tree points to the correct example file and that the layout is adjustable for better viewing. ```JavaScript $(document).ready(function(){initNavTree('da/de2/samples_2hello_service_2hello_service_8cpp-example.html','../../'); initResizable(); }); ``` -------------------------------- ### Initializing Doxygen Search and Navigation (JavaScript) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/da/de2/samples_2hello_service_2hello_service_8cpp-example.html This JavaScript code initializes the search box functionality and the navigation menu for Doxygen-generated documentation. It sets up the search path and ensures the search and menu are ready upon document load. ```JavaScript var searchBox = new SearchBox("searchBox", "../../search/",'.html'); $(function() { initMenu('../../',true,false,'search.php','Search'); $(document).ready(function() { init_search(); }); }); ``` -------------------------------- ### Starting Userver Service from Command Line (Bash) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/db/d69/md_en_2userver_2tutorial_2production__service.html This bash command illustrates how to launch a userver-based production service. It executes the compiled service binary, `userver-samples-production_service`, and specifies the path to the static configuration file (`static_config.yaml`) using the `--config` argument. This is the standard method for initiating the service with its defined settings. ```bash ./samples/userver-samples-production_service --config /etc/production_service/static_config.yaml ``` -------------------------------- ### Creating DistLockedTask without Retrying - C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/db/d9d/classdist__lock_1_1DistLockedTask.html This C++ example illustrates `dist_lock::DistLockedTask` configured to not retry on user exceptions or lock loss (`kSingleAttempt`). The task's callback increments a counter and immediately throws an exception. The example verifies that `Get()` throws the expected exception and the counter is incremented only once. ```C++ auto strategy = GetSomeDistLockStrategyForTheSample(); std::atomic counter = 0; dist_lock::DistLockedTask locked_task( "example", [&]() { counter++; throw std::runtime_error("123"); }, strategy, /*default settings*/ {}, dist_lock::DistLockWaitingMode::kWait, dist_lock::DistLockRetryMode::kSingleAttempt); try { locked_task.Get(); FAIL() << "Should have thrown"; } catch (const std::runtime_error& exception) { EXPECT_EQ(exception.what(), std::string("123")); } EXPECT_EQ(counter, 1); ``` -------------------------------- ### Building userver Hello Service with CMake Source: https://github.com/userver-framework/docs/blob/develop/v1.0/da/d16/md_en_2userver_2tutorial_2hello__service.html These Bash commands outline the standard build process for a `userver` sample application. It creates a `build_release` directory, navigates into it, configures the project with CMake for a release build, and then compiles the `userver-samples-hello_service` target using `make`. ```Bash mkdir build_release cd build_release cmake -DCMAKE_BUILD_TYPE=Release .. make userver-samples-hello_service ``` -------------------------------- ### Example Static Configuration for YDB Distributed Lock Source: https://github.com/userver-framework/docs/blob/develop/v2.0/da/d60/classydb_1_1DistLockComponentBase.html This YAML snippet provides an example static configuration for a YDB-based distributed lock component. It defines settings for the database, coordination node, semaphore name, and other operational parameters like initial setup, task processor, and session timeouts. ```YAML sample-dist-lock: # Settings that might be used for a group of related distlock instances database-settings: # The key of the database within ydb component (NOT the actual database path) dbname: sampledb # Name of the coordination node within the database coordination-node: sample-node # Name of the semaphore within the coordination node semaphore-name: sample-lock ``` -------------------------------- ### Initializing Userver Components and Daemon Main in C++ Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d3/ddd/samples_2tcp_service_2tcp_service_8cpp-example.html This snippet demonstrates how to initialize a minimal component list, append a custom component (`samples::tcp::Hello`), and then run the userver application using `utils::DaemonMain`. It sets up the core application lifecycle for a userver service. ```C++ components::MinimalComponentList().Append(); return utils::DaemonMain(argc, argv, component_list); ``` -------------------------------- ### Getting Allowed HTTP Methods in HttpHandlerBase C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/dc/d10/classserver_1_1handlers_1_1ServerMonitor.html Returns a constant reference to a vector of allowed HTTP methods for the handler. ```C++ const std::vector< http::HttpMethod > & GetAllowedMethods () const ``` -------------------------------- ### Getting Handler Name in HttpHandlerBase C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/dc/d10/classserver_1_1handlers_1_1ServerMonitor.html Returns the name of the handler as a constant reference to a `std::string`. This is a virtual method. ```C++ virtual const std::string & HandlerName () const ``` -------------------------------- ### Initializing userver Application Components (C++) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/dd/dd2/samples_2postgres_service_2postgres_service_8cpp-example.html This C++ `main` function initializes the userver application by constructing a `ComponentList`. It appends essential components like `MinimalServerComponentList`, `KeyValue` (a custom component), `Postgres`, `TestsuiteSupport`, and `clients::dns::Component`. The configured component list is then passed to `utils::DaemonMain` to start the application. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList() .Append() .Append("key-value-database") .Append() .Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Example Usage of Percentile Class in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/de/d4a/percentile_8hpp_source.html This C++ example demonstrates how to use the `utils::statistics::Percentile` class for timing statistics. It defines type aliases for `Percentile` and `Timings`, shows how to account for milliseconds, and how to extend statistics using a `utils::statistics::Writer`. This setup allows for precise tracking of execution times. ```C++ using Percentile = utils::statistics::Percentile<500, std::uint32_t, 100, 9>; using Timings = utils::statistics::RecentPeriod; void Account(Percentile& perc, std::chrono::milliseconds ms) { perc.Account(ms.count()); } void ExtendStatistics(utils::statistics::Writer& writer, Timings& timings) { writer["timings"]["1min"] = timings; } ``` -------------------------------- ### Initializing userver Application Components in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d4/d31/md_en_2userver_2tutorial_2postgres__service.html This C++ `main` function demonstrates how to assemble the component list for a userver application. It appends the custom `samples::pg::KeyValue` component, the `components::Postgres` component for database interaction, `components::TestsuiteSupport`, and `clients::dns::Component` to the minimal server component list, then starts the daemon. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList() .Append() .Append("key-value-database") .Append() .Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Getting Server Listening Port (C++) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d9/d55/classugrpc_1_1server_1_1Server.html Returns the port number assigned to the server using `AddListeningPort`. This method is only available after the `Start` method has successfully returned. ```C++ int ugrpc::server::Server::GetPort ( ) const noexcept ``` -------------------------------- ### Building userver Sample Service (Bash) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/da/d16/md_en_2userver_2tutorial_2hello__service.html These Bash commands demonstrate the standard build process for a userver sample service. It involves creating a release build directory, navigating into it, configuring the build with CMake for a Release type, and then compiling the specific 'userver-samples-hello_service' target using Make. ```bash mkdir build_release cd build_release cmake -DCMAKE_BUILD_TYPE=Release .. make userver-samples-hello_service ``` -------------------------------- ### Getting Epoch Time Point in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d7/d4a/datetime_8hpp_source.html This function returns a `std::chrono::system_clock::time_point` representing the start of the Unix epoch (January 1, 1970, 00:00:00 UTC). ```C++ std::chrono::system_clock::time_point Epoch() noexcept; ``` -------------------------------- ### Registering Userver Components and Starting Daemon (C++) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/db/d69/md_en_2userver_2tutorial_2production__service.html This C++ snippet demonstrates how to register various components like Secdist, DefaultSecdistProvider, and Ping handlers to a component_list. It then shows how to start the service using utils::DaemonMain, passing command-line arguments and the configured component list. This is typically found in the main function of a userver service. ```C++ Append() .Append() .Append() // Put your handlers and components here ; return utils::DaemonMain(argc, argv, component_list); ``` -------------------------------- ### Getting Response Generation Time (C++) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d3/d44/classserver_1_1http_1_1HttpRequest.html This C++ member function `GetResponseTime` returns a `std::chrono::duration` representing the timestamp when the HTTP response started being generated. ```C++ std::chrono::duration< double > GetResponseTime () const ``` -------------------------------- ### Getting Request Start Time (C++) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d3/d44/classserver_1_1http_1_1HttpRequest.html This C++ member function `GetRequestTime` returns a `std::chrono::duration` representing the timestamp when the HTTP request was received by the server. ```C++ std::chrono::duration< double > GetRequestTime () const ``` -------------------------------- ### Initializing Doxygen Search and Navigation Menu (JavaScript) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/da/de2/samples_2hello_service_2hello_service_8cpp-example.html This JavaScript snippet sets up the search box and initializes the navigation menu for Doxygen-generated documentation. It creates a `SearchBox` instance and uses jQuery's `$(function())` to ensure the menu and search functionalities are initialized once the DOM is ready. ```JavaScript var searchBox = new SearchBox("searchBox", "../../search/",'.html'); $(function() { initMenu('../../',true,false,'search.php','Search'); $(function() { init_search(); }); }); ``` -------------------------------- ### Getting HTTP Minor Version in C++ Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d3/d44/classserver_1_1http_1_1HttpRequest.html This method returns an `int` representing the minor version of the HTTP protocol used for the request. For example, for HTTP/1.0, it returns `0`. ```C++ int server::http::HttpRequest::GetHttpMinor() const ``` -------------------------------- ### Initializing Doxygen Search and Menu - Documentation UI - JavaScript Source: https://github.com/userver-framework/docs/blob/develop/v1.0/dir_000054_000120.html This snippet sets up the search functionality and the main navigation menu for the Doxygen documentation. It creates a `SearchBox` instance and uses jQuery's `$(function())` to ensure the menu and search initialization functions (`initMenu`, `init_search`) are called once the DOM is ready, providing interactive search and navigation. ```JavaScript var searchBox = new SearchBox("searchBox", "search/",'.html'); $(function() { initMenu('',true,false,'search.php','Search'); $(document).ready(function() { init_search(); }); }); ``` -------------------------------- ### Getting HTTP Major Version in C++ Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d3/d44/classserver_1_1http_1_1HttpRequest.html This method returns an `int` representing the major version of the HTTP protocol used for the request. For example, for HTTP/1.0, it returns `1`. ```C++ int server::http::HttpRequest::GetHttpMajor() const ``` -------------------------------- ### Registering Components and Starting Server (C++) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d6/daa/md_en_2userver_2tutorial_2grpc__service.html This C++ main function demonstrates how to register various components using components::MinimalServerComponentList and Append methods. It then starts the userver daemon by calling utils::DaemonMain with the registered component list. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList() .Append() .Append() .Append() .Append() .Append() .Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Initializing Doxygen Search and Menu in JavaScript Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d8/d26/samples_2config_service_2config_service_8cpp-example.html This JavaScript snippet sets up the search box and initializes the navigation menu for Doxygen-generated documentation. It ensures that the search functionality and menu are ready once the document is loaded. ```JavaScript var searchBox = new SearchBox("searchBox", "../../search/",'.html'); $(function() { initMenu('../../',true,false,'search.php','Search'); $(document).ready(function() { init_search(); }); }); ``` -------------------------------- ### Getting Total PostgreSQL Shard Count in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/df/d08/postgresql_2include_2userver_2storages_2postgres_2component_8hpp_source.html This method returns the total number of shards configured for the PostgreSQL component. It provides information about the sharding setup of the database. ```C++ size_t GetShardCount() const; ``` -------------------------------- ### Getting Default Log Level in HttpHandlerBase C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/dc/d10/classserver_1_1handlers_1_1ServerMonitor.html Returns the default log level for the handler as a constant reference to an optional `logging::Level`. ```C++ const std::optional< logging::Level > & GetLogLevel () const ``` -------------------------------- ### Starting userver gRPC Service Sample via make (Bash) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d6/daa/md_en_2userver_2tutorial_2grpc__service.html This command starts the compiled gRPC service sample using a `make` target. It leverages the `testsuite` start mechanism, which automatically configures necessary paths in the service's configuration files before launching the service. ```Bash make start-userver-samples-grpc_service ``` -------------------------------- ### Getting Formatted External Error Body in HttpHandlerBase C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/dc/d10/classserver_1_1handlers_1_1ServerMonitor.html Generates formatted error data for a custom handler exception. This is a virtual method. ```C++ virtual FormattedErrorData GetFormattedExternalErrorBody (const CustomHandlerException &exc) const ``` -------------------------------- ### Getting Sub-Buffer from FieldBuffer (C++) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d5/d3e/structstorages_1_1postgres_1_1io_1_1FieldBuffer.html Retrieves a sub-buffer from the current `FieldBuffer` starting at a specified `offset` and with an optional `size`. It allows specifying a `BufferCategory` for the new sub-buffer. ```C++ constexpr FieldBuffer GetSubBuffer (std::size_t offset, std::size_t size=npos, BufferCategory cat=BufferCategory::kKeepCategory) const ``` -------------------------------- ### Implementing a Basic HTTP Handler in Userver (C++) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/da/de2/samples_2hello_service_2hello_service_8cpp-example.html This C++ code defines a simple HTTP handler named `Hello` using the `userver` framework. It inherits from `HttpHandlerBase` and overrides `HandleRequestThrow` to return a "Hello world!" string. The `main` function sets up a minimal server component list and runs the daemon, registering the `Hello` handler. ```C++ #include #include #include #include namespace samples::hello { class Hello final : public server::handlers::HttpHandlerBase { public: // `kName` is used as the component name in static config static constexpr std::string_view kName = "handler-hello-sample"; // Component is valid after construction and is able to accept requests using HttpHandlerBase::HttpHandlerBase; std::string HandleRequestThrow( const server::http::HttpRequest&, server::request::RequestContext&) const override { return "Hello world!\n"; } }; } // namespace samples::hello int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList().Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Getting Column Iterator Start (C++) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d4/d01/classstorages_1_1clickhouse_1_1io_1_1columns_1_1UuidRfc4122Column.html This method returns an iterator pointing to the beginning of the column data, allowing for traversal of the elements within the `UuidRfc4122Column`. ```C++ iterator begin () const ``` -------------------------------- ### Initializing userver Application Main Function in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d3/dba/samples_2multipart_service_2service_8cpp-example.html This C++ main function demonstrates the standard way to initialize a userver application. It constructs a component list including a 'samples::Multipart' component and then starts the daemon using `utils::DaemonMain`, passing command-line arguments and the configured component list. ```C++ int main(int argc, char* argv[]) { const auto component_list = components::MinimalServerComponentList().Append(); return utils::DaemonMain(argc, argv, component_list); } ``` -------------------------------- ### Get Modifiable Iterator to RcuMap End Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d0/d1f/classrcu_1_1RcuMap.html Returns a modifiable iterator pointing to the past-the-end element of the map. The keyset for iteration is fixed at the start of the iteration and is not affected by concurrent changes. ```C++ Iterator end(); ``` -------------------------------- ### Building userver Sample in Bash Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d4/d95/md_en_2userver_2tutorial_2config__service.html These Bash commands provide the steps to build the `userver-samples-config_service` project. They guide the user through creating a release build directory, configuring the build with CMake, and compiling the specific sample application. ```Bash mkdir build_release cd build_release cmake -DCMAKE_BUILD_TYPE=Release .. make userver-samples-config_service ``` -------------------------------- ### Building and Running userver Production Service (Bash) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/db/d69/md_en_2userver_2tutorial_2production__service.html This snippet provides a sequence of Bash commands to build and run both the `config_service` and `production_service` components of the userver framework. It includes steps for creating a release build directory, configuring CMake, compiling services, running the config service in the background, preparing production configurations using a Python script, and finally launching the production service with a specified static configuration file. Dependencies include a pre-existing `config_service` and the `userver` framework build system. ```bash mkdir build_release cd build_release cmake -DCMAKE_BUILD_TYPE=Release .. make userver-samples-config_service ./samples/userver-samples-config_service & make userver-samples-production_service python3 ../samples/tests/prepare_production_configs.py ./samples/userver-samples-production_service --config /tmp/userver/production_service/static_config.yaml ``` -------------------------------- ### Get Modifiable Iterator to RcuMap Beginning Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d0/d1f/classrcu_1_1RcuMap.html Returns a modifiable iterator pointing to the first element of the map. The keyset for iteration is fixed at the start of the iteration and is not affected by concurrent changes. ```C++ Iterator begin(); ``` -------------------------------- ### Starting userver Flatbuffer Sample via Testsuite (Bash) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d8/d91/md_en_2userver_2tutorial_2flatbuf__service.html This bash command starts the `userver-samples-flatbuf_service` using the `make start-` target provided by the userver testsuite. This method automatically handles setting up proper paths in configuration files, simplifying the service startup process. ```bash make start-userver-samples-flatbuf_service ``` -------------------------------- ### Get Constant Iterator to RcuMap End Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d0/d1f/classrcu_1_1RcuMap.html Returns a constant iterator pointing to the past-the-end element of the map. The keyset for iteration is fixed at the start of the iteration and is not affected by concurrent changes. ```C++ ConstIterator end() const; ``` -------------------------------- ### Get Constant Iterator to RcuMap Beginning Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d0/d1f/classrcu_1_1RcuMap.html Returns a constant iterator pointing to the first element of the map. The keyset for iteration is fixed at the start of the iteration and is not affected by concurrent changes. ```C++ ConstIterator begin() const; ``` -------------------------------- ### Getting Log Level for Response Status in HttpHandlerBase C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/dc/d10/classserver_1_1handlers_1_1ServerMonitor.html Determines the appropriate logging level for a given HTTP response status. This is a virtual method. ```C++ virtual logging::Level GetLogLevelForResponseStatus (http::HttpStatus status) const ``` -------------------------------- ### Initializing Doxygen Search and Menu (JavaScript) Source: https://github.com/userver-framework/docs/blob/develop/v2.0/da/d9c/samples_2postgres_auth_2schemas_2postgresql_2auth_2migrations_2V001__create_db_8sql-example.html This JavaScript snippet initializes the Doxygen search box and navigation menu functionalities. It sets up the search mechanism and ensures the menu is properly loaded and interactive for navigating the documentation. ```JavaScript var searchBox = new SearchBox("searchBox", "../../search/",'.html'); $(function() { initMenu('../../',true,false,'search.php','Search'); $(function() { init_search(); }); }); ``` -------------------------------- ### Initializing Doxygen Menu and Search (JavaScript) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d8/d8a/samples_2production_service_2production_service_8cpp-example.html This jQuery snippet initializes the navigation menu and the search functionality for Doxygen-generated documentation. It ensures that the menu is set up and the search index is ready once the DOM is loaded. ```JavaScript $(function() { initMenu('../../',true,false,'search.php','Search'); $(document).ready(function() { init_search(); }); }); ``` -------------------------------- ### Initializing Server Components in C++ Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d4/d95/md_en_2userver_2tutorial_2config__service.html This C++ `main` function demonstrates how to initialize and start a userver application. It appends the custom `samples::ConfigDistributor` component to the minimal server component list and then uses `utils::DaemonMain` to run the server. ```C++ const auto component_list = components::MinimalServerComponentList() .Append(); return utils::DaemonMain(argc, argv, component_list); ``` -------------------------------- ### Initializing FbsRequest Component in C++ Source: https://github.com/userver-framework/docs/blob/develop/v2.0/d8/dea/samples_2flatbuf_service_2flatbuf_service_8cpp-example.html This constructor initializes the `FbsRequest` component, inheriting from `LoggableComponentBase`. It retrieves the `HttpClient` from the component context and starts an asynchronous task (`KeepRequesting`) to continuously send requests. ```C++ FbsRequest(const components::ComponentConfig& config, const components::ComponentContext& context) : LoggableComponentBase(config, context), http_client_{ context.FindComponent().GetHttpClient()}, task_{utils::Async("requests", [this]() { KeepRequesting(); })} {} ``` -------------------------------- ### Getting Static Configuration Schema (C++) Source: https://github.com/userver-framework/docs/blob/develop/v1.0/d4/df6/http__handler__base_8hpp_source.html This static method provides the YAML configuration schema for the handler. It allows for validation and documentation of the handler's static configuration parameters, ensuring proper setup. ```C++ static yaml_config::Schema GetStaticConfigSchema(); ```