pethost 0.2.5

Client for the API of Pethost, managed hosting for Docker Compose projects: deploy, logs, HTTP traffic, files
Documentation
// @generated by protoc-gen-panel-rust. DO NOT EDIT.

//! The README's program on streams: it prints a project's newest log lines, then follows them.
//!
//! `PETHOST_TOKEN=pth_... cargo run --example logs`

use pethost::types::{QueryContainerLogsRequest, TailContainerLogsRequest};
use pethost::{Client, Error};

#[tokio::main]
async fn main() -> Result<(), Error> {
    // An API token from the panel's Settings, kept out of the code.
    let token = std::env::var("PETHOST_TOKEN").expect("PETHOST_TOKEN is not set");
    let pethost = Client::new(&token);

    // The newest lines of the project `notes`, and where a stream goes on from them without
    // missing one.
    let request = QueryContainerLogsRequest {
        project_id: "notes".into(),
        ..Default::default()
    };
    let newest = pethost.query_container_logs(request).await?;
    for line in &newest.lines {
        println!("{} {}", line.service, line.text);
    }

    // Each later line as it is written. The loop ends when the stream does, and `?` returns
    // the error of one that failed; to stop sooner, leave the loop.
    let request = TailContainerLogsRequest {
        project_id: "notes".into(),
        after_cursor: newest.tail_cursor,
        ..Default::default()
    };
    let mut lines = pethost.tail_container_logs(request);
    while let Some(response) = lines.next().await {
        if let Some(line) = response?.line {
            println!("{} {}", line.service, line.text);
        }
    }
    Ok(())
}