Coder Social home page Coder Social logo

Comments (2)

yulidai avatar yulidai commented on June 11, 2024

@jimmycuadra Or just add members::leader(&client) for getting leader, url is /v2/members/leader

from rust-etcd.

yulidai avatar yulidai commented on June 11, 2024

I solved it by adding this function into member.rs :)

/// Leader of members
///
/// # Parameters
///
/// * client: A `Client` to use to make the API call.
pub fn leader<C>(
    client: &Client<C>,
) -> impl Future<Item = Response<Member>, Error = Vec<Error>> + Send
    where
        C: Clone + Connect,
{
    let http_client = client.http_client().clone();

    first_ok(client.endpoints().to_vec(), move |member| {
        let url = build_url(member, "/leader");
        let uri = Uri::from_str(url.as_str())
            .map_err(Error::from)
            .into_future();

        println!("uri: {:?}", uri);
        let http_client = http_client.clone();

        let response = uri.and_then(move |uri| http_client.get(uri).map_err(Error::from));

        response.and_then(|response| {
            let status = response.status();
            let cluster_info = ClusterInfo::from(response.headers());
            let body = response.into_body().concat2().map_err(Error::from);
            body.and_then(move |ref body| {
                if status == StatusCode::OK {
                    match serde_json::from_slice::<Member>(body) {
                        Ok(data) => {
                            /*
                            for member in data.members {
                                println!("");
                            }
                            */
                            println!("data: {:?}", data);

                            Ok(Response {
                                data: data,
                                cluster_info,
                            })
                        },
                        Err(error) => Err(Error::Serialization(error)),
                    }
                } else {
                    match serde_json::from_slice::<ApiError>(body) {
                        Ok(error) => Err(Error::Api(error)),
                        Err(error) => Err(Error::Serialization(error)),
                    }
                }
            })
        })
    })
}

from rust-etcd.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.