function=Text basepath=$(cd `dirname $0`; cd ..;pwd) cd $basepath name=$( pwd|awk -F "/" '{print $NF}'|tr '-' '_') server_name=${basepath##*/} prefix=${server_name##*-} newstr=$(echo ${prefix:0:1}|tr '[a-z]' '[A-Z]')$(echo ${prefix:1}) [[ "$newstr" == "K8s" ]] && newstr="K8S" action=${newstr}${function}Action business=${newstr}${function}Business pname=$(echo ${newstr}${function}|sed -E 's/([A-Z])/_\1/g' | sed -E 's/^_//g' | tr 'A-Z' 'a-z'| tr '-' '_') [[ -f "src/grpcprotos/$action.proto" ]] || echo "syntax = \"proto3\";\n\n\npackage $name;\n\n//${newstr}${function}服务的传递参数\nmessage $action {\n string result=1;\t///返回的结果\n string error=2;\t///返回的错误\n}\n"> src/grpcprotos/$action.proto [[ -f "src/grpcprotos/services/$business.proto" ]] || echo "syntax = \"proto3\";\n\nimport \"$action.proto\";\n\npackage $name;\n\n//${newstr}${function}服务\nservice ${business}Service {\n ///固定的方法名\n rpc Flow ($action) returns ($action);\n}"> src/grpcprotos/services/$business.proto [[ -f "src/grpcs/${pname}_business.rs" ]] || echo "use tonic::{Request, Response, Status};\nuse std::default::Default;\nuse tonic::transport::server::Router;\nuse usc::mygrpcserver;\nuse usc::cin::CollectorIGrpcServer;\n\nuse usb::pbs::${name}::{${pname}_business_service_server::${business}Service,${pname}_business_service_server::${business}ServiceServer, ${action}};\n\n\n\n#[derive(Debug, Default)]\npub struct ${business} {}\n\n#[tonic::async_trait]\nimpl ${business}Service for ${business} {\n async fn flow(&self, request: Request<${action}>) -> Result, Status> {\n let mut action_obj =request.get_ref().clone();\n let mut action=& mut action_obj;\n action.result=\"success\".to_string();\n Ok(Response::new(action_obj))\n }\n}\n\nimpl usc::cin::IGrpcServer for ${business} {\n fn add_to_server(&self, server: Router) -> Router {\n server.add_service(${business}ServiceServer::new(${business}::default()))\n }\n fn classname(&self) -> String {\n \"${newstr}${function}\".to_string()\n }\n}\n\nmygrpcserver!(${business}::default());\n"> src/grpcs/${pname}_business.rs grep "pub mod ${pname}_business;" src/grpcs/mod.rs||echo -e "pub mod ${pname}_business;\n">>src/grpcs/mod.rs p=$(pwd) server_name=${p##*/} prefix=$(echo ${server_name##*-}) find src/grpcs -type f -name "*.rs"|awk -F "[./]" '{print $2}'|xargs -P 1 -I @ bash -xec "a=@;b=\$(echo -n @|sed -E 's/([A-Z])/_\1/g'|sed 's/K8_S/K8S/g'|sed -E 's/^_//g'|tr \"a-z\" \"A-Z\");grep \$a ../base/c/mod.rs||(echo const \$b: &str =\\\"\$a\\\";>>../base/c/mod.rs)" #source grpcrecreate.sh