userver: userver/storages/secdist/helpers.hpp Source File
Loading...
Searching...
No Matches
helpers.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/secdist/helpers.hpp
4/// @brief Secdist JSON parsing helper functions
5
6#include <string>
7
8#include <userver/compiler/demangle.hpp>
9#include <userver/formats/json/value.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace storages::secdist {
14
15[[noreturn]] void ThrowInvalidSecdistType(const formats::json::Value& val, std::string_view type);
16
17std::string GetString(const formats::json::Value& parent_val, std::string_view name);
18
19int GetInt(const formats::json::Value& parent_val, std::string_view name, int dflt);
20
21template <typename T>
22T GetValue(const formats::json::Value& parent_val, std::string_view key, const T& dflt) {
23 const auto& val = parent_val[key];
24 try {
25 return val.template As<T>(dflt);
26 } catch (const formats::json::TypeMismatchException&) {
27 ThrowInvalidSecdistType(val, compiler::GetTypeName<T>());
28 }
29}
30
31void CheckIsObject(const formats::json::Value& val, std::string_view name);
32
33void CheckIsArray(const formats::json::Value& val, std::string_view name);
34
35} // namespace storages::secdist
36
37USERVER_NAMESPACE_END