-
Notifications
You must be signed in to change notification settings - Fork 7
/
struct.rs
69 lines (56 loc) · 1.73 KB
/
struct.rs
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
68
69
use feignhttp::{feign, Feign};
#[derive(Feign)]
struct Github {
// `url_path` and `param` are used to set the shared data.
// The other two for share data are `header` and `query`.
#[url_path("owner")]
user: &'static str,
#[url_path]
repo: &'static str,
#[param]
accept: &'static str,
}
#[feign(
url = "https://api.github.com/repos/{owner}/{repo}",
headers = "Accept: {accept}"
)]
impl Github {
// The method must have a self argument.
#[get]
async fn home(&self) -> feignhttp::Result<String> {}
#[get(path = "", headers = "Accept: application/json")]
async fn repository(&self) -> feignhttp::Result<String> {}
#[get(path = "/contributors")]
async fn contributors(&self, #[query] page: u32) -> feignhttp::Result<String> {}
#[get("/commits")]
async fn commits(
&self,
#[header] accept: &str,
#[query] page: u32,
#[query] per_page: u32,
) -> feignhttp::Result<String> {
}
#[get(path = "/languages")]
async fn languages(&self) -> feignhttp::Result<String> {}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let dxx_github = Github {
user: "dxx",
repo: "feignhttp",
accept: "*/*",
};
let r = dxx_github.home().await?;
println!("github result: {}\n", r);
let r = dxx_github.repository().await?;
println!("repository result: {}\n", r);
let r = dxx_github.contributors(1).await?;
println!("contributors result: {}\n", r);
let r = dxx_github
.commits("application/vnd.github.v3+json", 1, 1)
.await?;
println!("commits result: {}\n", r);
let r = dxx_github.languages().await?;
println!("languages result: {}\n", r);
Ok(())
}