1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Rust client libray for [Consul](http://consul.io/) HTTP API
//!
//! # Usage
//!
//! This crate is [on crates.io](https://crates.io/crates/consul) and
//! can be used by adding `consul` to the dependencies in your
//! project's `Cargo.toml`.
//!
//! ```toml
//! [dependencies]
//! consul = "*"
//! ```
//!
//! and this to your crate root:
//!
//! ```rust
//! extern crate consul;
//! ```
//! # Examples
//! ```rust
//! use std::collections::HashMap;
//! use consul::{Client, Service};
//!
//! let client = Client::new("127.0.0.1:8500");
//! let services: HashMap<String, Service> = client.agent.services();
//! println!("{:?}", services);
//! ```
//!

#![crate_name = "consul"]
#![crate_type = "lib"]

#[doc(no_inline)]
extern crate curl;
extern crate rustc_serialize;

/// public api
pub use agent::{Agent, AgentMember};
pub use catalog::Catalog;
pub use health::Health;
pub use client::Client;
pub use keystore::Keystore;
pub use session::Session;
pub use structs::{Node, Service, HealthService, RegisterService, TtlHealthCheck};

mod agent;
mod catalog;
mod structs;
mod health;
mod client;
mod session;
mod keystore;

use rustc_serialize::json;

#[inline]
pub fn get_string(json_data: &json::Json, path: &[&str]) -> Option<String> {
    let value = match json_data.find_path(path) {
        Some(value) => value,
        None => return None
    };
    let s_value = match value.as_string() {
        Some(value) => value,
        None => return None
    };
    Some(s_value.to_owned())
}