ivanmejiarocha / micro-service

sample micro-service in C++
MIT License
263 stars 129 forks source link

web::json::value::string and endpointURI Errors #19

Closed thisismz closed 9 months ago

thisismz commented 5 years ago

hello when i want to build this project in window 10 with vs2019 i got this error I search alot but cant fix them

Severity Code Description Project File Line Suppression State Error C2248 'web::json::value::string': cannot access private member declared in class 'web::json::value' PonimaServer C:\Users\MahdiMz\source\repos\PonimaServer\microsvc_controller.cpp 46

and this is project code

void MicroserviceController::handleGet(http_request message) {
auto path = requestPath(message);
if (!path.empty()) {
    if (path[0] == "service" && path[1] == "test") {
        auto response = json::value::object();
        response["version"] = json::value::string("0.1.1");
        response["status"] = json::value::string("ready!");
        message.reply(status_codes::OK, response);
    }
}
else {
    message.reply(status_codes::NotFound);
}
}

and else this is endpointURI error

here is project code

  void BasicController::setEndpoint(const std::string & value) {
    uri endpointURI(value);
    uri_builder endpointBuilder;

    endpointBuilder.set_scheme(endpointURI.scheme());
    if (endpointURI.host() == "host_auto_ip4") {
        endpointBuilder.set_host(NetworkUtils::hostIP4());        
    }
    else if (endpointURI.host() == "host_auto_ip6") {
        endpointBuilder.set_host(NetworkUtils::hostIP6());
    }
    endpointBuilder.set_port(endpointURI.port());
    endpointBuilder.set_path(endpointURI.path());

    _listener = http_listener(endpointBuilder.to_uri());
}

and i got this error

Severity Code Description Project File Line Suppression State Error C2678 binary '==': no operator found which takes a left-hand operand of type 'const utility::string_t' (or there is no acceptable conversion) PonimaServer C:\Users\MahdiMz\source\repos\PonimaServer\foundation\basic_controller.cpp 43

Error C2664 'web::uri::uri(const web::uri &)': cannot convert argument 1 from 'const std::string' to 'const utility::char_t *' PonimaServer C:\Users\MahdiMz\source\repos\PonimaServer\foundation\basic_controller.cpp 39

Error C2664 'web::uri_builder &web::uri_builder::set_host(const utility::string_t &,bool)': cannot convert argument 1 from 'std::string' to 'const utility::string_t &' PonimaServer C:\Users\MahdiMz\source\repos\PonimaServer\foundation\basic_controller.cpp 44

your help will makes me happy thanks alot

coldweek commented 5 years ago

Hi, I had a same problem, and I found , for example instead of "service" I am using utility::conversions::to_string_t("service") , so conversion is added for strings.

Regards Adrian.