-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abd3b5e
commit cd6815d
Showing
5 changed files
with
218 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use serde_json::{Value, json}; | ||
use crate::http::types; | ||
|
||
pub fn get_string(k: &Value, name: String, default: String) -> String { | ||
match k.get(name.as_str()) { | ||
Some(x) => { | ||
match x.as_str() { | ||
Some (y) => { | ||
return y.to_string(); | ||
}, | ||
None => {} | ||
} | ||
}, | ||
None => {} | ||
} | ||
|
||
match k.get(name.as_str()) { | ||
Some(x) => { | ||
match x.as_bool() { | ||
Some (y) => { | ||
return y.to_string(); | ||
}, | ||
None => {} | ||
} | ||
}, | ||
None => {} | ||
} | ||
|
||
match k.get(name.as_str()) { | ||
Some(x) => { | ||
match x.as_i64() { | ||
Some (y) => { | ||
return y.to_string(); | ||
}, | ||
None => {} | ||
} | ||
}, | ||
None => {} | ||
} | ||
|
||
match k.get(name.as_str()) { | ||
Some(x) => { | ||
match x.as_object() { | ||
Some (y) => { | ||
return format!("{:?}", y); | ||
}, | ||
None => {} | ||
} | ||
}, | ||
None => {} | ||
} | ||
return default; | ||
} | ||
|
||
pub fn get_value(key: String, o: &Value, v: String) -> Value { | ||
let mut value = Value::Null; | ||
if o.is_boolean() { | ||
if v.to_lowercase() == "true".to_string() { | ||
value = Value::Bool(true); | ||
} else if v.to_lowercase() == "false".to_string() { | ||
value = Value::Bool(false); | ||
} else { | ||
println!("Invalid bool value {{ {} : {} }}", key.as_str(), v.as_str()); | ||
return value; | ||
} | ||
} else if o.is_f64() { | ||
let (b, f) = types::str_to_f64(v.clone()); | ||
if b == false { | ||
println!("Invalid f64 value {{ {} : {} }}", key.as_str(), v.as_str()); | ||
return value; | ||
} | ||
value = json!(f); | ||
} else if o.is_i64() || o.is_number() { | ||
let (b, f) = types::str_to_i64(v.clone()); | ||
if b == false { | ||
println!("Invalid i64 value {{ {} : {} }}", key.as_str(), v.as_str()); | ||
return value; | ||
} | ||
value = json!(f); | ||
} else if o.is_string() { | ||
value = json!(v.as_str()); | ||
} else if o.is_u64() { | ||
let (b, f) = types::str_to_u64(v.clone()); | ||
if b == false { | ||
println!("Invalid u64 value {{ {} : {} }}", key.as_str(), v.as_str()); | ||
return value; | ||
} | ||
value = json!(f); | ||
} | ||
return value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod http_fast_reqwest; | ||
pub mod stringops; | ||
pub mod path; | ||
pub mod types; | ||
pub mod types; | ||
pub mod json; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.