GithubHelp home page GithubHelp logo

googapis's Introduction

googapis

ci Rust Documentation Latest Version

This library generated from Google API using tonic-build.

Overview

This library contains all the code generated from the Google API.

When using each product API, you must explicitly include it in your build using a feature flag. For example, if you want to use Cloud Pub/Sub, write features = ["google-pubsub-v1"] to Cargo.toml.

The feature name is the period of the package name of each proto file, replaced by a hyphen. If you specify a package, it will automatically load the dependent packages and include them in the build. It means that features = ["google-spanner-admin-database-v1"] is the same as the code below:

pub mod google {
    pub mod api {
        tonic::include_proto!("google.api");
    }
    pub mod iam {
        pub mod v1 {
            tonic::include_proto!("google.iam.v1");
        }
    }
    pub mod longrunning {
        tonic::include_proto!("google.longrunning");
    }
    pub mod r#type {
        tonic::include_proto!("google.r#type");
    }
    pub mod rpc {
        tonic::include_proto!("google.rpc");
    }
    pub mod spanner {
        pub mod admin {
            pub mod database {
                pub mod v1 {
                    tonic::include_proto!("google.spanner.admin.database.v1");
                }
            }
        }
    }
}

In addition, multiple features can be specified.

The list of available features can be found here.

Version matrices

googapis tonic tonic-build
0.1.x 0.2.x 0.2.x
0.2.x 0.2.x 0.2.x
0.3.x 0.3.x 0.3.x
0.4.x 0.4.x 0.4.x
0.5.x 0.5.x 0.5.x

Example

The complete code can be found here.

Cargo.toml:

[dependencies]
googapis = { version = "0.5", features = ["google-spanner-admin-database-v1"] }
gouth = { version = "0.2" }
tonic = { version = "0.5", features = ["tls"] }
prost = "0.8"
prost-types = "0.8"
tokio = { version = "1.9", features = ["rt-multi-thread", "time", "fs", "macros"] }

main.rs:

use googapis::{
    google::spanner::admin::database::v1::{
        database_admin_client::DatabaseAdminClient, ListDatabasesRequest,
    },
    CERTIFICATES,
};
use gouth::Token;
use tonic::{
    metadata::MetadataValue,
    transport::{Certificate, Channel, ClientTlsConfig},
    Request,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let project = std::env::var("PROJECT")?;
    let instance = std::env::var("INSTANCE")?;
    let token = Token::new()?;

    let tls_config = ClientTlsConfig::new()
        .ca_certificate(Certificate::from_pem(CERTIFICATES))
        .domain_name("spanner.googleapis.com");

    let channel = Channel::from_static("https://spanner.googleapis.com")
        .tls_config(tls_config)?
        .connect()
        .await?;

    let mut service = DatabaseAdminClient::with_interceptor(channel, move |mut req: Request<()>| {
        let token = &*token.header_value().unwrap();
        let meta = MetadataValue::from_str(token).unwrap();
        req.metadata_mut().insert("authorization", meta);
        Ok(req)
    });

    let response = service
        .list_databases(Request::new(ListDatabasesRequest {
            parent: format!("projects/{}/instances/{}", project, instance),
            page_size: 100,
            ..Default::default()
        }))
        .await?;

    println!("RESPONSE={:?}", response);

    Ok(())
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

googapis's People

Contributors

mechiru avatar renovate-bot avatar shikhar avatar nathanhowell avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.