summaryrefslogtreecommitdiffstats
path: root/examples/servicelogs.rs
diff options
context:
space:
mode:
authorWojciech Kępka <46892771+wojciechkepka@users.noreply.github.com>2021-02-09 01:22:26 +0100
committerGitHub <noreply@github.com>2021-02-08 19:22:26 -0500
commit5af822c5691a772cad36bd9a69e94419b03d4511 (patch)
tree761ebc2ac10608a8772d8f7085596ee2ee838b37 /examples/servicelogs.rs
parent4e3f69c34a177697af940849fced1a284fc09449 (diff)
Add services api (#263)
* Add initial Services models * Add initial Services controllers * Add ServicesListOptions * Rename ServicesList -> ServiceList * Fix some optional fields on ServiceRep * Add Service::inspect * Add Service::delete * Add Service::logs * Rename example logs -> containerlogs * Add ServiceOptions, ServiceCreateInfo, fix typo * Add a way to pass headers to request, add Payload and Headers for easier types * Add Service::create * Add examples * Fix fmt * Fix example
Diffstat (limited to 'examples/servicelogs.rs')
-rw-r--r--examples/servicelogs.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/servicelogs.rs b/examples/servicelogs.rs
new file mode 100644
index 0000000..54d4743
--- /dev/null
+++ b/examples/servicelogs.rs
@@ -0,0 +1,32 @@
+use futures::StreamExt;
+use shiplift::{tty::TtyChunk, Docker, LogsOptions};
+use std::env;
+
+#[tokio::main]
+async fn main() {
+ let docker = Docker::new();
+ let id = env::args()
+ .nth(1)
+ .expect("You need to specify a service name");
+
+ let services = docker.services();
+
+ let mut logs_stream = services
+ .get(&id)
+ .logs(&LogsOptions::builder().stdout(true).stderr(true).build());
+
+ while let Some(log_result) = logs_stream.next().await {
+ match log_result {
+ Ok(chunk) => print_chunk(chunk),
+ Err(e) => eprintln!("Error: {}", e),
+ }
+ }
+}
+
+fn print_chunk(chunk: TtyChunk) {
+ match chunk {
+ TtyChunk::StdOut(bytes) => println!("Stdout: {}", std::str::from_utf8(&bytes).unwrap()),
+ TtyChunk::StdErr(bytes) => eprintln!("Stdout: {}", std::str::from_utf8(&bytes).unwrap()),
+ TtyChunk::StdIn(_) => unreachable!(),
+ }
+}