use std::collections::HashMap; use std::io; use wascc_host::{Actor, Host, NativeCapability}; fn main() -> std::result::Result<(), Box> { env_logger::init(); let host = Host::new(); host.add_actor(Actor::from_file("./examples/.assets/kvcounter.wasm")?)?; host.add_actor(Actor::from_file("./examples/.assets/echo.wasm")?)?; // This actor doesn't get removed host.add_native_capability(NativeCapability::from_file( "./examples/.assets/libwascc_httpsrv.so", None, )?)?; host.add_native_capability(NativeCapability::from_file( "./examples/.assets/libwascc_redis.so", None, )?)?; host.set_binding( "MB4OLDIC3TCZ4Q4TGGOVAZC43VXFE2JQVRAXQMQFXUCREOOFEKOKZTY2", "wascc:http_server", None, generate_port_config(8082), )?; host.set_binding( "MASCXFM4R6X63UD5MSCDZYCJNPBVSIU6RKMXUPXRKAOSBQ6UY3VT3NPZ", "wascc:keyvalue", None, redis_config(), )?; host.set_binding( "MASCXFM4R6X63UD5MSCDZYCJNPBVSIU6RKMXUPXRKAOSBQ6UY3VT3NPZ", "wascc:http_server", None, generate_port_config(8081), )?; println!( "**> curl localhost:8081/counter1 to test, then press ENTER to remove the actor from the host" ); let mut input = String::new(); io::stdin().read_line(&mut input)?; host.remove_actor("MASCXFM4R6X63UD5MSCDZYCJNPBVSIU6RKMXUPXRKAOSBQ6UY3VT3NPZ")?; println!("Actor removed. Echo server should still be working. Press ENTER to finish"); io::stdin().read_line(&mut input)?; Ok(()) } fn redis_config() -> HashMap { let mut hm = HashMap::new(); hm.insert("URL".to_string(), "redis://127.0.0.1:6379".to_string()); hm } fn generate_port_config(port: u16) -> HashMap { let mut hm = HashMap::new(); hm.insert("PORT".to_string(), port.to_string()); hm }