Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no isLeader attribute in the result of member list #24

Open
yulidai opened this issue Dec 21, 2018 · 2 comments
Open

There is no isLeader attribute in the result of member list #24

yulidai opened this issue Dec 21, 2018 · 2 comments

Comments

@yulidai
Copy link

yulidai commented Dec 21, 2018

i need the members' is_leader attribute, can you add it to the result of members::list(&client)?

@yulidai
Copy link
Author

yulidai commented Dec 22, 2018

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

@yulidai
Copy link
Author

yulidai commented Dec 22, 2018

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)),
                    }
                }
            })
        })
    })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants