pub async fn start_webserver<T: 'static + Provider + Send + Sync>(
    provider: Arc<Mutex<T>>,
    address: &SocketAddr,
) -> Result<(), failure::Error> {
    let service = make_service_fn(move |_conn: &AddrStream| {
        let provider = provider.clone();
        async {
            Ok::<_, Error>(service_fn(move |req: Request<Body>| {
                let provider = provider.clone();

                async move {
                    let path: Vec<&str> = req.uri().path().split('/').collect();
                    let path_len = path.len();
                    let response = if path_len < 2 {
                        get_ping()
                    } else {
                        match (req.method(), path[1], path_len) {
                            (&Method::GET, "containerLogs", 5) => {
                                get_container_logs(&*provider.lock().await, &req).await
                            }
                            (&Method::POST, "exec", 5) => post_exec(&*provider.lock().await, &req),
                            _ => {
                                let mut response = Response::new(Body::from("Not Found"));
                                *response.status_mut() = StatusCode::NOT_FOUND;
                                response
                            }
                        }
                    };
                    Ok::<_, Error>(response)
                }
            }))
        }
    });
    let server = Server::bind(address).serve(service);

    info!("starting webserver at: {:?}", address);

    server.await?;

    Ok(())
}
/// Start the Krustlet HTTP(S) server
///
/// This is a primitive implementation of an HTTP provider for the internal API.
/// TODO: Support TLS/SSL.
Start the Krustlet HTTP(S) server
This is a primitive implementation of an HTTP provider for the internal API.
TODO: Support TLS/SSL.
Start the Krustlet HTTP ( S ) server This is a primitive implementation of an HTTP provider for the internal API . TODO : Support TLS / SSL .
pub async fn start_webserver<T: 'static + Provider + Send + Sync>(
    provider: Arc<Mutex<T>>,
    address: &SocketAddr,
) -> Result<(), failure::Error> {
    let service = make_service_fn(move |_conn: &AddrStream| {
        let provider = provider.clone();
        async {
            Ok::<_, Error>(service_fn(move |req: Request<Body>| {
                let provider = provider.clone();
                async move {
                    let path: Vec<&str> = req.uri().path().split('/').collect();
                    let path_len = path.len();
                    let response = if path_len < 2 {
                        get_ping()
                    } else {
                        match (req.method(), path[1], path_len) {
                            (&Method::GET, "containerLogs", 5) => {
                                get_container_logs(&*provider.lock().await, &req).await
                            }
                            (&Method::POST, "exec", 5) => post_exec(&*provider.lock().await, &req),
                            _ => {
                                let mut response = Response::new(Body::from("Not Found"));
                                *response.status_mut() = StatusCode::NOT_FOUND;
                                response
                            }
                        }
                    };
                    Ok::<_, Error>(response)
                }
            }))
        }
    });
    let server = Server::bind(address).serve(service);
    info!("starting webserver at: {:?}", address);
    server.await?;
    Ok(())
}
pub async fn start_webserver < T : ' static + Provider + Send + Sync > ( provider : Arc < Mutex < T > > , address : & SocketAddr , ) -> Result < ( ) , failure :: Error > { let service = make_service_fn ( move | _conn : & AddrStream | { let provider = provider . clone ( ) ; async { Ok :: < _ , Error > ( service_fn ( move | req : Request < Body > | { let provider = provider . clone ( ) ; async move { let path : Vec < & str > = req . uri ( ) . path ( ) . split ( '/' ) . collect ( ) ; let path_len = path . len ( ) ; let response = if path_len < 2 { get_ping ( ) } else { match ( req . method ( ) , path [ 1 ] , path_len ) { ( & Method :: GET , " " , 5 ) => { get_container_logs ( & * provider . lock ( ) . await , & req ) . await } ( & Method :: POST , " " , 5 ) => post_exec ( & * provider . lock ( ) . await , & req ) , _ => { let mut response = Response :: new ( Body :: from ( " " ) ) ; * response . status_mut ( ) = StatusCode :: NOT_FOUND ; response } } } ; Ok :: < _ , Error > ( response ) } } ) ) } } ) ; let server = Server :: bind ( address ) . serve ( service ) ; info ! ( " " address ) ; server . await ? ; Ok ( ( ) ) }
Start the Krustlet HTTP(S) server
This is a primitive implementation of an HTTP provider for the internal API.
Start the Krustlet HTTP ( S ) server This is a primitive implementation of an HTTP provider for the internal API .
provider
Arc<Mutex<T>>
address
&SocketAddr
provider
Arc<Mutex<T>>
address
&SocketAddr