├── .github ├── CODEOWNERS ├── dependabot.yml ├── pull_request_template.md └── workflows │ ├── dependabot.yml │ ├── pr-check.yml │ ├── push-check.yml │ └── reviewdog.yml ├── .gitignore ├── .licenserc.yaml ├── Dockerfile ├── LICENSE ├── NOTICE ├── README.md ├── README_CN.md ├── async_call ├── client │ └── main.go ├── run.sh ├── server │ └── main.go └── test.sh ├── basic ├── client │ └── main.go ├── example_shop │ ├── README.md │ ├── README_CN.md │ ├── api │ │ └── main.go │ ├── docker-compose.yml │ ├── go.mod │ ├── go.sum │ ├── idl │ │ ├── base.thrift │ │ ├── item.thrift │ │ └── stock.thrift │ ├── kitex_gen │ │ └── example │ │ │ └── shop │ │ │ ├── base │ │ │ ├── base.go │ │ │ ├── k-base.go │ │ │ └── k-consts.go │ │ │ ├── item │ │ │ ├── item.go │ │ │ ├── itemservice │ │ │ │ ├── client.go │ │ │ │ ├── invoker.go │ │ │ │ ├── itemservice.go │ │ │ │ └── server.go │ │ │ ├── k-consts.go │ │ │ └── k-item.go │ │ │ └── stock │ │ │ ├── k-consts.go │ │ │ ├── k-stock.go │ │ │ ├── stock.go │ │ │ └── stockservice │ │ │ ├── client.go │ │ │ ├── invoker.go │ │ │ ├── server.go │ │ │ └── stockservice.go │ ├── rpc │ │ ├── item │ │ │ ├── build.sh │ │ │ ├── handler.go │ │ │ ├── kitex_info.yaml │ │ │ ├── main.go │ │ │ └── script │ │ │ │ └── bootstrap.sh │ │ └── stock │ │ │ ├── build.sh │ │ │ ├── handler.go │ │ │ ├── kitex_info.yaml │ │ │ ├── main.go │ │ │ └── script │ │ │ └── bootstrap.sh │ ├── run.sh │ └── test.sh ├── run.sh ├── server │ └── main.go └── test.sh ├── bizdemo ├── README.md ├── easy_note │ ├── ApiDockerfile │ ├── Makefile │ ├── NoteDockerfile │ ├── README.md │ ├── README_CN.md │ ├── UserDockerfile │ ├── api.md │ ├── cmd │ │ ├── api │ │ │ ├── handlers │ │ │ │ ├── create_note.go │ │ │ │ ├── delete_note.go │ │ │ │ ├── handler.go │ │ │ │ ├── query_note.go │ │ │ │ ├── register.go │ │ │ │ └── update_note.go │ │ │ ├── main.go │ │ │ ├── rpc │ │ │ │ ├── init.go │ │ │ │ ├── note.go │ │ │ │ └── user.go │ │ │ └── run.sh │ │ ├── note │ │ │ ├── .gitignore │ │ │ ├── Makefile │ │ │ ├── build.sh │ │ │ ├── dal │ │ │ │ ├── db │ │ │ │ │ ├── init.go │ │ │ │ │ └── note.go │ │ │ │ └── init.go │ │ │ ├── handler.go │ │ │ ├── main.go │ │ │ ├── pack │ │ │ │ ├── note.go │ │ │ │ └── resp.go │ │ │ ├── rpc │ │ │ │ ├── init.go │ │ │ │ └── user.go │ │ │ ├── script │ │ │ │ └── bootstrap.sh │ │ │ └── service │ │ │ │ ├── create_note.go │ │ │ │ ├── delete_note.go │ │ │ │ ├── mget_note.go │ │ │ │ ├── query_note.go │ │ │ │ └── update_note.go │ │ └── user │ │ │ ├── Makefile │ │ │ ├── build.sh │ │ │ ├── dal │ │ │ ├── db │ │ │ │ ├── init.go │ │ │ │ └── user.go │ │ │ └── init.go │ │ │ ├── handler.go │ │ │ ├── main.go │ │ │ ├── pack │ │ │ ├── resp.go │ │ │ └── user.go │ │ │ ├── script │ │ │ └── bootstrap.sh │ │ │ └── service │ │ │ ├── check_user.go │ │ │ ├── create_user.go │ │ │ └── mget_user.go │ ├── docker-compose.yml │ ├── go.mod │ ├── go.sum │ ├── idl │ │ ├── note.thrift │ │ └── user.proto │ ├── images │ │ ├── network.png │ │ └── shot.png │ ├── kitex_gen │ │ ├── notedemo │ │ │ ├── k-consts.go │ │ │ ├── k-note.go │ │ │ ├── note.go │ │ │ └── noteservice │ │ │ │ ├── client.go │ │ │ │ ├── invoker.go │ │ │ │ ├── noteservice.go │ │ │ │ └── server.go │ │ └── userdemo │ │ │ ├── user.pb.go │ │ │ └── userservice │ │ │ ├── client.go │ │ │ ├── invoker.go │ │ │ ├── server.go │ │ │ └── userservice.go │ ├── pkg │ │ ├── bound │ │ │ └── cpu.go │ │ ├── configs │ │ │ └── sql │ │ │ │ └── init.sql │ │ ├── constants │ │ │ ├── constant.go │ │ │ └── util.go │ │ ├── errno │ │ │ └── errno.go │ │ ├── middleware │ │ │ ├── client.go │ │ │ ├── common.go │ │ │ └── server.go │ │ └── tracer │ │ │ └── tracer.go │ └── test.sh ├── kitex_ent │ ├── dao │ │ ├── init.go │ │ └── mysql │ │ │ ├── init.go │ │ │ └── user.go │ ├── ent │ │ ├── client.go │ │ ├── ent.go │ │ ├── enttest │ │ │ └── enttest.go │ │ ├── generate.go │ │ ├── hook │ │ │ └── hook.go │ │ ├── migrate │ │ │ ├── migrate.go │ │ │ └── schema.go │ │ ├── mutation.go │ │ ├── predicate │ │ │ └── predicate.go │ │ ├── runtime.go │ │ ├── runtime │ │ │ └── runtime.go │ │ ├── schema │ │ │ └── user.go │ │ ├── tx.go │ │ ├── user.go │ │ ├── user │ │ │ ├── user.go │ │ │ └── where.go │ │ ├── user_create.go │ │ ├── user_delete.go │ │ ├── user_query.go │ │ └── user_update.go │ ├── go.mod │ ├── go.sum │ ├── handler.go │ ├── idl │ │ └── user.thrift │ ├── kitex_gen │ │ └── user │ │ │ ├── k-consts.go │ │ │ ├── k-user.go │ │ │ ├── user.go │ │ │ └── userservice │ │ │ ├── client.go │ │ │ ├── invoker.go │ │ │ ├── server.go │ │ │ └── userservice.go │ ├── kitex_info.yaml │ ├── main.go │ ├── model │ │ └── sql │ │ │ └── user.sql │ ├── pack │ │ └── user.go │ ├── run.sh │ └── test.sh ├── kitex_gorm │ ├── Makefile │ ├── README.md │ ├── dao │ │ ├── init.go │ │ └── mysql │ │ │ ├── init.go │ │ │ └── user.go │ ├── docker-compose.yml │ ├── go.mod │ ├── go.sum │ ├── handler.go │ ├── idl │ │ └── user.thrift │ ├── kitex_gen │ │ └── user │ │ │ ├── k-consts.go │ │ │ ├── k-user.go │ │ │ ├── user.go │ │ │ └── userservice │ │ │ ├── client.go │ │ │ ├── invoker.go │ │ │ ├── server.go │ │ │ └── userservice.go │ ├── kitex_info.yaml │ ├── main.go │ ├── model │ │ ├── sql │ │ │ └── user.sql │ │ └── user.go │ ├── pack │ │ └── user.go │ ├── run.sh │ └── test.sh ├── kitex_gorm_gen │ ├── Makefile │ ├── README.md │ ├── cmd │ │ └── generate.go │ ├── dao │ │ ├── init.go │ │ └── mysql │ │ │ └── init.go │ ├── docker-compose.yml │ ├── go.mod │ ├── go.sum │ ├── handler.go │ ├── idl │ │ └── user.thrift │ ├── kitex_gen │ │ └── user │ │ │ ├── k-consts.go │ │ │ ├── k-user.go │ │ │ ├── user.go │ │ │ └── userservice │ │ │ ├── client.go │ │ │ ├── invoker.go │ │ │ ├── server.go │ │ │ └── userservice.go │ ├── kitex_info.yaml │ ├── main.go │ ├── model │ │ ├── model │ │ │ └── users.gen.go │ │ ├── query │ │ │ ├── gen.go │ │ │ └── users.gen.go │ │ └── sql │ │ │ └── user.sql │ ├── pack │ │ └── user.go │ ├── run.sh │ └── test.sh ├── kitex_swagger_gen │ ├── Makefile │ ├── README.md │ ├── README_CN.md │ ├── build.sh │ ├── dao │ │ ├── init.go │ │ └── mysql │ │ │ ├── init.go │ │ │ └── user.go │ ├── docker-compose.yml │ ├── downstream_server │ │ └── server.go │ ├── go.mod │ ├── go.sum │ ├── handler.go │ ├── idl │ │ ├── openapi.thrift │ │ └── user.thrift │ ├── kitex_gen │ │ ├── openapi │ │ │ ├── k-consts.go │ │ │ ├── k-openapi.go │ │ │ └── openapi.go │ │ └── user │ │ │ ├── k-consts.go │ │ │ ├── k-user.go │ │ │ ├── user.go │ │ │ └── userservice │ │ │ ├── client.go │ │ │ ├── invoker.go │ │ │ ├── server.go │ │ │ └── userservice.go │ ├── kitex_info.yaml │ ├── main.go │ ├── model │ │ ├── sql │ │ │ └── user.sql │ │ └── user.go │ ├── pack │ │ └── user.go │ ├── run.sh │ ├── script │ │ └── bootstrap.sh │ ├── swagger │ │ ├── openapi.yaml │ │ └── swagger.go │ └── test.sh └── kitex_zorm │ ├── Makefile │ ├── README.md │ ├── dao │ ├── init.go │ └── mysql │ │ ├── init.go │ │ └── user.go │ ├── docker-compose.yml │ ├── go.mod │ ├── go.sum │ ├── handler.go │ ├── idl │ └── user.thrift │ ├── kitex_gen │ └── user │ │ ├── k-consts.go │ │ ├── k-user.go │ │ ├── user.go │ │ └── userservice │ │ ├── client.go │ │ ├── invoker.go │ │ ├── server.go │ │ └── userservice.go │ ├── kitex_info.yaml │ ├── main.go │ ├── model │ ├── sql │ │ └── user.sql │ └── user.go │ ├── pack │ └── user.go │ ├── run.sh │ └── test.sh ├── business_exception ├── TTHeader │ ├── client │ │ └── main.go │ ├── run.sh │ ├── server │ │ └── main.go │ └── test.sh └── gRPC │ ├── client │ └── main.go │ ├── run.sh │ ├── server │ └── main.go │ └── test.sh ├── codec ├── client │ └── main.go ├── json │ ├── codec.go │ └── meta.go ├── run.sh ├── server │ └── main.go └── test.sh ├── discovery ├── client │ └── main.go ├── p2p │ ├── instance.go │ └── resolver.go ├── run.sh ├── server │ └── main.go └── test.sh ├── echo.proto ├── echo.thrift ├── frugal ├── client.go ├── codec │ └── frugal.go ├── main.go ├── run.sh ├── server.go └── test.sh ├── generic-protobuf └── jsonpb-client │ ├── README.md │ ├── generate.sh │ ├── go.mod │ ├── go.sum │ ├── idl │ └── api.proto │ ├── kitex_gen │ └── api │ │ ├── api.pb.fast.go │ │ ├── api.pb.go │ │ └── echo │ │ ├── client.go │ │ ├── echo.go │ │ ├── invoker.go │ │ └── server.go │ ├── main.go │ ├── run.sh │ └── test.sh ├── generic ├── binary │ ├── client │ │ └── main.go │ ├── run.sh │ ├── server │ │ └── main.go │ └── test.sh ├── http │ ├── client │ │ └── main.go │ ├── http.thrift │ ├── run.sh │ ├── server │ │ └── main.go │ └── test.sh ├── json │ ├── client │ │ └── main.go │ ├── example_service.thrift │ ├── run.sh │ ├── server │ │ └── main.go │ └── test.sh ├── kitex_gen │ └── http │ │ ├── bizservice │ │ ├── bizservice.go │ │ ├── client.go │ │ ├── invoker.go │ │ └── server.go │ │ ├── http.go │ │ ├── k-consts.go │ │ └── k-http.go └── map │ ├── client │ └── main.go │ ├── run.sh │ ├── server │ └── main.go │ └── test.sh ├── generic_streaming ├── pb │ ├── build.sh │ ├── client │ │ └── main.go │ ├── go.mod │ ├── go.sum │ ├── handler.go │ ├── idl │ │ └── streaming.proto │ ├── kitex_gen │ │ └── pb │ │ │ ├── streaming.pb.go │ │ │ └── streamingservice │ │ │ ├── client.go │ │ │ ├── server.go │ │ │ └── streamingservice.go │ ├── kitex_info.yaml │ ├── main.go │ ├── run.sh │ ├── script │ │ └── bootstrap.sh │ └── test.sh └── thrift │ ├── client │ └── main.go │ ├── go.mod │ ├── go.sum │ ├── idl │ └── streaming.thrift │ ├── kitex_gen │ └── echo │ │ ├── k-consts.go │ │ ├── k-streaming.go │ │ ├── streaming.go │ │ └── testservice │ │ ├── client.go │ │ ├── server.go │ │ └── testservice.go │ ├── rpc │ ├── build.sh │ ├── handler.go │ ├── kitex_info.yaml │ ├── main.go │ └── script │ │ └── bootstrap.sh │ ├── run.sh │ └── test.sh ├── go.mod ├── go.sum ├── goroutine-local-storage ├── client │ └── main.go ├── run.sh ├── server │ └── main.go └── test.sh ├── governance ├── circuitbreak │ ├── fail.go │ ├── main.go │ ├── run.sh │ ├── test.sh │ └── util.go ├── limit │ ├── main.go │ ├── run.sh │ └── test.sh ├── retry │ ├── client │ │ ├── backup │ │ │ └── main.go │ │ └── failure │ │ │ └── main.go │ ├── failure │ │ └── failure.go │ ├── run.sh │ ├── server │ │ └── main.go │ └── test.sh └── timeout │ ├── client │ └── main.go │ ├── run.sh │ ├── server │ └── main.go │ └── test.sh ├── grpc_multi_service ├── client │ ├── README.md │ ├── README_CN.md │ ├── go.mod │ ├── go.sum │ ├── idl │ │ └── demo.proto │ ├── kitex_gen │ │ └── multi │ │ │ └── service │ │ │ ├── demo.pb.fast.go │ │ │ ├── demo.pb.go │ │ │ ├── servicea │ │ │ ├── client.go │ │ │ ├── invoker.go │ │ │ ├── server.go │ │ │ └── servicea.go │ │ │ └── serviceb │ │ │ ├── client.go │ │ │ ├── invoker.go │ │ │ ├── server.go │ │ │ └── serviceb.go │ └── main.go ├── run.sh ├── server │ ├── README.md │ ├── README_CN.md │ ├── build.sh │ ├── go.mod │ ├── go.sum │ ├── handler.go │ ├── idl │ │ └── demo.proto │ ├── kitex_gen │ │ └── multi │ │ │ └── service │ │ │ ├── demo.pb.fast.go │ │ │ ├── demo.pb.go │ │ │ ├── servicea │ │ │ ├── client.go │ │ │ ├── invoker.go │ │ │ ├── server.go │ │ │ └── servicea.go │ │ │ └── serviceb │ │ │ ├── client.go │ │ │ ├── invoker.go │ │ │ ├── server.go │ │ │ └── serviceb.go │ ├── kitex_info.yaml │ ├── main.go │ └── script │ │ └── bootstrap.sh └── test.sh ├── grpcproxy ├── client │ └── client.go ├── idl │ └── demo.proto ├── kitex_gen │ └── grpcproxy │ │ ├── demo.pb.go │ │ ├── servicea │ │ ├── client.go │ │ ├── invoker.go │ │ ├── server.go │ │ └── servicea.go │ │ └── serviceproxy │ │ ├── client.go │ │ ├── invoker.go │ │ ├── server.go │ │ └── serviceproxy.go ├── main.go ├── proxy │ ├── handler │ │ ├── frame_handler.go │ │ └── struct_handler.go │ └── proxy_server.go ├── run.sh ├── server │ ├── handler.go │ └── server.go └── test.sh ├── hello ├── build.sh ├── client │ └── main.go ├── conf │ └── kitex.yml ├── handler.go ├── hello.thrift ├── kitex_gen │ └── api │ │ ├── hello.go │ │ ├── hello │ │ ├── client.go │ │ ├── hello.go │ │ ├── invoker.go │ │ └── server.go │ │ ├── k-consts.go │ │ └── k-hello.go ├── main.go ├── run.sh ├── script │ ├── bootstrap.sh │ └── settings.py └── test.sh ├── istio ├── .gitignore ├── README.md ├── build.sh ├── client │ └── main.go ├── conf │ └── kitex.yml ├── go.mod ├── go.sum ├── hello.proto ├── kitex_gen │ └── hello │ │ ├── hello.pb.fast.go │ │ ├── hello.pb.go │ │ └── hello │ │ ├── client.go │ │ ├── hello.go │ │ ├── invoker.go │ │ └── server.go ├── kitex_info.yaml ├── run.sh ├── script │ ├── bootstrap.sh │ └── settings.py ├── server │ ├── handler.go │ └── main.go ├── test.sh └── yaml │ ├── client.yaml │ └── service.yaml ├── kitex ├── protobuf │ ├── README.md │ ├── README_CN.md │ ├── build.sh │ ├── go.mod │ ├── go.sum │ ├── handler.go │ ├── idl │ │ └── hello.proto │ ├── kitex_gen │ │ └── hello │ │ │ ├── hello.pb.fast.go │ │ │ ├── hello.pb.go │ │ │ └── helloservice │ │ │ ├── client.go │ │ │ ├── helloservice.go │ │ │ ├── invoker.go │ │ │ └── server.go │ ├── kitex_info.yaml │ ├── main.go │ ├── run.sh │ ├── script │ │ └── bootstrap.sh │ └── test.sh ├── template │ ├── .gitignore │ ├── biz │ │ ├── dal │ │ │ ├── init.go │ │ │ ├── mysql │ │ │ │ └── init.go │ │ │ └── redis │ │ │ │ └── init.go │ │ └── service │ │ │ ├── hello_method.go │ │ │ └── hello_method_test.go │ ├── build.sh │ ├── conf │ │ ├── conf.go │ │ ├── dev │ │ │ └── conf.yaml │ │ ├── online │ │ │ └── conf.yaml │ │ └── test │ │ │ └── conf.yaml │ ├── docker-compose.yaml │ ├── go.mod │ ├── go.sum │ ├── handler.go │ ├── idl │ │ └── hello.thrift │ ├── kitex_gen │ │ └── hello │ │ │ └── example │ │ │ ├── hello.go │ │ │ ├── helloservice │ │ │ ├── client.go │ │ │ ├── helloservice.go │ │ │ ├── invoker.go │ │ │ └── server.go │ │ │ ├── k-consts.go │ │ │ └── k-hello.go │ ├── kitex_info.yaml │ ├── main.go │ ├── makefile │ ├── readme.md │ ├── readme_zn.md │ ├── run.sh │ ├── script │ │ └── bootstrap.sh │ ├── template │ │ ├── bootstrap_sh_tpl.yaml │ │ ├── build_sh_tpl.yaml │ │ ├── conf_dev_tpl.yaml │ │ ├── conf_online_tpl.yaml │ │ ├── conf_test_tpl.yaml │ │ ├── conf_tpl.yaml │ │ ├── dal_init.yaml │ │ ├── docker_compose.yaml │ │ ├── handler_tpl.yaml │ │ ├── ignore_tpl.yaml │ │ ├── kitex_yaml.yaml │ │ ├── main_tpl.yaml │ │ ├── mysql.yaml │ │ ├── readme_tpl.yaml │ │ ├── redis.yaml │ │ ├── service.yaml │ │ └── service_test.yaml │ └── test.sh └── thrift │ ├── README.md │ ├── README_CN.md │ ├── build.sh │ ├── go.mod │ ├── go.sum │ ├── handler.go │ ├── idl │ └── hello.thrift │ ├── kitex_gen │ └── hello │ │ └── example │ │ ├── hello.go │ │ ├── helloservice │ │ ├── client.go │ │ ├── helloservice.go │ │ ├── invoker.go │ │ └── server.go │ │ ├── k-consts.go │ │ └── k-hello.go │ ├── kitex_info.yaml │ ├── main.go │ ├── run.sh │ ├── script │ └── bootstrap.sh │ └── test.sh ├── kitex_gen ├── api │ ├── echo.go │ ├── echo │ │ ├── client.go │ │ ├── echo.go │ │ ├── invoker.go │ │ └── server.go │ ├── k-consts.go │ └── k-echo.go ├── pbapi │ ├── echo.pb.fast.go │ ├── echo.pb.go │ └── echo │ │ ├── client.go │ │ ├── echo.go │ │ ├── invoker.go │ │ └── server.go └── slim │ └── api │ ├── echo.go │ ├── echo │ ├── client.go │ ├── echo.go │ ├── invoker.go │ └── server.go │ ├── k-consts.go │ └── k-echo.go ├── klog ├── README.md ├── README_CN.md ├── custom │ ├── logger.go │ ├── main.go │ ├── run.sh │ └── test.sh ├── logrus │ ├── main.go │ ├── run.sh │ └── test.sh ├── slog │ ├── main.go │ ├── run.sh │ └── test.sh ├── standard │ ├── main.go │ ├── run.sh │ └── test.sh └── zap │ ├── main.go │ ├── run.sh │ └── test.sh ├── licenses ├── LICENSE-gin-jwt.txt ├── LICENSE-gin.txt ├── LICENSE-go-sysconf.txt ├── LICENSE-gopkg.txt ├── LICENSE-gopsutil.txt ├── LICENSE-gorm-mysql.txt ├── LICENSE-gorm-opentracing.txt ├── LICENSE-gorm.txt ├── LICENSE-jaeger-client-go.txt ├── LICENSE-logrus.txt ├── LICENSE-opentracing-go.txt ├── LICENSE-protobuf.txt ├── LICENSE-thrift.txt ├── LICENSE-wmi.txt └── LICENSE-zap.txt ├── loadbalancer ├── client │ ├── consistbalancer │ │ └── main.go │ ├── interleavedweightedroundrobin │ │ └── main.go │ ├── weightedrandom │ │ └── main.go │ └── weightedroundrobin │ │ └── main.go ├── run.sh ├── server │ └── main.go └── test.sh ├── longconnection ├── client │ └── main.go ├── run.sh ├── server │ └── main.go └── test.sh ├── metainfo ├── backward │ ├── README.md │ ├── client │ │ └── main.go │ ├── run.sh │ ├── server │ │ └── main.go │ └── test.sh └── forward │ ├── README.md │ ├── client │ └── main.go │ ├── run.sh │ ├── server-1 │ └── main.go │ ├── server-2 │ └── main.go │ └── test.sh ├── middleware ├── client │ └── main.go ├── mymiddleware │ └── mw.go ├── run.sh ├── server │ └── main.go └── test.sh ├── opentelemetry ├── README.md ├── README_CN.md ├── client │ ├── main.go │ └── run.sh ├── docker-compose.yaml ├── jaeger-arch │ └── img.png ├── otel-collector-config.yaml ├── server │ ├── main.go │ └── run.sh ├── static │ ├── grafana.png │ ├── jaeger-otlp.png │ ├── jaeger.png │ └── panel.png └── test.sh ├── profiler ├── client │ └── main.go ├── run.sh ├── server │ └── main.go └── test.sh ├── prometheus ├── README.md ├── README_CN.md ├── custom │ ├── client │ │ └── main.go │ ├── run.sh │ ├── server │ │ └── main.go │ └── test.sh ├── docker-compose.yaml ├── prometheus.yml └── simple │ ├── client │ └── main.go │ ├── run.sh │ ├── server │ └── main.go │ └── test.sh ├── protobuf_multi_service ├── client │ └── main.go ├── idl │ └── demo.proto ├── kitex_gen │ └── multi │ │ └── service │ │ ├── demo.pb.fast.go │ │ ├── demo.pb.go │ │ ├── servicea │ │ ├── client.go │ │ ├── invoker.go │ │ ├── server.go │ │ └── servicea.go │ │ └── serviceb │ │ ├── client.go │ │ ├── invoker.go │ │ ├── server.go │ │ └── serviceb.go ├── run.sh ├── server │ └── main.go └── test.sh ├── proxyless ├── README.md ├── README_CN.md ├── cleanup.sh ├── config │ └── const.go ├── deploy.sh ├── go.mod ├── go.sum ├── service │ ├── Dockerfile │ ├── bootstrap.sh │ ├── build.sh │ ├── build_image.sh │ ├── codec │ │ └── thrift │ │ │ ├── build.sh │ │ │ ├── gen.sh │ │ │ ├── handler.go │ │ │ ├── idl │ │ │ └── greet.thrift │ │ │ ├── kitex_gen │ │ │ └── proxyless │ │ │ │ ├── greet.go │ │ │ │ ├── greetservice │ │ │ │ ├── client.go │ │ │ │ ├── greetservice.go │ │ │ │ ├── invoker.go │ │ │ │ └── server.go │ │ │ │ ├── k-consts.go │ │ │ │ └── k-greet.go │ │ │ ├── main.go │ │ │ └── script │ │ │ └── bootstrap.sh │ ├── main.go │ └── src │ │ ├── benchmark │ │ └── main.go │ │ ├── client.go │ │ ├── server.go │ │ └── service.go ├── testutil │ ├── Dockerfile │ ├── build.sh │ ├── build_image.sh │ ├── main.go │ └── testSuite │ │ └── controller.go └── yaml │ ├── client │ └── kitex_client.yaml │ ├── server │ ├── kitex_server.yaml │ ├── thrift_proxy.yaml │ ├── virtualService_default.yaml │ ├── virtualService_match_path.yaml │ ├── virtualService_match_tag.yaml │ └── virtualService_traffic_split.yaml │ └── testutil │ └── controller.yaml ├── regenerate-dependabot-config.sh ├── regenerate-idl.sh ├── server_hook ├── run.sh ├── server │ └── main.go └── test.sh ├── server_sdk ├── run.sh ├── test.sh └── thrift │ └── main.go ├── streaming ├── client │ └── main.go ├── echo.proto ├── kitex_gen │ └── pbapi │ │ ├── echo.pb.go │ │ └── echo │ │ ├── client.go │ │ ├── echo.go │ │ ├── invoker.go │ │ └── server.go ├── run.sh ├── server │ └── main.go └── test.sh ├── thrift_multi_service ├── client │ └── main.go ├── idl │ └── demo.thrift ├── kitex_gen │ └── api │ │ ├── demo.go │ │ ├── k-consts.go │ │ ├── k-demo.go │ │ ├── servicea │ │ ├── client.go │ │ ├── invoker.go │ │ ├── server.go │ │ └── servicea.go │ │ └── serviceb │ │ ├── client.go │ │ ├── invoker.go │ │ ├── server.go │ │ └── serviceb.go ├── run.sh ├── server │ └── main.go └── test.sh └── thrift_streaming ├── api.thrift ├── build.sh ├── client └── demo_client.go ├── generate.sh ├── handler.go ├── kitex_gen └── echo │ ├── api.go │ ├── k-api.go │ ├── k-consts.go │ └── testservice │ ├── client.go │ ├── invoker.go │ ├── server.go │ └── testservice.go ├── kitex_info.yaml ├── main.go ├── run.sh ├── script └── bootstrap.sh └── test.sh /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # For more information, please refer to https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners 2 | 3 | * @cloudwego/kitex-reviewers @cloudwego/kitex-approvers @cloudwego/kitex-maintainers 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gomod 4 | schedule: 5 | interval: weekly 6 | allow: 7 | - dependency-name: github.com/cloudwego/kitex 8 | groups: 9 | kitex-dependencies: 10 | patterns: 11 | - github.com/cloudwego/kitex 12 | directories: 13 | - / 14 | - /basic/example_shop 15 | - /bizdemo/easy_note 16 | - /bizdemo/kitex_ent 17 | - /bizdemo/kitex_gorm 18 | - /bizdemo/kitex_gorm_gen 19 | - /bizdemo/kitex_swagger_gen 20 | - /bizdemo/kitex_zorm 21 | - /generic-protobuf/jsonpb-client 22 | - /grpc_multi_service/client 23 | - /grpc_multi_service/server 24 | - /istio 25 | - /kitex/protobuf 26 | - /kitex/template 27 | - /kitex/thrift 28 | - /proxyless 29 | -------------------------------------------------------------------------------- /.github/workflows/pr-check.yml: -------------------------------------------------------------------------------- 1 | name: Pull Request Check 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v4 10 | 11 | - name: Set up Go 12 | uses: actions/setup-go@v5 13 | with: 14 | go-version: 1.23 15 | 16 | - uses: actions/cache@v3 17 | with: 18 | path: ~/go/pkg/mod 19 | key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} 20 | restore-keys: | 21 | ${{ runner.os }}-go- 22 | 23 | - name: Benchmark 24 | run: go test -bench=. -benchmem -run=none ./... 25 | 26 | 27 | -------------------------------------------------------------------------------- /.github/workflows/reviewdog.yml: -------------------------------------------------------------------------------- 1 | name: reviewdog 2 | on: [pull_request] 3 | jobs: 4 | staticcheck: 5 | name: runner / staticcheck 6 | runs-on: ubuntu-latest 7 | steps: 8 | # checkout code 9 | - uses: actions/checkout@v4 10 | 11 | - uses: reviewdog/action-staticcheck@v1 12 | with: 13 | github_token: ${{ secrets.github_token }} 14 | # Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review]. 15 | reporter: github-pr-review 16 | # Report all results. 17 | filter_mode: nofilter 18 | # Exit with 1 when it finds at least one finding. 19 | fail_on_error: true 20 | # Set staticcheck flags 21 | staticcheck_flags: -checks=inherit,-SA1029,-ST1005 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | 17 | # IDE config 18 | .vscode 19 | .idea 20 | 21 | # kitex 22 | thrift_streaming/output 23 | -------------------------------------------------------------------------------- /.licenserc.yaml: -------------------------------------------------------------------------------- 1 | header: 2 | license: 3 | spdx-id: Apache-2.0 4 | copyright-owner: CloudWeGo Authors 5 | 6 | paths: 7 | - '**/*.go' 8 | - '**/*.s' 9 | - '**/*.thrift' 10 | - '**/*.proto' 11 | 12 | paths-ignore: 13 | - '**/kitex_gen/**' 14 | - '**/kitex_info.yaml' 15 | - '**/script/bootstrap.sh' 16 | - 'kitex/**' 17 | - 'grpc_multi_service/kitex_gen/**' 18 | - 'bizdemo/kitex_ent/ent/**' 19 | 20 | comment: on-failure -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2021 CloudWeGo Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | FROM golang:1.21.5-alpine 17 | 18 | RUN apk update && apk add git 19 | 20 | WORKDIR /code 21 | 22 | COPY . . 23 | RUN go env -w GOPROXY=https://goproxy.io,direct 24 | RUN go env -w GO111MODULE=on 25 | RUN go mod tidy 26 | RUN go build -o hello-client ./hello/client 27 | RUN go build -o hello-server ./hello 28 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | CloudWeGo 2 | Copyright 2021 CloudWeGo Authors 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). -------------------------------------------------------------------------------- /async_call/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="async_call" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 26 | trap 'kill $server_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /basic/example_shop/README.md: -------------------------------------------------------------------------------- 1 | ## Example Shop 2 | 3 | English | [中文](./README_CN.md) 4 | 5 | This is a tutorial demo for users who are new to Kitex. You can learn it in [Getting Started](https://www.cloudwego.io/docs/kitex/getting-started/tutorial). 6 | 7 | -------------------------------------------------------------------------------- /basic/example_shop/README_CN.md: -------------------------------------------------------------------------------- 1 | ## Example Shop 2 | 3 | [English](./README.md) | 中文 4 | 5 | 这是一个面向初次接触 Kitex 用户的教学 demo,你可以在[快速开始](https://www.cloudwego.io/zh/docs/kitex/getting-started/tutorial)中学习相关内容。 6 | -------------------------------------------------------------------------------- /basic/example_shop/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | etcd: 5 | image: bitnami/etcd:3.5 6 | container_name: etcd 7 | ports: 8 | - 2379:2379 9 | - 2380:2380 10 | volumes: 11 | - ./etcd/data:/bitnami/etcd-data 12 | environment: 13 | - TZ=Asia/Shanghai 14 | - ALLOW_NONE_AUTHENTICATION=yes 15 | - ETCD_ADVERTISE_CLIENT_URLS=http://etcd:2379 16 | -------------------------------------------------------------------------------- /basic/example_shop/idl/base.thrift: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 CloudWeGo Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | namespace go example.shop.base 18 | 19 | struct BaseResp { 20 | 1: string code 21 | 2: string msg 22 | } -------------------------------------------------------------------------------- /basic/example_shop/kitex_gen/example/shop/base/k-consts.go: -------------------------------------------------------------------------------- 1 | package base 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /basic/example_shop/kitex_gen/example/shop/item/itemservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | 3 | package itemservice 4 | 5 | import ( 6 | item "example_shop/kitex_gen/example/shop/item" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler item.ItemService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /basic/example_shop/kitex_gen/example/shop/item/itemservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package itemservice 3 | 4 | import ( 5 | item "example_shop/kitex_gen/example/shop/item" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler item.ItemService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler item.ItemService, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /basic/example_shop/kitex_gen/example/shop/item/k-consts.go: -------------------------------------------------------------------------------- 1 | package item 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /basic/example_shop/kitex_gen/example/shop/stock/k-consts.go: -------------------------------------------------------------------------------- 1 | package stock 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /basic/example_shop/kitex_gen/example/shop/stock/stockservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | 3 | package stockservice 4 | 5 | import ( 6 | stock "example_shop/kitex_gen/example/shop/stock" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler stock.StockService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /basic/example_shop/kitex_gen/example/shop/stock/stockservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package stockservice 3 | 4 | import ( 5 | stock "example_shop/kitex_gen/example/shop/stock" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler stock.StockService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler stock.StockService, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /basic/example_shop/rpc/item/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="example.shop.item" 3 | 4 | mkdir -p output/bin 5 | cp script/* output/ 6 | chmod +x output/bootstrap.sh 7 | 8 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 9 | go build -o output/bin/${RUN_NAME} 10 | else 11 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 12 | fi 13 | -------------------------------------------------------------------------------- /basic/example_shop/rpc/item/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'example.shop.item' 3 | ToolVersion: 'v0.8.0' 4 | -------------------------------------------------------------------------------- /basic/example_shop/rpc/item/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | CURDIR=$(cd $(dirname $0); pwd) 3 | 4 | if [ "X$1" != "X" ]; then 5 | RUNTIME_ROOT=$1 6 | else 7 | RUNTIME_ROOT=${CURDIR} 8 | fi 9 | 10 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 11 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 12 | 13 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 14 | mkdir -p "$KITEX_LOG_DIR/app" 15 | fi 16 | 17 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 18 | mkdir -p "$KITEX_LOG_DIR/rpc" 19 | fi 20 | 21 | exec "$CURDIR/bin/example.shop.item" 22 | -------------------------------------------------------------------------------- /basic/example_shop/rpc/stock/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="example.shop.stock" 3 | 4 | mkdir -p output/bin 5 | cp script/* output/ 6 | chmod +x output/bootstrap.sh 7 | 8 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 9 | go build -o output/bin/${RUN_NAME} 10 | else 11 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 12 | fi 13 | -------------------------------------------------------------------------------- /basic/example_shop/rpc/stock/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'example.shop.stock' 3 | ToolVersion: 'v0.8.0' 4 | -------------------------------------------------------------------------------- /basic/example_shop/rpc/stock/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | CURDIR=$(cd $(dirname $0); pwd) 3 | 4 | if [ "X$1" != "X" ]; then 5 | RUNTIME_ROOT=$1 6 | else 7 | RUNTIME_ROOT=${CURDIR} 8 | fi 9 | 10 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 11 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 12 | 13 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 14 | mkdir -p "$KITEX_LOG_DIR/app" 15 | fi 16 | 17 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 18 | mkdir -p "$KITEX_LOG_DIR/rpc" 19 | fi 20 | 21 | exec "$CURDIR/bin/example.shop.stock" 22 | -------------------------------------------------------------------------------- /basic/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="basic" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 26 | trap 'kill $server_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /bizdemo/easy_note/ApiDockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.17.2 2 | ENV GO111MODULE=on 3 | ENV GOPROXY="https://goproxy.io" 4 | ENV MysqlIp="192.168.32.1" 5 | ENV EtcdIp="192.168.32.1" 6 | ENV JAEGER_AGENT_HOST="192.168.32.1" 7 | ENV JAEGER_DISABLED=false 8 | ENV JAEGER_SAMPLER_TYPE="const" 9 | ENV JAEGER_SAMPLER_PARAM=1 10 | ENV JAEGER_REPORTER_LOG_SPANS=true 11 | ENV JAEGER_AGENT_PORT=6831 12 | WORKDIR $GOPATH/src/easy_note 13 | COPY . $GOPATH/src/easy_note 14 | WORKDIR $GOPATH/src/easy_note/cmd/api 15 | RUN go build -o main . 16 | EXPOSE 8080 17 | ENTRYPOINT ["./main"] -------------------------------------------------------------------------------- /bizdemo/easy_note/Makefile: -------------------------------------------------------------------------------- 1 | update_user_kitex_gen: 2 | kitex -I idl/ -type protobuf idl/user.proto 3 | 4 | update_note_kitex_gen: 5 | kitex idl/note.thrift -------------------------------------------------------------------------------- /bizdemo/easy_note/NoteDockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.17.2 2 | ENV GO111MODULE=on 3 | ENV GOPROXY="https://goproxy.io" 4 | ENV MysqlIp="192.168.32.1" 5 | ENV EtcdIp="192.168.32.1" 6 | ENV JAEGER_AGENT_HOST="192.168.32.1" 7 | ENV JAEGER_DISABLED=false 8 | ENV JAEGER_SAMPLER_TYPE="const" 9 | ENV JAEGER_SAMPLER_PARAM=1 10 | ENV JAEGER_REPORTER_LOG_SPANS=true 11 | ENV JAEGER_AGENT_PORT=6831 12 | WORKDIR $GOPATH/src/easy_note 13 | COPY . $GOPATH/src/easy_note 14 | WORKDIR $GOPATH/src/easy_note/cmd/note 15 | RUN ["sh", "build.sh"] 16 | EXPOSE 8888 17 | ENTRYPOINT ["./output/bin/demonote"] -------------------------------------------------------------------------------- /bizdemo/easy_note/UserDockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.17.2 2 | ENV GO111MODULE=on 3 | ENV GOPROXY="https://goproxy.io" 4 | ENV MysqlIp="192.168.32.1" 5 | ENV EtcdIp="192.168.32.1" 6 | ENV JAEGER_AGENT_HOST="192.168.32.1" 7 | ENV JAEGER_DISABLED=false 8 | ENV JAEGER_SAMPLER_TYPE="const" 9 | ENV JAEGER_SAMPLER_PARAM=1 10 | ENV JAEGER_REPORTER_LOG_SPANS=true 11 | ENV JAEGER_AGENT_PORT=6831 12 | WORKDIR $GOPATH/src/easy_note 13 | COPY . $GOPATH/src/easy_note 14 | WORKDIR $GOPATH/src/easy_note/cmd/user 15 | RUN ["sh", "build.sh"] 16 | EXPOSE 8889 17 | ENTRYPOINT ["./output/bin/demouser"] -------------------------------------------------------------------------------- /bizdemo/easy_note/cmd/api/rpc/init.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package rpc 17 | 18 | // InitRPC init rpc client 19 | func InitRPC() { 20 | initUserRpc() 21 | initNoteRpc() 22 | } 23 | -------------------------------------------------------------------------------- /bizdemo/easy_note/cmd/api/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2021 CloudWeGo Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | export JAEGER_DISABLED=false 19 | export JAEGER_SAMPLER_TYPE="const" 20 | export JAEGER_SAMPLER_PARAM=1 21 | export JAEGER_REPORTER_LOG_SPANS=true 22 | export JAEGER_AGENT_HOST="127.0.0.1" 23 | export JAEGER_AGENT_PORT=6831 24 | go run ./main.go 25 | -------------------------------------------------------------------------------- /bizdemo/easy_note/cmd/note/.gitignore: -------------------------------------------------------------------------------- 1 | output -------------------------------------------------------------------------------- /bizdemo/easy_note/cmd/note/Makefile: -------------------------------------------------------------------------------- 1 | server: 2 | cd ../.. && kitex idl/note.thrift 3 | kitex -service demonote -use github.com/cloudwego/kitex-examples/biz-demo/easy_note/kitex_gen ../../idl/note.thrift 4 | -------------------------------------------------------------------------------- /bizdemo/easy_note/cmd/note/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2021 CloudWeGo Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | RUN_NAME="demonote" 19 | 20 | mkdir -p output/bin 21 | cp script/* output/ 22 | chmod +x output/bootstrap.sh 23 | 24 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 25 | go build -o output/bin/${RUN_NAME} 26 | else 27 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 28 | fi -------------------------------------------------------------------------------- /bizdemo/easy_note/cmd/note/dal/init.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package dal 17 | 18 | import "github.com/cloudwego/kitex-examples/bizdemo/easy_note/cmd/note/dal/db" 19 | 20 | // Init init dal 21 | func Init() { 22 | db.Init() // mysql 23 | } 24 | -------------------------------------------------------------------------------- /bizdemo/easy_note/cmd/note/rpc/init.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package rpc 17 | 18 | // InitRPC init rpc client 19 | func InitRPC() { 20 | initUserRpc() 21 | } 22 | -------------------------------------------------------------------------------- /bizdemo/easy_note/cmd/user/Makefile: -------------------------------------------------------------------------------- 1 | server: 2 | kitex -I ../../idl/ -type protobuf -service demouser -use github.com/cloudwego/kitex-examples/biz-demo/easy_note/kitex_gen ../../idl/user.proto 3 | -------------------------------------------------------------------------------- /bizdemo/easy_note/cmd/user/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2021 CloudWeGo Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | RUN_NAME="demouser" 19 | 20 | mkdir -p output/bin 21 | cp script/* output/ 22 | chmod +x output/bootstrap.sh 23 | 24 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 25 | go build -o output/bin/${RUN_NAME} 26 | else 27 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 28 | fi 29 | -------------------------------------------------------------------------------- /bizdemo/easy_note/cmd/user/dal/init.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package dal 17 | 18 | import "github.com/cloudwego/kitex-examples/bizdemo/easy_note/cmd/user/dal/db" 19 | 20 | // Init init dal 21 | func Init() { 22 | db.Init() // mysql init 23 | } 24 | -------------------------------------------------------------------------------- /bizdemo/easy_note/images/network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwego/kitex-examples/0f8011b1ef15db252b2bf6ca6e7bd6248da6adaa/bizdemo/easy_note/images/network.png -------------------------------------------------------------------------------- /bizdemo/easy_note/images/shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwego/kitex-examples/0f8011b1ef15db252b2bf6ca6e7bd6248da6adaa/bizdemo/easy_note/images/shot.png -------------------------------------------------------------------------------- /bizdemo/easy_note/kitex_gen/notedemo/k-consts.go: -------------------------------------------------------------------------------- 1 | package notedemo 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /bizdemo/easy_note/kitex_gen/notedemo/noteservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.1.4. DO NOT EDIT. 2 | 3 | package noteservice 4 | 5 | import ( 6 | "github.com/cloudwego/kitex-examples/bizdemo/easy_note/kitex_gen/notedemo" 7 | "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler notedemo.NoteService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /bizdemo/easy_note/kitex_gen/notedemo/noteservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package noteservice 3 | 4 | import ( 5 | notedemo "github.com/cloudwego/kitex-examples/bizdemo/easy_note/kitex_gen/notedemo" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler notedemo.NoteService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler notedemo.NoteService, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /bizdemo/easy_note/kitex_gen/userdemo/userservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.1.4. DO NOT EDIT. 2 | 3 | package userservice 4 | 5 | import ( 6 | "github.com/cloudwego/kitex-examples/bizdemo/easy_note/kitex_gen/userdemo" 7 | "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler userdemo.UserService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /bizdemo/easy_note/kitex_gen/userdemo/userservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.1.4. DO NOT EDIT. 2 | package userservice 3 | 4 | import ( 5 | "github.com/cloudwego/kitex-examples/bizdemo/easy_note/kitex_gen/userdemo" 6 | "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler userdemo.UserService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/dao/init.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 CloudWeGo Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dao 18 | 19 | import "github.com/cloudwego/kitex-examples/bizdemo/kitex_ent/dao/mysql" 20 | 21 | func init() { 22 | mysql.Init() 23 | } 24 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/ent/generate.go: -------------------------------------------------------------------------------- 1 | package ent 2 | 3 | //go:generate go run -mod=mod entgo.io/ent/cmd/ent generate ./schema 4 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/ent/migrate/schema.go: -------------------------------------------------------------------------------- 1 | // Code generated by ent, DO NOT EDIT. 2 | 3 | package migrate 4 | 5 | import ( 6 | "entgo.io/ent/dialect/sql/schema" 7 | "entgo.io/ent/schema/field" 8 | ) 9 | 10 | var ( 11 | // UsersColumns holds the columns for the "users" table. 12 | UsersColumns = []*schema.Column{ 13 | {Name: "id", Type: field.TypeInt, Increment: true}, 14 | {Name: "name", Type: field.TypeString}, 15 | {Name: "age", Type: field.TypeInt}, 16 | {Name: "gender", Type: field.TypeInt}, 17 | {Name: "introduce", Type: field.TypeString}, 18 | } 19 | // UsersTable holds the schema information for the "users" table. 20 | UsersTable = &schema.Table{ 21 | Name: "users", 22 | Columns: UsersColumns, 23 | PrimaryKey: []*schema.Column{UsersColumns[0]}, 24 | } 25 | // Tables holds all the tables in the schema. 26 | Tables = []*schema.Table{ 27 | UsersTable, 28 | } 29 | ) 30 | 31 | func init() { 32 | } 33 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/ent/predicate/predicate.go: -------------------------------------------------------------------------------- 1 | // Code generated by ent, DO NOT EDIT. 2 | 3 | package predicate 4 | 5 | import ( 6 | "entgo.io/ent/dialect/sql" 7 | ) 8 | 9 | // User is the predicate function for user builders. 10 | type User func(*sql.Selector) 11 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/ent/runtime.go: -------------------------------------------------------------------------------- 1 | // Code generated by ent, DO NOT EDIT. 2 | 3 | package ent 4 | 5 | // The init function reads all schema descriptors with runtime code 6 | // (default values, validators, hooks and policies) and stitches it 7 | // to their package variables. 8 | func init() { 9 | } 10 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/ent/runtime/runtime.go: -------------------------------------------------------------------------------- 1 | // Code generated by ent, DO NOT EDIT. 2 | 3 | package runtime 4 | 5 | // The schema-stitching logic is generated in github.com/cloudwego/kitex-examples/bizdemo/kitex_ent/ent/runtime.go 6 | 7 | const ( 8 | Version = "v0.12.5" // Version of ent codegen. 9 | Sum = "h1:KREM5E4CSoej4zeGa88Ou/gfturAnpUv0mzAjch1sj4=" // Sum of ent codegen. 10 | ) 11 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/ent/schema/user.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | import ( 4 | "entgo.io/ent" 5 | "entgo.io/ent/schema/field" 6 | ) 7 | 8 | // User holds the schema definition for the User entity. 9 | type User struct { 10 | ent.Schema 11 | } 12 | 13 | // Fields of the User. 14 | func (User) Fields() []ent.Field { 15 | return []ent.Field{ 16 | field.Int("id"), 17 | field.String("name"), 18 | field.Int("age"), 19 | field.Int("gender"), 20 | field.String("introduce"), 21 | } 22 | } 23 | 24 | // Edges of the User. 25 | func (User) Edges() []ent.Edge { 26 | return nil 27 | } 28 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/kitex_gen/user/k-consts.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/kitex_gen/user/userservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | 3 | package userservice 4 | 5 | import ( 6 | user "github.com/cloudwego/kitex-examples/bizdemo/kitex_ent/kitex_gen/user" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler user.UserService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/kitex_gen/user/userservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package userservice 3 | 4 | import ( 5 | user "github.com/cloudwego/kitex-examples/bizdemo/kitex_ent/kitex_gen/user" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler user.UserService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler user.UserService, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'user' 3 | ToolVersion: 'v0.8.0' 4 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 CloudWeGo Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "log" 21 | 22 | user "github.com/cloudwego/kitex-examples/bizdemo/kitex_ent/kitex_gen/user/userservice" 23 | ) 24 | 25 | func main() { 26 | svr := user.NewServer(new(UserServiceImpl)) 27 | 28 | err := svr.Run() 29 | if err != nil { 30 | log.Println(err.Error()) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /bizdemo/kitex_ent/model/sql/user.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `users` 2 | ( 3 | `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK', 4 | `name` varchar(128) NOT NULL DEFAULT '' COMMENT 'User name', 5 | `gender` int(8) NOT NULL DEFAULT 0 COMMENT 'User gender', 6 | `age` int(64) NOT NULL DEFAULT 0 COMMENT 'User age', 7 | `introduce` Text NULL COMMENT 'User introduce', 8 | `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'User information create time', 9 | `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'User information update time', 10 | `deleted_at` timestamp NULL DEFAULT NULL COMMENT 'User information delete time', 11 | PRIMARY KEY (`id`), 12 | KEY `idx_name` (`name`,`deleted_at`) COMMENT 'User name index' 13 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='User information table' -------------------------------------------------------------------------------- /bizdemo/kitex_ent/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="kitex_ent" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 21 | trap 'kill $server_pid' EXIT 22 | 23 | # 等待 server 结束 24 | wait $server_pid -------------------------------------------------------------------------------- /bizdemo/kitex_ent/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="kitex_ent" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | # 检查 server 是否仍在运行 27 | if kill -0 $server_pid; then 28 | echo "Project run successfully: $project" 29 | echo "---------------------------------------" 30 | else 31 | echo "Project failed to run: $project" 32 | echo "---------------------------------------" 33 | status=1 34 | fi 35 | 36 | # 杀死 server 37 | kill -9 $server_pid $(lsof -t -i:8888) 38 | 39 | 40 | # 设置脚本的退出状态 41 | exit $status -------------------------------------------------------------------------------- /bizdemo/kitex_gorm/Makefile: -------------------------------------------------------------------------------- 1 | init_user/update_user: 2 | kitex -service user -module github.com/cloudwego/kitex-examples/bizdemo/kitex_gorm ./idl/user.thrift 3 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm/README.md: -------------------------------------------------------------------------------- 1 | # kitex_gorm 2 | 3 | ## Introduce 4 | 5 | A demo with `Kitex` and `Gorm` 6 | 7 | - Use `thrift` IDL to define `RPC` interface 8 | - Use `kitex` to generate code 9 | - Use `Gorm` and `MySQL` 10 | 11 | ## IDL 12 | 13 | This demo use `thrift` IDL to define `RPC` interface. The specific interface define in [user.thrift](idl/user.thrift) 14 | 15 | ## Code generation tool 16 | 17 | This demo use `kitex` to generate code. The use of `kitex` refers 18 | to [kitex](https://www.cloudwego.io/docs/kitex/tutorials/code-gen/) 19 | 20 | The `kitex` commands used can be found in [Makefile](Makefile) 21 | 22 | ## Gorm 23 | 24 | This demo use `Gorm` to operate `MySQL` and refers to [Gorm](https://gorm.io/) 25 | 26 | ## How to run 27 | 28 | ### Run mysql docker 29 | 30 | ```bash 31 | cd bizdemo/kitex_gorm && docker-compose up 32 | ``` 33 | 34 | ### Run demo 35 | 36 | ```bash 37 | cd bizdemo/kitex_gorm 38 | go build -o kitex_gorm && ./kitex_gorm 39 | ``` -------------------------------------------------------------------------------- /bizdemo/kitex_gorm/dao/init.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 CloudWeGo Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dao 18 | 19 | import "github.com/cloudwego/kitex-examples/bizdemo/kitex_gorm/dao/mysql" 20 | 21 | func init() { 22 | mysql.Init() 23 | } 24 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | mysql: 5 | image: 'mysql:latest' 6 | volumes: 7 | - ./biz/model/sql:/docker-entrypoint-initdb.d 8 | ports: 9 | - 9910:3306 10 | environment: 11 | - MYSQL_DATABASE=gorm 12 | - MYSQL_USER=gorm 13 | - MYSQL_PASSWORD=gorm 14 | - MYSQL_RANDOM_ROOT_PASSWORD="yes" -------------------------------------------------------------------------------- /bizdemo/kitex_gorm/kitex_gen/user/k-consts.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm/kitex_gen/user/userservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | 3 | package userservice 4 | 5 | import ( 6 | user "github.com/cloudwego/kitex-examples/bizdemo/kitex_gorm/kitex_gen/user" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler user.UserService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm/kitex_gen/user/userservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package userservice 3 | 4 | import ( 5 | user "github.com/cloudwego/kitex-examples/bizdemo/kitex_gorm/kitex_gen/user" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler user.UserService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler user.UserService, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'user' 3 | ToolVersion: 'v0.8.0' 4 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm/model/sql/user.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `users` 2 | ( 3 | `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK', 4 | `name` varchar(128) NOT NULL DEFAULT '' COMMENT 'User name', 5 | `gender` int(8) NOT NULL DEFAULT 0 COMMENT 'User gender', 6 | `age` int(64) NOT NULL DEFAULT 0 COMMENT 'User age', 7 | `introduce` Text NULL COMMENT 'User introduce', 8 | `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'User information create time', 9 | `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'User information update time', 10 | `deleted_at` timestamp NULL DEFAULT NULL COMMENT 'User information delete time', 11 | PRIMARY KEY (`id`), 12 | KEY `idx_name` (`name`,`deleted_at`) COMMENT 'User name index' 13 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='User information table' -------------------------------------------------------------------------------- /bizdemo/kitex_gorm/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="kitex_gorm" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 21 | trap 'kill $server_pid' EXIT 22 | 23 | # 等待 server 结束 24 | wait $server_pid -------------------------------------------------------------------------------- /bizdemo/kitex_gorm/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="kitex_gorm" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | # 检查 server 是否仍在运行 27 | if kill -0 $server_pid; then 28 | echo "Project run successfully: $project" 29 | echo "---------------------------------------" 30 | else 31 | echo "Project failed to run: $project" 32 | echo "---------------------------------------" 33 | status=1 34 | fi 35 | 36 | # 杀死 server 37 | kill -9 $server_pid $(lsof -t -i:8888) 38 | 39 | 40 | # 设置脚本的退出状态 41 | exit $status -------------------------------------------------------------------------------- /bizdemo/kitex_gorm_gen/Makefile: -------------------------------------------------------------------------------- 1 | init_user/update_user: 2 | kitex -service user -module github.com/cloudwego/kitex-examples/bizdemo/kitex_gorm_gen ./idl/user.thrift 3 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm_gen/dao/init.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 CloudWeGo Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dao 18 | 19 | import "github.com/cloudwego/kitex-examples/bizdemo/kitex_gorm_gen/dao/mysql" 20 | 21 | func init() { 22 | mysql.Init() 23 | } 24 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm_gen/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | mysql: 5 | image: 'mysql:latest' 6 | volumes: 7 | - ./biz/model/sql:/docker-entrypoint-initdb.d 8 | ports: 9 | - 9910:3306 10 | environment: 11 | - MYSQL_DATABASE=gorm 12 | - MYSQL_USER=gorm 13 | - MYSQL_PASSWORD=gorm 14 | - MYSQL_RANDOM_ROOT_PASSWORD="yes" -------------------------------------------------------------------------------- /bizdemo/kitex_gorm_gen/kitex_gen/user/k-consts.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm_gen/kitex_gen/user/userservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | 3 | package userservice 4 | 5 | import ( 6 | user "github.com/cloudwego/kitex-examples/bizdemo/kitex_gorm_gen/kitex_gen/user" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler user.UserService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm_gen/kitex_gen/user/userservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package userservice 3 | 4 | import ( 5 | user "github.com/cloudwego/kitex-examples/bizdemo/kitex_gorm_gen/kitex_gen/user" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler user.UserService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler user.UserService, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm_gen/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'user' 3 | ToolVersion: 'v0.8.0' 4 | -------------------------------------------------------------------------------- /bizdemo/kitex_gorm_gen/model/sql/user.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `users` 2 | ( 3 | `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK', 4 | `name` varchar(128) NOT NULL DEFAULT '' COMMENT 'User name', 5 | `gender` int(8) NOT NULL DEFAULT 0 COMMENT 'User gender', 6 | `age` int(64) NOT NULL DEFAULT 0 COMMENT 'User age', 7 | `introduce` Text NULL COMMENT 'User introduce', 8 | `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'User information create time', 9 | `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'User information update time', 10 | `deleted_at` timestamp NULL DEFAULT NULL COMMENT 'User information delete time', 11 | PRIMARY KEY (`id`), 12 | KEY `idx_name` (`name`,`deleted_at`) COMMENT 'User name index' 13 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='User information table' -------------------------------------------------------------------------------- /bizdemo/kitex_gorm_gen/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="kitex_gorm_gen" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 21 | trap 'kill $server_pid' EXIT 22 | 23 | # 等待 server 结束 24 | wait $server_pid -------------------------------------------------------------------------------- /bizdemo/kitex_gorm_gen/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="kitex_gorm_gen" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | # 检查 server 是否仍在运行 27 | if kill -0 $server_pid; then 28 | echo "Project run successfully: $project" 29 | echo "---------------------------------------" 30 | else 31 | echo "Project failed to run: $project" 32 | echo "---------------------------------------" 33 | status=1 34 | fi 35 | 36 | # 杀死 server 37 | kill -9 $server_pid $(lsof -t -i:8888) 38 | 39 | 40 | # 设置脚本的退出状态 41 | exit $status -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/Makefile: -------------------------------------------------------------------------------- 1 | init_user/update_user: 2 | kitex -service user -module github.com/cloudwego/kitex-examples/bizdemo/kitex_swagger_gen -thrift-plugin rpc-swagger ./idl/user.thrift 3 | -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="user" 3 | 4 | mkdir -p output/bin 5 | cp script/* output/ 6 | chmod +x output/bootstrap.sh 7 | 8 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 9 | go build -o output/bin/${RUN_NAME} 10 | else 11 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 12 | fi 13 | -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/dao/init.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 CloudWeGo Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dao 18 | 19 | import "github.com/cloudwego/kitex-examples/bizdemo/kitex_swagger_gen/dao/mysql" 20 | 21 | func init() { 22 | mysql.Init() 23 | } 24 | -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | mysql: 5 | image: 'mysql:latest' 6 | volumes: 7 | - ./biz/model/sql:/docker-entrypoint-initdb.d 8 | ports: 9 | - 9910:3306 10 | environment: 11 | - MYSQL_DATABASE=gorm 12 | - MYSQL_USER=gorm 13 | - MYSQL_PASSWORD=gorm 14 | - MYSQL_RANDOM_ROOT_PASSWORD="yes" -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/kitex_gen/openapi/k-consts.go: -------------------------------------------------------------------------------- 1 | package openapi 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/kitex_gen/user/k-consts.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/kitex_gen/user/userservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.10.3. DO NOT EDIT. 2 | 3 | package userservice 4 | 5 | import ( 6 | user "github.com/cloudwego/kitex-examples/bizdemo/kitex_swagger_gen/kitex_gen/user" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler user.UserService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/kitex_gen/user/userservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package userservice 3 | 4 | import ( 5 | user "github.com/cloudwego/kitex-examples/bizdemo/kitex_swagger_gen/kitex_gen/user" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler user.UserService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler user.UserService, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'user' 3 | ToolVersion: 'v0.10.3' 4 | -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/model/sql/user.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `users` 2 | ( 3 | `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK', 4 | `name` varchar(128) NOT NULL DEFAULT '' COMMENT 'User name', 5 | `gender` int(8) NOT NULL DEFAULT 0 COMMENT 'User gender', 6 | `age` int(64) NOT NULL DEFAULT 0 COMMENT 'User age', 7 | `introduce` Text NULL COMMENT 'User introduce', 8 | `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'User information create time', 9 | `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'User information update time', 10 | `deleted_at` timestamp NULL DEFAULT NULL COMMENT 'User information delete time', 11 | PRIMARY KEY (`id`), 12 | KEY `idx_name` (`name`,`deleted_at`) COMMENT 'User name index' 13 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='User information table' -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | REPO_PATH="." 5 | DOWNSTREAM_PATH="./downstream_server" 6 | 7 | project="kitex_swagger_gen" 8 | 9 | echo "---------------------------------------" 10 | echo "Running project: $project" 11 | 12 | # 启动当前目录下的服务 13 | cd "$REPO_PATH/" || exit 14 | echo "Starting main server..." 15 | go run . > /dev/null 2>&1 & 16 | main_server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 downstream_server 服务 20 | cd "$DOWNSTREAM_PATH/" || exit 21 | echo "Starting downstream server..." 22 | go run . > /dev/null 2>&1 & 23 | downstream_server_pid=$! 24 | cd - > /dev/null || exit 25 | 26 | # 当脚本退出时,停止所有服务 27 | trap 'kill $main_server_pid $downstream_server_pid' EXIT 28 | 29 | # 等待所有服务结束 30 | wait $main_server_pid $downstream_server_pid 31 | -------------------------------------------------------------------------------- /bizdemo/kitex_swagger_gen/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | CURDIR=$(cd $(dirname $0); pwd) 3 | 4 | if [ "X$1" != "X" ]; then 5 | RUNTIME_ROOT=$1 6 | else 7 | RUNTIME_ROOT=${CURDIR} 8 | fi 9 | 10 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 11 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 12 | 13 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 14 | mkdir -p "$KITEX_LOG_DIR/app" 15 | fi 16 | 17 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 18 | mkdir -p "$KITEX_LOG_DIR/rpc" 19 | fi 20 | 21 | exec "$CURDIR/bin/user" 22 | -------------------------------------------------------------------------------- /bizdemo/kitex_zorm/Makefile: -------------------------------------------------------------------------------- 1 | init_user/update_user: 2 | kitex -service user -module github.com/cloudwego/kitex-examples/bizdemo/kitex_gorm ./idl/user.thrift 3 | -------------------------------------------------------------------------------- /bizdemo/kitex_zorm/README.md: -------------------------------------------------------------------------------- 1 | # kitex_zorm 2 | 3 | ## Introduce 4 | 5 | A demo with `Kitex` and `Zorm` 6 | 7 | - Use `thrift` IDL to define `RPC` interface 8 | - Use `kitex` to generate code 9 | - Use `Zorm` and `MySQL` 10 | 11 | ## IDL 12 | 13 | This demo use `thrift` IDL to define `RPC` interface. The specific interface define in [user.thrift](idl/user.thrift) 14 | 15 | ## Code generation tool 16 | 17 | This demo use `kitex` to generate code. The use of `kitex` refers 18 | to [kitex](https://www.cloudwego.io/docs/kitex/tutorials/code-gen/) 19 | 20 | The `kitex` commands used can be found in [Makefile](Makefile) 21 | 22 | ## Zorm 23 | 24 | This demo use `Zorm` to operate `MySQL` and refers to [Zorm](https://www.zorm.cn/) 25 | 26 | ## How to run 27 | 28 | ### Run mysql docker 29 | 30 | ```bash 31 | cd bizdemo/kitex_zorm && docker-compose up 32 | ``` 33 | 34 | ### Run demo 35 | 36 | ```bash 37 | cd bizdemo/kitex_zorm 38 | go build -o kitex_zorm && ./kitex_zorm 39 | ``` -------------------------------------------------------------------------------- /bizdemo/kitex_zorm/dao/init.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 CloudWeGo Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dao 18 | 19 | import "github.com/cloudwego/kitex-examples/bizdemo/kitex_zorm/dao/mysql" 20 | 21 | func init() { 22 | mysql.Init() 23 | } 24 | -------------------------------------------------------------------------------- /bizdemo/kitex_zorm/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | mysql: 5 | image: 'mysql:latest' 6 | volumes: 7 | - ./biz/model/sql:/docker-entrypoint-initdb.d 8 | ports: 9 | - 9910:3306 10 | environment: 11 | - MYSQL_DATABASE=gorm 12 | - MYSQL_USER=gorm 13 | - MYSQL_PASSWORD=gorm 14 | - MYSQL_RANDOM_ROOT_PASSWORD="yes" -------------------------------------------------------------------------------- /bizdemo/kitex_zorm/kitex_gen/user/k-consts.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /bizdemo/kitex_zorm/kitex_gen/user/userservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | 3 | package userservice 4 | 5 | import ( 6 | user "github.com/cloudwego/kitex-examples/bizdemo/kitex_zorm/kitex_gen/user" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler user.UserService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /bizdemo/kitex_zorm/kitex_gen/user/userservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package userservice 3 | 4 | import ( 5 | user "github.com/cloudwego/kitex-examples/bizdemo/kitex_zorm/kitex_gen/user" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler user.UserService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler user.UserService, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /bizdemo/kitex_zorm/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'user' 3 | ToolVersion: 'v0.8.0' 4 | -------------------------------------------------------------------------------- /bizdemo/kitex_zorm/model/sql/user.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `users` 2 | ( 3 | `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK', 4 | `name` varchar(128) NOT NULL DEFAULT '' COMMENT 'User name', 5 | `gender` int(8) NOT NULL DEFAULT 0 COMMENT 'User gender', 6 | `age` int(64) NOT NULL DEFAULT 0 COMMENT 'User age', 7 | `introduce` Text NULL COMMENT 'User introduce', 8 | `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'User information create time', 9 | `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'User information update time', 10 | `deleted_at` timestamp NULL DEFAULT NULL COMMENT 'User information delete time', 11 | PRIMARY KEY (`id`), 12 | KEY `idx_name` (`name`,`deleted_at`) COMMENT 'User name index' 13 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='User information table' -------------------------------------------------------------------------------- /bizdemo/kitex_zorm/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="kitex_zorm" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 21 | trap 'kill $server_pid' EXIT 22 | 23 | # 等待 server 结束 24 | wait $server_pid -------------------------------------------------------------------------------- /bizdemo/kitex_zorm/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="kitex_zorm" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | # 检查 server 是否仍在运行 27 | if kill -0 $server_pid; then 28 | echo "Project run successfully: $project" 29 | echo "---------------------------------------" 30 | else 31 | echo "Project failed to run: $project" 32 | echo "---------------------------------------" 33 | status=1 34 | fi 35 | 36 | # 杀死 server 37 | kill -9 $server_pid $(lsof -t -i:8888) 38 | 39 | 40 | # 设置脚本的退出状态 41 | exit $status -------------------------------------------------------------------------------- /business_exception/TTHeader/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="business_exception_TTHeader" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 26 | trap 'kill $server_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /business_exception/gRPC/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="business_exception_gRPC" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 26 | trap 'kill $server_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /codec/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="codec" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /discovery/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="discovery" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /echo.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2021 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | syntax = "proto3"; 17 | package pbapi; 18 | // The greeting service definition. 19 | option go_package = "pbapi"; 20 | 21 | message Request { 22 | string message = 1; 23 | } 24 | 25 | message Response { 26 | string message = 1; 27 | } 28 | 29 | service Echo { 30 | rpc Echo (Request) returns (Response) {} 31 | } -------------------------------------------------------------------------------- /echo.thrift: -------------------------------------------------------------------------------- 1 | // Copyright 2021 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | namespace go api 17 | 18 | struct Request { 19 | 1: string message 20 | } 21 | 22 | struct Response { 23 | 1: string message 24 | } 25 | 26 | service Echo { 27 | Response echo(1: Request req) 28 | } 29 | -------------------------------------------------------------------------------- /frugal/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package main 17 | 18 | import ( 19 | "github.com/cloudwego/kitex/server" 20 | ) 21 | 22 | func main() { 23 | server.RegisterStartHook(frugalClient) 24 | frugalServer() 25 | } 26 | -------------------------------------------------------------------------------- /frugal/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="frugal" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/codec" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 26 | trap 'kill $server_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /frugal/test.sh: -------------------------------------------------------------------------------- 1 | #!/opt/homebrew/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="frugal" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | go run . > /dev/null 2>&1 & 18 | server_pid=$! 19 | 20 | 21 | # 等待 server 启动 22 | sleep 1 23 | 24 | # 启动 client 25 | 26 | cd "$REPO_PATH/codec" || exit 27 | go run frugal.go > /dev/null 2>&1 & 28 | cd - > /dev/null || exit 29 | 30 | 31 | # 等待 client 启动 32 | sleep 1 33 | 34 | # 检查 server 是否仍在运行 35 | if kill -0 $server_pid ; then 36 | echo "Project run successfully: $project" 37 | echo "---------------------------------------" 38 | else 39 | echo "Project failed to run: $project" 40 | echo "---------------------------------------" 41 | status=1 42 | fi 43 | 44 | # 杀死 server 45 | kill -9 $server_pid $(lsof -t -i:8888) 46 | 47 | 48 | # 设置脚本的退出状态 49 | exit $status -------------------------------------------------------------------------------- /generic-protobuf/jsonpb-client/README.md: -------------------------------------------------------------------------------- 1 | Example for JSON PB Generic Client. 2 | 3 | Note: Available since `kitex v0.9.0-rc6` -------------------------------------------------------------------------------- /generic-protobuf/jsonpb-client/generate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd `dirname $0` 4 | 5 | kitex=${1:-kitex} 6 | 7 | set -x 8 | 9 | $kitex -module jsonpb-demo -service jsonpb-demo-service idl/api.proto 10 | -------------------------------------------------------------------------------- /generic-protobuf/jsonpb-client/kitex_gen/api/echo/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | 3 | package echo 4 | 5 | import ( 6 | server "github.com/cloudwego/kitex/server" 7 | api "jsonpb-demo/kitex_gen/api" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler api.Echo, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /generic-protobuf/jsonpb-client/kitex_gen/api/echo/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | package echo 3 | 4 | import ( 5 | server "github.com/cloudwego/kitex/server" 6 | api "jsonpb-demo/kitex_gen/api" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler api.Echo, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /generic-protobuf/jsonpb-client/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="generic-protobuf" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 和 client 14 | cd "$REPO_PATH" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 当脚本退出时,停止 server 和 client 20 | trap 'kill $pid ' EXIT 21 | 22 | # 等待 server 和 client 结束 23 | wait $pid -------------------------------------------------------------------------------- /generic-protobuf/jsonpb-client/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="generic-protobuf" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 和 client 16 | 17 | cd "$REPO_PATH" || exit 18 | go run main.go > /dev/null 2>&1 & 19 | pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 和 client 启动 24 | sleep 1 25 | 26 | # 检查 server 和 client 是否仍在运行 27 | if kill -0 $pid ; then 28 | echo "Project run successfully: $project" 29 | echo "---------------------------------------" 30 | else 31 | echo "Project failed to run: $project" 32 | echo "---------------------------------------" 33 | status=1 34 | fi 35 | 36 | # 杀死 server 和 client 37 | kill -9 $pid $(lsof -t -i:8888) 38 | 39 | 40 | # 设置脚本的退出状态 41 | exit $status -------------------------------------------------------------------------------- /generic/binary/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="generic_binary" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /generic/http/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="generic_http" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /generic/json/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="generic_json" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /generic/kitex_gen/http/bizservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.1.4. DO NOT EDIT. 2 | 3 | package bizservice 4 | 5 | import ( 6 | "github.com/cloudwego/kitex-examples/generic/kitex_gen/http" 7 | "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler http.BizService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /generic/kitex_gen/http/bizservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package bizservice 3 | 4 | import ( 5 | http "github.com/cloudwego/kitex-examples/generic/kitex_gen/http" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler http.BizService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler http.BizService, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /generic/kitex_gen/http/k-consts.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /generic/map/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="generic_map" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /generic_streaming/pb/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="StreamingService" 3 | 4 | mkdir -p output/bin 5 | cp script/* output/ 6 | chmod +x output/bootstrap.sh 7 | 8 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 9 | go build -o output/bin/${RUN_NAME} 10 | else 11 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 12 | fi 13 | -------------------------------------------------------------------------------- /generic_streaming/pb/kitex_gen/pb/streamingservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.13.1. DO NOT EDIT. 2 | package streamingservice 3 | 4 | import ( 5 | server "github.com/cloudwego/kitex/server" 6 | pb "pb_generic_streaming_demo/kitex_gen/pb" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler pb.StreamingService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | 22 | func RegisterService(svr server.Server, handler pb.StreamingService, opts ...server.RegisterOption) error { 23 | return svr.RegisterService(serviceInfo(), handler, opts...) 24 | } 25 | -------------------------------------------------------------------------------- /generic_streaming/pb/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'StreamingService' 3 | ToolVersion: 'v0.13.1' 4 | -------------------------------------------------------------------------------- /generic_streaming/pb/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Start server 4 | echo "Starting server..." 5 | go run . & 6 | SERVER_PID=$! 7 | 8 | # Wait for server to start 9 | sleep 2 10 | 11 | # Run client 12 | echo "Running client..." 13 | cd client 14 | go run main.go 15 | 16 | # Cleanup 17 | kill -9 $SERVER_PID $(lsof -t -i:8888) 2>/dev/null || true -------------------------------------------------------------------------------- /generic_streaming/pb/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | CURDIR=$(cd $(dirname $0); pwd) 3 | 4 | if [ "X$1" != "X" ]; then 5 | RUNTIME_ROOT=$1 6 | else 7 | RUNTIME_ROOT=${CURDIR} 8 | fi 9 | 10 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 11 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 12 | 13 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 14 | mkdir -p "$KITEX_LOG_DIR/app" 15 | fi 16 | 17 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 18 | mkdir -p "$KITEX_LOG_DIR/rpc" 19 | fi 20 | 21 | exec "$CURDIR/bin/StreamingService" 22 | -------------------------------------------------------------------------------- /generic_streaming/thrift/kitex_gen/echo/k-consts.go: -------------------------------------------------------------------------------- 1 | package echo 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /generic_streaming/thrift/kitex_gen/echo/testservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.13.1. DO NOT EDIT. 2 | package testservice 3 | 4 | import ( 5 | echo "generic_streaming_demo_thrift/kitex_gen/echo" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler echo.TestService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler echo.TestService, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /generic_streaming/thrift/rpc/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="test" 3 | 4 | mkdir -p output/bin 5 | cp script/* output/ 6 | chmod +x output/bootstrap.sh 7 | 8 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 9 | go build -o output/bin/${RUN_NAME} 10 | else 11 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 12 | fi 13 | -------------------------------------------------------------------------------- /generic_streaming/thrift/rpc/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'test' 3 | ToolVersion: 'v0.13.1' 4 | -------------------------------------------------------------------------------- /generic_streaming/thrift/rpc/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | CURDIR=$(cd $(dirname $0); pwd) 3 | 4 | if [ "X$1" != "X" ]; then 5 | RUNTIME_ROOT=$1 6 | else 7 | RUNTIME_ROOT=${CURDIR} 8 | fi 9 | 10 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 11 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 12 | 13 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 14 | mkdir -p "$KITEX_LOG_DIR/app" 15 | fi 16 | 17 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 18 | mkdir -p "$KITEX_LOG_DIR/rpc" 19 | fi 20 | 21 | exec "$CURDIR/bin/test" 22 | -------------------------------------------------------------------------------- /generic_streaming/thrift/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | project="generic-streaming-thrift" 4 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 | 6 | echo "---------------------------------------" 7 | echo "Running project: $project" 8 | 9 | # Start server 10 | cd "$SCRIPT_DIR/rpc" 11 | go run . & 12 | pid=$! 13 | cd "$SCRIPT_DIR" 14 | 15 | # Wait for server to start 16 | echo "Waiting for server to start..." 17 | sleep 5 18 | 19 | # Check if server is still running 20 | if ! ps -p $pid > /dev/null; then 21 | echo "Error: Server failed to start" 22 | exit 1 23 | fi 24 | 25 | # Run client 26 | echo "Running client..." 27 | cd "$SCRIPT_DIR/client" 28 | go run main.go 29 | cd "$SCRIPT_DIR" 30 | 31 | # Stop server when script exits 32 | trap 'kill $pid 2>/dev/null || true' EXIT 33 | 34 | # Wait for server to finish 35 | wait $pid -------------------------------------------------------------------------------- /goroutine-local-storage/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="goroutine-local-storage" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /governance/circuitbreak/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="governance-circuitbreak" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 21 | trap 'kill $server_pid ' EXIT 22 | 23 | # 等待 server 24 | wait $server_pid -------------------------------------------------------------------------------- /governance/circuitbreak/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="governance-circuitbreak" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 3 25 | 26 | # 检查 server 和 client 是否仍在运行 27 | if kill -0 $server_pid ; then 28 | echo "Project run successfully: $project" 29 | echo "---------------------------------------" 30 | else 31 | echo "Project failed to run: $project" 32 | echo "---------------------------------------" 33 | status=1 34 | fi 35 | 36 | # 杀死 server 和 client 37 | kill -9 $server_pid $(lsof -t -i:8888) 38 | 39 | 40 | # 设置脚本的退出状态 41 | exit $status -------------------------------------------------------------------------------- /governance/limit/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="governance-limit" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 21 | trap 'kill $server_pid ' EXIT 22 | 23 | # 等待 server 24 | wait $server_pid -------------------------------------------------------------------------------- /governance/limit/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="governance-limit" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run main.go > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | # 检查 server 和 client 是否仍在运行 27 | if kill -0 $server_pid ; then 28 | echo "Project run successfully: $project" 29 | echo "---------------------------------------" 30 | else 31 | echo "Project failed to run: $project" 32 | echo "---------------------------------------" 33 | status=1 34 | fi 35 | 36 | # 杀死 server 和 client 37 | kill -9 $server_pid $(lsof -t -i:8888) 38 | 39 | 40 | # 设置脚本的退出状态 41 | exit $status -------------------------------------------------------------------------------- /governance/retry/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="governance-retry" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | cd - > /dev/null || exit 23 | 24 | # 当脚本退出时,停止 server 25 | trap 'kill $server_pid' EXIT 26 | 27 | # 等待 server 结束 28 | wait $server_pid -------------------------------------------------------------------------------- /governance/timeout/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="governance-timeout" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /grpc_multi_service/client/kitex_gen/multi/service/servicea/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | 3 | package servicea 4 | 5 | import ( 6 | server "github.com/cloudwego/kitex/server" 7 | service "grpc_multi_service_client/kitex_gen/multi/service" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler service.ServiceA, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /grpc_multi_service/client/kitex_gen/multi/service/servicea/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | package servicea 3 | 4 | import ( 5 | server "github.com/cloudwego/kitex/server" 6 | service "grpc_multi_service_client/kitex_gen/multi/service" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler service.ServiceA, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /grpc_multi_service/client/kitex_gen/multi/service/serviceb/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | 3 | package serviceb 4 | 5 | import ( 6 | server "github.com/cloudwego/kitex/server" 7 | service "grpc_multi_service_client/kitex_gen/multi/service" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler service.ServiceB, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /grpc_multi_service/client/kitex_gen/multi/service/serviceb/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.8.0. DO NOT EDIT. 2 | package serviceb 3 | 4 | import ( 5 | server "github.com/cloudwego/kitex/server" 6 | service "grpc_multi_service_client/kitex_gen/multi/service" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler service.ServiceB, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /grpc_multi_service/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | project="grpc_multi_service" 8 | 9 | echo "---------------------------------------" 10 | echo "Running project: $project" 11 | 12 | # Start server 13 | echo "Starting server..." 14 | cd "$REPO_PATH/server" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # Wait for server to start 20 | sleep 1 21 | 22 | # Check if server is still running 23 | if ! kill -0 $server_pid 2>/dev/null; then 24 | echo "Error: Server failed to start" 25 | exit 1 26 | fi 27 | echo "Server started successfully (PID: $server_pid)" 28 | 29 | # Run client 30 | echo "Running client..." 31 | cd "$REPO_PATH/client" || exit 32 | go run main.go 33 | client_status=$? 34 | cd - > /dev/null || exit 35 | 36 | # Cleanup processes 37 | kill -9 $server_pid $(lsof -t -i:8888) 38 | 39 | # Set script exit status 40 | exit $client_status -------------------------------------------------------------------------------- /grpc_multi_service/server/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="multiservice" 3 | 4 | mkdir -p output/bin 5 | cp script/* output/ 6 | chmod +x output/bootstrap.sh 7 | 8 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 9 | go build -o output/bin/${RUN_NAME} 10 | else 11 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 12 | fi 13 | 14 | -------------------------------------------------------------------------------- /grpc_multi_service/server/kitex_gen/multi/service/servicea/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.0. DO NOT EDIT. 2 | 3 | package servicea 4 | 5 | import ( 6 | server "github.com/cloudwego/kitex/server" 7 | service "grpc_multi_service/kitex_gen/multi/service" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler service.ServiceA, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /grpc_multi_service/server/kitex_gen/multi/service/servicea/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.0. DO NOT EDIT. 2 | package servicea 3 | 4 | import ( 5 | server "github.com/cloudwego/kitex/server" 6 | service "grpc_multi_service/kitex_gen/multi/service" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler service.ServiceA, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | 22 | func RegisterService(svr server.Server, handler service.ServiceA, opts ...server.RegisterOption) error { 23 | return svr.RegisterService(serviceInfo(), handler, opts...) 24 | } 25 | -------------------------------------------------------------------------------- /grpc_multi_service/server/kitex_gen/multi/service/serviceb/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.0. DO NOT EDIT. 2 | 3 | package serviceb 4 | 5 | import ( 6 | server "github.com/cloudwego/kitex/server" 7 | service "grpc_multi_service/kitex_gen/multi/service" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler service.ServiceB, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /grpc_multi_service/server/kitex_gen/multi/service/serviceb/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.0. DO NOT EDIT. 2 | package serviceb 3 | 4 | import ( 5 | server "github.com/cloudwego/kitex/server" 6 | service "grpc_multi_service/kitex_gen/multi/service" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler service.ServiceB, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | 22 | func RegisterService(svr server.Server, handler service.ServiceB, opts ...server.RegisterOption) error { 23 | return svr.RegisterService(serviceInfo(), handler, opts...) 24 | } 25 | -------------------------------------------------------------------------------- /grpc_multi_service/server/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'multiservice' 3 | ToolVersion: 'v0.8.0' 4 | 5 | -------------------------------------------------------------------------------- /grpc_multi_service/server/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | CURDIR=$(cd $(dirname $0); pwd) 3 | 4 | if [ "X$1" != "X" ]; then 5 | RUNTIME_ROOT=$1 6 | else 7 | RUNTIME_ROOT=${CURDIR} 8 | fi 9 | 10 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 11 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 12 | 13 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 14 | mkdir -p "$KITEX_LOG_DIR/app" 15 | fi 16 | 17 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 18 | mkdir -p "$KITEX_LOG_DIR/rpc" 19 | fi 20 | 21 | exec "$CURDIR/bin/multiservice" 22 | 23 | -------------------------------------------------------------------------------- /grpcproxy/kitex_gen/grpcproxy/servicea/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.3.2. DO NOT EDIT. 2 | 3 | package servicea 4 | 5 | import ( 6 | "github.com/cloudwego/kitex-examples/grpcproxy/kitex_gen/grpcproxy" 7 | "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler grpcproxy.ServiceA, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /grpcproxy/kitex_gen/grpcproxy/servicea/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.3.2. DO NOT EDIT. 2 | package servicea 3 | 4 | import ( 5 | "github.com/cloudwego/kitex-examples/grpcproxy/kitex_gen/grpcproxy" 6 | "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler grpcproxy.ServiceA, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /grpcproxy/kitex_gen/grpcproxy/serviceproxy/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.3.2. DO NOT EDIT. 2 | 3 | package serviceproxy 4 | 5 | import ( 6 | "github.com/cloudwego/kitex-examples/grpcproxy/kitex_gen/grpcproxy" 7 | "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler grpcproxy.ServiceProxy, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /grpcproxy/kitex_gen/grpcproxy/serviceproxy/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.3.2. DO NOT EDIT. 2 | package serviceproxy 3 | 4 | import ( 5 | "github.com/cloudwego/kitex-examples/grpcproxy/kitex_gen/grpcproxy" 6 | "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler grpcproxy.ServiceProxy, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /grpcproxy/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="grpc_proxy" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 和 client 14 | cd "$REPO_PATH" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 和 client 21 | trap 'kill $pid' EXIT 22 | 23 | # 等待 server 和 client 结束 24 | wait $pid -------------------------------------------------------------------------------- /grpcproxy/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="grpc_proxy" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 和 client 16 | 17 | cd "$REPO_PATH" || exit 18 | go run main.go > /dev/null 2>&1 & 19 | pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 和 client 启动 24 | sleep 1 25 | 26 | 27 | # 检查 server 和 client 是否仍在运行 28 | if kill -0 $pid ; then 29 | echo "Project run successfully: $project" 30 | echo "---------------------------------------" 31 | else 32 | echo "Project failed to run: $project" 33 | echo "---------------------------------------" 34 | status=1 35 | fi 36 | 37 | # 杀死 server 和 client 38 | kill -9 $pid $(lsof -t -i:8888) 39 | 40 | 41 | # 设置脚本的退出状态 42 | exit $status -------------------------------------------------------------------------------- /hello/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="a.b.c" 3 | 4 | mkdir -p output/bin output/conf 5 | cp script/* output/ 6 | cp conf/* output/conf/ 7 | chmod +x output/bootstrap.sh 8 | 9 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 10 | go build -o output/bin/${RUN_NAME} 11 | else 12 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 13 | fi -------------------------------------------------------------------------------- /hello/conf/kitex.yml: -------------------------------------------------------------------------------- 1 | Address: ":8888" 2 | EnableDebugServer: true 3 | DebugServerPort: "18888" 4 | Log: 5 | Dir: log 6 | Loggers: 7 | - Name: default 8 | Level: info # Notice: change it to debug if needed in local development 9 | Outputs: 10 | - File 11 | - Agent 12 | # - Console # Notice: change it to debug if needed in local development, don't use this in production! 13 | - Name: rpcAccess 14 | Level: trace # Notice: Not recommended for modification, otherwise may affect construction of call chain (tracing) 15 | Outputs: 16 | - File 17 | - Agent 18 | - Name: rpcCall 19 | Level: trace # Notice: Not recommended for modification, otherwise may affect construction of call chain (tracing) 20 | Outputs: 21 | - File 22 | - Agent -------------------------------------------------------------------------------- /hello/hello.thrift: -------------------------------------------------------------------------------- 1 | // Copyright 2021 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | namespace go api 17 | 18 | struct Request { 19 | 1: string message 20 | } 21 | 22 | struct Response { 23 | 1: string message 24 | } 25 | 26 | service Hello { 27 | Response echo(1: Request req) 28 | } 29 | -------------------------------------------------------------------------------- /hello/kitex_gen/api/hello/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.1.4. DO NOT EDIT. 2 | 3 | package hello 4 | 5 | import ( 6 | "github.com/cloudwego/kitex-examples/hello/kitex_gen/api" 7 | "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler api.Hello, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /hello/kitex_gen/api/hello/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package hello 3 | 4 | import ( 5 | api "github.com/cloudwego/kitex-examples/hello/kitex_gen/api" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler api.Hello, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler api.Hello, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /hello/kitex_gen/api/k-consts.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /hello/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package main 17 | 18 | import ( 19 | "log" 20 | 21 | api "github.com/cloudwego/kitex-examples/hello/kitex_gen/api/hello" 22 | ) 23 | 24 | func main() { 25 | svr := api.NewServer(new(HelloImpl)) 26 | 27 | err := svr.Run() 28 | if err != nil { 29 | log.Println(err.Error()) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /hello/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="hello" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /hello/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | export PSM=${PSM:-a.b.c} 3 | CURDIR=$(cd $(dirname $0); pwd) 4 | 5 | if [ "X$1" != "X" ]; then 6 | RUNTIME_ROOT=$1 7 | else 8 | RUNTIME_ROOT=${CURDIR} 9 | fi 10 | 11 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 12 | export KITEX_CONF_FILE="kitex.yml" 13 | export KITEX_CONF_DIR="$CURDIR/conf" 14 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 15 | 16 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 17 | mkdir -p "$KITEX_LOG_DIR/app" 18 | fi 19 | 20 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 21 | mkdir -p "$KITEX_LOG_DIR/rpc" 22 | fi 23 | 24 | exec "$CURDIR/bin/a.b.c" -------------------------------------------------------------------------------- /hello/script/settings.py: -------------------------------------------------------------------------------- 1 | PRODUCT="a" 2 | SUBSYSTEM="b" 3 | MODULE="c" 4 | APP_TYPE="binary" 5 | -------------------------------------------------------------------------------- /istio/.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | -------------------------------------------------------------------------------- /istio/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="a.b.c" 3 | 4 | mkdir -p output/bin output/conf 5 | cp script/* output/ 6 | cp conf/* output/conf/ 7 | chmod +x output/bootstrap.sh 8 | 9 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 10 | go build -o output/bin/${RUN_NAME} 11 | else 12 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 13 | fi -------------------------------------------------------------------------------- /istio/conf/kitex.yml: -------------------------------------------------------------------------------- 1 | Address: ":8888" 2 | EnableDebugServer: true 3 | DebugServerPort: "18888" 4 | Log: 5 | Dir: log 6 | Loggers: 7 | - Name: default 8 | Level: info # Notice: change it to debug if needed in local development 9 | Outputs: 10 | - File 11 | - Agent 12 | # - Console # Notice: change it to debug if needed in local development, don't use this in production! 13 | - Name: rpcAccess 14 | Level: trace # Notice: Not recommended for modification, otherwise may affect construction of call chain (tracing) 15 | Outputs: 16 | - File 17 | - Agent 18 | - Name: rpcCall 19 | Level: trace # Notice: Not recommended for modification, otherwise may affect construction of call chain (tracing) 20 | Outputs: 21 | - File 22 | - Agent -------------------------------------------------------------------------------- /istio/hello.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2024 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | syntax = "proto3"; 17 | 18 | option go_package = "/hello"; 19 | 20 | message Request { string message = 1; } 21 | 22 | message Response { string message = 1; } 23 | 24 | service Hello { rpc Echo(Request) returns (Response); } 25 | -------------------------------------------------------------------------------- /istio/kitex_gen/hello/hello/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.1. DO NOT EDIT. 2 | 3 | package hello 4 | 5 | import ( 6 | hello "github.com/cloudwego/kitex-examples/istio/kitex_gen/hello" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler hello.Hello, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /istio/kitex_gen/hello/hello/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.1. DO NOT EDIT. 2 | package hello 3 | 4 | import ( 5 | hello "github.com/cloudwego/kitex-examples/istio/kitex_gen/hello" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler hello.Hello, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | 22 | func RegisterService(svr server.Server, handler hello.Hello, opts ...server.RegisterOption) error { 23 | return svr.RegisterService(serviceInfo(), handler, opts...) 24 | } 25 | -------------------------------------------------------------------------------- /istio/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'Hello' 3 | ToolVersion: 'v0.9.1' 4 | -------------------------------------------------------------------------------- /istio/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="hello" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /istio/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | export PSM=${PSM:-a.b.c} 3 | CURDIR=$(cd $(dirname $0); pwd) 4 | 5 | if [ "X$1" != "X" ]; then 6 | RUNTIME_ROOT=$1 7 | else 8 | RUNTIME_ROOT=${CURDIR} 9 | fi 10 | 11 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 12 | export KITEX_CONF_FILE="kitex.yml" 13 | export KITEX_CONF_DIR="$CURDIR/conf" 14 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 15 | 16 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 17 | mkdir -p "$KITEX_LOG_DIR/app" 18 | fi 19 | 20 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 21 | mkdir -p "$KITEX_LOG_DIR/rpc" 22 | fi 23 | 24 | exec "$CURDIR/bin/a.b.c" -------------------------------------------------------------------------------- /istio/script/settings.py: -------------------------------------------------------------------------------- 1 | PRODUCT="a" 2 | SUBSYSTEM="b" 3 | MODULE="c" 4 | APP_TYPE="binary" 5 | -------------------------------------------------------------------------------- /istio/server/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package main 17 | 18 | import ( 19 | "log" 20 | 21 | api "github.com/cloudwego/kitex-examples/istio/kitex_gen/hello/hello" 22 | ) 23 | 24 | func main() { 25 | svr := api.NewServer(new(HelloImpl)) 26 | 27 | err := svr.Run() 28 | if err != nil { 29 | log.Println(err.Error()) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /istio/yaml/client.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: hello-client 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: hello-client 10 | version: v1 11 | strategy: 12 | rollingUpdate: 13 | maxSurge: 25% 14 | maxUnavailable: 25% 15 | type: RollingUpdate 16 | template: 17 | metadata: 18 | creationTimestamp: null 19 | labels: 20 | app: hello-client 21 | version: v1 22 | sidecar.istio.io/inject: "true" 23 | spec: 24 | containers: 25 | - image: mse-cn-beijing.cr.volces.com/demo/hello:v0.0.1 26 | imagePullPolicy: Always 27 | command: 28 | - ./client 29 | name: c0 30 | env: 31 | - name: SERVICE_NAME 32 | value: hello 33 | -------------------------------------------------------------------------------- /kitex/protobuf/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="hello" 3 | 4 | mkdir -p output/bin 5 | cp script/* output/ 6 | chmod +x output/bootstrap.sh 7 | 8 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 9 | go build -o output/bin/${RUN_NAME} 10 | else 11 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 12 | fi 13 | 14 | -------------------------------------------------------------------------------- /kitex/protobuf/handler.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | hello "kitex-examples/kitex/protobuf/kitex_gen/hello" 7 | ) 8 | 9 | // HelloServiceImpl implements the last service interface defined in the IDL. 10 | type HelloServiceImpl struct{} 11 | 12 | // Hello implements the HelloServiceImpl interface. 13 | func (s *HelloServiceImpl) Hello(ctx context.Context, req *hello.HelloReq) (resp *hello.HelloResp, err error) { 14 | resp = new(hello.HelloResp) 15 | resp.RespBody = "hello " + req.Name 16 | return 17 | } 18 | -------------------------------------------------------------------------------- /kitex/protobuf/idl/hello.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package hello; 4 | 5 | option go_package = "hello"; 6 | 7 | message HelloReq { 8 | string Name = 1; 9 | } 10 | 11 | message HelloResp { 12 | string RespBody = 1; 13 | } 14 | 15 | message ByeReq { 16 | string Name = 1; 17 | } 18 | 19 | message ByeResp { 20 | string RespBody = 1; 21 | } 22 | 23 | service HelloService { 24 | rpc Hello(HelloReq) returns(HelloResp); 25 | rpc Bye(ByeReq) returns(ByeResp); 26 | } -------------------------------------------------------------------------------- /kitex/protobuf/kitex_gen/hello/helloservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.7.3. DO NOT EDIT. 2 | 3 | package helloservice 4 | 5 | import ( 6 | server "github.com/cloudwego/kitex/server" 7 | hello "kitex-examples/kitex/protobuf/kitex_gen/hello" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler hello.HelloService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /kitex/protobuf/kitex_gen/hello/helloservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.7.3. DO NOT EDIT. 2 | package helloservice 3 | 4 | import ( 5 | server "github.com/cloudwego/kitex/server" 6 | hello "kitex-examples/kitex/protobuf/kitex_gen/hello" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler hello.HelloService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /kitex/protobuf/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'hello' 3 | ToolVersion: 'v0.7.3' 4 | 5 | -------------------------------------------------------------------------------- /kitex/protobuf/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | hello "kitex-examples/kitex/protobuf/kitex_gen/hello/helloservice" 7 | ) 8 | 9 | func main() { 10 | svr := hello.NewServer(new(HelloServiceImpl)) 11 | 12 | err := svr.Run() 13 | if err != nil { 14 | log.Println(err.Error()) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /kitex/protobuf/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="kitex_protobuf" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 当脚本退出时,停止 server 20 | trap 'kill $server_pid' EXIT 21 | 22 | # 等待 server 结束 23 | wait $server_pid -------------------------------------------------------------------------------- /kitex/protobuf/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | CURDIR=$(cd $(dirname $0); pwd) 3 | 4 | if [ "X$1" != "X" ]; then 5 | RUNTIME_ROOT=$1 6 | else 7 | RUNTIME_ROOT=${CURDIR} 8 | fi 9 | 10 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 11 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 12 | 13 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 14 | mkdir -p "$KITEX_LOG_DIR/app" 15 | fi 16 | 17 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 18 | mkdir -p "$KITEX_LOG_DIR/rpc" 19 | fi 20 | 21 | exec "$CURDIR/bin/hello" 22 | 23 | -------------------------------------------------------------------------------- /kitex/protobuf/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="kitex_protobuf" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | 27 | # 检查 server 是否仍在运行 28 | if kill -0 $server_pid ; then 29 | echo "Project run successfully: $project" 30 | echo "---------------------------------------" 31 | else 32 | echo "Project failed to run: $project" 33 | echo "---------------------------------------" 34 | status=1 35 | fi 36 | 37 | # 杀死 server 38 | kill -9 $server_pid $(lsof -t -i:8888) 39 | 40 | 41 | # 设置脚本的退出状态 42 | exit $status -------------------------------------------------------------------------------- /kitex/template/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | *.so 4 | _obj 5 | _test 6 | *.[568vq] 7 | [568vq].out 8 | *.cgo1.go 9 | *.cgo2.c 10 | _cgo_defun.c 11 | _cgo_gotypes.go 12 | _cgo_export.* 13 | _testmain.go 14 | *.exe 15 | *.exe~ 16 | *.test 17 | *.prof 18 | *.rar 19 | *.zip 20 | *.gz 21 | *.psd 22 | *.bmd 23 | *.cfg 24 | *.pptx 25 | *.log 26 | *nohup.out 27 | *settings.pyc 28 | *.sublime-project 29 | *.sublime-workspace 30 | !.gitkeep 31 | .DS_Store 32 | /.idea 33 | /.vscode 34 | /output 35 | *.local.yml -------------------------------------------------------------------------------- /kitex/template/biz/dal/init.go: -------------------------------------------------------------------------------- 1 | package dal 2 | 3 | import ( 4 | "github.com/kitex/hello/biz/dal/mysql" 5 | "github.com/kitex/hello/biz/dal/redis" 6 | ) 7 | 8 | func Init() { 9 | redis.Init() 10 | mysql.Init() 11 | } 12 | -------------------------------------------------------------------------------- /kitex/template/biz/dal/mysql/init.go: -------------------------------------------------------------------------------- 1 | package mysql 2 | 3 | import ( 4 | "github.com/kitex/hello/conf" 5 | 6 | "gorm.io/driver/mysql" 7 | "gorm.io/gorm" 8 | ) 9 | 10 | var ( 11 | DB *gorm.DB 12 | err error 13 | ) 14 | 15 | func Init() { 16 | DB, err = gorm.Open(mysql.Open(conf.GetConf().MySQL.DSN), 17 | &gorm.Config{ 18 | PrepareStmt: true, 19 | SkipDefaultTransaction: true, 20 | }, 21 | ) 22 | if err != nil { 23 | panic(err) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /kitex/template/biz/dal/redis/init.go: -------------------------------------------------------------------------------- 1 | package redis 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/kitex/hello/conf" 7 | "github.com/redis/go-redis/v9" 8 | ) 9 | 10 | var RedisClient *redis.Client 11 | 12 | func Init() { 13 | RedisClient = redis.NewClient(&redis.Options{ 14 | Addr: conf.GetConf().Redis.Address, 15 | Username: conf.GetConf().Redis.Username, 16 | Password: conf.GetConf().Redis.Password, 17 | DB: conf.GetConf().Redis.DB, 18 | }) 19 | if err := RedisClient.Ping(context.Background()).Err(); err != nil { 20 | panic(err) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /kitex/template/biz/service/hello_method.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | 6 | example "github.com/kitex/hello/kitex_gen/hello/example" 7 | ) 8 | 9 | type HelloMethodService struct { 10 | ctx context.Context 11 | } // NewHelloMethodService new HelloMethodService 12 | func NewHelloMethodService(ctx context.Context) *HelloMethodService { 13 | return &HelloMethodService{ctx: ctx} 14 | } 15 | 16 | // Run create note info 17 | func (s *HelloMethodService) Run(request *example.HelloReq) (resp *example.HelloResp, err error) { 18 | // Finish your business logic. 19 | 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /kitex/template/biz/service/hello_method_test.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "testing" 6 | 7 | example "github.com/kitex/hello/kitex_gen/hello/example" 8 | ) 9 | 10 | func TestHelloMethod_Run(t *testing.T) { 11 | ctx := context.Background() 12 | s := NewHelloMethodService(ctx) 13 | // init req and assert value 14 | 15 | request := &example.HelloReq{} 16 | resp, err := s.Run(request) 17 | t.Logf("err: %v", err) 18 | t.Logf("resp: %v", resp) 19 | 20 | // todo: edit your unit test 21 | } 22 | -------------------------------------------------------------------------------- /kitex/template/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="hello" 3 | mkdir -p output/bin output/conf 4 | cp script/* output/ 5 | cp -r conf/* output/conf 6 | chmod +x output/bootstrap.sh 7 | go build -o output/bin/${RUN_NAME} -------------------------------------------------------------------------------- /kitex/template/conf/dev/conf.yaml: -------------------------------------------------------------------------------- 1 | kitex: 2 | service: "hello" 3 | address: ":8888" 4 | log_level: info 5 | log_file_name: "log/kitex.log" 6 | log_max_size: 10 7 | log_max_age: 3 8 | log_max_backups: 50 9 | 10 | registry: 11 | registry_address: 12 | - 127.0.0.1:2379 13 | username: "" 14 | password: "" 15 | 16 | mysql: 17 | dsn: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8mb4&parseTime=True&loc=Local" 18 | 19 | redis: 20 | address: "127.0.0.1:6379" 21 | username: "" 22 | password: "" 23 | db: 0 -------------------------------------------------------------------------------- /kitex/template/conf/online/conf.yaml: -------------------------------------------------------------------------------- 1 | kitex: 2 | service: "hello" 3 | address: ":8888" 4 | log_level: info 5 | log_file_name: "log/kitex.log" 6 | log_max_size: 10 7 | log_max_age: 3 8 | log_max_backups: 50 9 | 10 | registry: 11 | registry_address: 12 | - 127.0.0.1:2379 13 | username: "" 14 | password: "" 15 | 16 | mysql: 17 | dsn: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8mb4&parseTime=True&loc=Local" 18 | 19 | redis: 20 | address: "127.0.0.1:6379" 21 | username: "" 22 | password: "" 23 | db: 0 -------------------------------------------------------------------------------- /kitex/template/conf/test/conf.yaml: -------------------------------------------------------------------------------- 1 | kitex: 2 | service: "hello" 3 | address: ":8888" 4 | log_level: info 5 | log_file_name: "log/kitex.log" 6 | log_max_size: 10 7 | log_max_age: 3 8 | log_max_backups: 50 9 | 10 | registry: 11 | registry_address: 12 | - 127.0.0.1:2379 13 | username: "" 14 | password: "" 15 | 16 | mysql: 17 | dsn: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8mb4&parseTime=True&loc=Local" 18 | 19 | redis: 20 | address: "127.0.0.1:6379" 21 | username: "" 22 | password: "" 23 | db: 0 -------------------------------------------------------------------------------- /kitex/template/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | mysql: 4 | image: 'mysql:latest' 5 | ports: 6 | - 3306:3306 7 | environment: 8 | - MYSQL_DATABASE=gorm 9 | - MYSQL_USER=gorm 10 | - MYSQL_PASSWORD=gorm 11 | - MYSQL_RANDOM_ROOT_PASSWORD="yes" 12 | redis: 13 | image: 'redis:latest' 14 | ports: 15 | - 6379:6379 -------------------------------------------------------------------------------- /kitex/template/handler.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/kitex/hello/biz/service" 7 | example "github.com/kitex/hello/kitex_gen/hello/example" 8 | ) 9 | 10 | // HelloServiceImpl implements the last service interface defined in the IDL. 11 | type HelloServiceImpl struct{} 12 | 13 | // HelloMethod implements the HelloServiceImpl interface. 14 | func (s *HelloServiceImpl) HelloMethod(ctx context.Context, request *example.HelloReq) (resp *example.HelloResp, err error) { 15 | resp, err = service.NewHelloMethodService(ctx).Run(request) 16 | 17 | return resp, err 18 | } 19 | -------------------------------------------------------------------------------- /kitex/template/idl/hello.thrift: -------------------------------------------------------------------------------- 1 | // idl/hello.proto 2 | namespace go hello.example 3 | 4 | struct HelloReq { 5 | 1: string Name; 6 | } 7 | 8 | struct HelloResp { 9 | 1: string RespBody; 10 | } 11 | 12 | 13 | service HelloService { 14 | HelloResp HelloMethod(1: HelloReq request); 15 | } 16 | -------------------------------------------------------------------------------- /kitex/template/kitex_gen/hello/example/helloservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.7.3. DO NOT EDIT. 2 | 3 | package helloservice 4 | 5 | import ( 6 | server "github.com/cloudwego/kitex/server" 7 | example "github.com/kitex/hello/kitex_gen/hello/example" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler example.HelloService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /kitex/template/kitex_gen/hello/example/helloservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.7.3. DO NOT EDIT. 2 | package helloservice 3 | 4 | import ( 5 | server "github.com/cloudwego/kitex/server" 6 | example "github.com/kitex/hello/kitex_gen/hello/example" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler example.HelloService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /kitex/template/kitex_gen/hello/example/k-consts.go: -------------------------------------------------------------------------------- 1 | package example 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /kitex/template/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'hello' 3 | ToolVersion: 'v0.7.3' -------------------------------------------------------------------------------- /kitex/template/makefile: -------------------------------------------------------------------------------- 1 | init_rpc: 2 | kitex -module github.com/kitex/hello -template-dir template ./idl/hello.thrift 3 | -------------------------------------------------------------------------------- /kitex/template/readme.md: -------------------------------------------------------------------------------- 1 | # Project 2 | 3 | ## introduce 4 | 5 | - Use the [Kitex](https://github.com/cloudwego/kitex/) framework 6 | - Generating the base code for unit tests. 7 | - Provides basic config functions 8 | - Provides the most basic MVC code hierarchy. 9 | 10 | ## Directory structure 11 | 12 | | catalog | introduce | 13 | |-------------|-------------------------------------------------| 14 | | conf | Configuration files | 15 | | main.go | Startup file | 16 | | handler.go | Used for request processing return of response. | 17 | | kitex_gen | kitex generated code | 18 | | biz/service | The actual business logic. | 19 | | biz/dal | Logic for operating the storage layer | 20 | 21 | ## How to run 22 | 23 | ```shell 24 | sh build.sh 25 | sh output/bootstrap.sh 26 | ``` 27 | -------------------------------------------------------------------------------- /kitex/template/readme_zn.md: -------------------------------------------------------------------------------- 1 | # *** 项目 2 | 3 | ## 介绍 4 | 5 | - 使用[Kitex](https://github.com/cloudwego/kitex/)框架 6 | - 生成单元测试的基本代码。 7 | - 提供基本的配置功能 8 | - 提供最基本的MVC代码层次结构。 9 | 10 | ## 目录结构 11 | 12 | | 目录 | 介绍 | 13 | |-------------|-------------| 14 | | conf | 配置文件 | 15 | | main.go | 启动文件 | 16 | | handler.go | 用于请求处理返回响应。 | 17 | | kitex_gen | kitex 生成的代码 | 18 | | biz/service | 实际的业务逻辑。 | 19 | | biz/dal | 存储层操作逻辑 | 20 | 21 | ## 如何运行 22 | 23 | ````外壳 24 | sh build.sh 25 | sh output/bootstrap.sh 26 | ```` -------------------------------------------------------------------------------- /kitex/template/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="kitex_template" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 当脚本退出时,停止 server 20 | trap 'kill $server_pid' EXIT 21 | 22 | # 等待 server 结束 23 | wait $server_pid -------------------------------------------------------------------------------- /kitex/template/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | CURDIR=$(cd $(dirname $0); pwd) 3 | echo "$CURDIR/bin/hello" 4 | exec "$CURDIR/bin/hello" -------------------------------------------------------------------------------- /kitex/template/template/bootstrap_sh_tpl.yaml: -------------------------------------------------------------------------------- 1 | path: script/bootstrap.sh 2 | update_behavior: 3 | type: skip 4 | body: |- 5 | #! /usr/bin/env bash 6 | CURDIR=$(cd $(dirname $0); pwd) 7 | echo "$CURDIR/bin/hello" 8 | exec "$CURDIR/bin/hello" -------------------------------------------------------------------------------- /kitex/template/template/build_sh_tpl.yaml: -------------------------------------------------------------------------------- 1 | path: build.sh 2 | update_behavior: 3 | type: skip 4 | body: |- 5 | #!/usr/bin/env bash 6 | RUN_NAME="hello" 7 | mkdir -p output/bin output/conf 8 | cp script/* output/ 9 | cp -r conf/* output/conf 10 | chmod +x output/bootstrap.sh 11 | go build -o output/bin/${RUN_NAME} 12 | -------------------------------------------------------------------------------- /kitex/template/template/conf_dev_tpl.yaml: -------------------------------------------------------------------------------- 1 | path: conf/dev/conf.yaml 2 | update_behavior: 3 | type: skip 4 | body: |- 5 | kitex: 6 | service: "hello" 7 | address: ":8888" 8 | log_level: info 9 | log_file_name: "log/kitex.log" 10 | log_max_size: 10 11 | log_max_age: 3 12 | log_max_backups: 50 13 | 14 | registry: 15 | registry_address: 16 | - 127.0.0.1:2379 17 | username: "" 18 | password: "" 19 | 20 | mysql: 21 | dsn: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8mb4&parseTime=True&loc=Local" 22 | 23 | redis: 24 | address: "127.0.0.1:6379" 25 | username: "" 26 | password: "" 27 | db: 0 28 | -------------------------------------------------------------------------------- /kitex/template/template/conf_online_tpl.yaml: -------------------------------------------------------------------------------- 1 | path: conf/online/conf.yaml 2 | update_behavior: 3 | type: skip 4 | body: |- 5 | kitex: 6 | service: "hello" 7 | address: ":8888" 8 | log_level: info 9 | log_file_name: "log/kitex.log" 10 | log_max_size: 10 11 | log_max_age: 3 12 | log_max_backups: 50 13 | 14 | registry: 15 | registry_address: 16 | - 127.0.0.1:2379 17 | username: "" 18 | password: "" 19 | 20 | mysql: 21 | dsn: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8mb4&parseTime=True&loc=Local" 22 | 23 | redis: 24 | address: "127.0.0.1:6379" 25 | username: "" 26 | password: "" 27 | db: 0 28 | -------------------------------------------------------------------------------- /kitex/template/template/conf_test_tpl.yaml: -------------------------------------------------------------------------------- 1 | path: conf/test/conf.yaml 2 | update_behavior: 3 | type: skip 4 | body: |- 5 | kitex: 6 | service: "hello" 7 | address: ":8888" 8 | log_level: info 9 | log_file_name: "log/kitex.log" 10 | log_max_size: 10 11 | log_max_age: 3 12 | log_max_backups: 50 13 | 14 | registry: 15 | registry_address: 16 | - 127.0.0.1:2379 17 | username: "" 18 | password: "" 19 | 20 | mysql: 21 | dsn: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8mb4&parseTime=True&loc=Local" 22 | 23 | redis: 24 | address: "127.0.0.1:6379" 25 | username: "" 26 | password: "" 27 | db: 0 28 | -------------------------------------------------------------------------------- /kitex/template/template/dal_init.yaml: -------------------------------------------------------------------------------- 1 | path: biz/dal/init.go 2 | update_behavior: 3 | type: skip 4 | body: |- 5 | package dal 6 | 7 | import ( 8 | "{{.Module}}/biz/dal/mysql" 9 | "{{.Module}}/biz/dal/redis" 10 | ) 11 | 12 | func Init() { 13 | redis.Init() 14 | mysql.Init() 15 | } -------------------------------------------------------------------------------- /kitex/template/template/docker_compose.yaml: -------------------------------------------------------------------------------- 1 | path: docker-compose.yaml 2 | update_behavior: 3 | type: skip 4 | body: |- 5 | version: '3' 6 | services: 7 | mysql: 8 | image: 'mysql:latest' 9 | ports: 10 | - 3306:3306 11 | environment: 12 | - MYSQL_DATABASE=gorm 13 | - MYSQL_USER=gorm 14 | - MYSQL_PASSWORD=gorm 15 | - MYSQL_RANDOM_ROOT_PASSWORD="yes" 16 | redis: 17 | image: 'redis:latest' 18 | ports: 19 | - 6379:6379 -------------------------------------------------------------------------------- /kitex/template/template/ignore_tpl.yaml: -------------------------------------------------------------------------------- 1 | path: .gitignore 2 | update_behavior: 3 | type: skip 4 | body: |- 5 | *.o 6 | *.a 7 | *.so 8 | _obj 9 | _test 10 | *.[568vq] 11 | [568vq].out 12 | *.cgo1.go 13 | *.cgo2.c 14 | _cgo_defun.c 15 | _cgo_gotypes.go 16 | _cgo_export.* 17 | _testmain.go 18 | *.exe 19 | *.exe~ 20 | *.test 21 | *.prof 22 | *.rar 23 | *.zip 24 | *.gz 25 | *.psd 26 | *.bmd 27 | *.cfg 28 | *.pptx 29 | *.log 30 | *nohup.out 31 | *settings.pyc 32 | *.sublime-project 33 | *.sublime-workspace 34 | !.gitkeep 35 | .DS_Store 36 | /.idea 37 | /.vscode 38 | /output 39 | *.local.yml -------------------------------------------------------------------------------- /kitex/template/template/kitex_yaml.yaml: -------------------------------------------------------------------------------- 1 | path: kitex_info.yaml 2 | update_behavior: 3 | type: cover 4 | body: |- 5 | kitexinfo: 6 | ServiceName: 'hello' 7 | ToolVersion: '{{.Version}}' 8 | -------------------------------------------------------------------------------- /kitex/template/template/mysql.yaml: -------------------------------------------------------------------------------- 1 | path: biz/dal/mysql/init.go 2 | update_behavior: 3 | type: skip 4 | body: |- 5 | package mysql 6 | 7 | import ( 8 | "{{.Module}}/conf" 9 | 10 | "gorm.io/driver/mysql" 11 | "gorm.io/gorm" 12 | ) 13 | 14 | var ( 15 | DB *gorm.DB 16 | err error 17 | ) 18 | 19 | func Init() { 20 | DB, err = gorm.Open(mysql.Open(conf.GetConf().MySQL.DSN), 21 | &gorm.Config{ 22 | PrepareStmt: true, 23 | SkipDefaultTransaction: true, 24 | }, 25 | ) 26 | if err != nil { 27 | panic(err) 28 | } 29 | } -------------------------------------------------------------------------------- /kitex/template/template/readme_tpl.yaml: -------------------------------------------------------------------------------- 1 | path: readme.md 2 | update_behavior: 3 | type: skip 4 | body: |- 5 | # *** Project 6 | 7 | ## introduce 8 | 9 | - Use the [Kitex](https://github.com/cloudwego/kitex/) framework 10 | - Generating the base code for unit tests. 11 | - Provides basic config functions 12 | - Provides the most basic MVC code hierarchy. 13 | 14 | ## Directory structure 15 | 16 | | catalog | introduce | 17 | | ---- | ---- | 18 | | conf | Configuration files | 19 | | main.go | Startup file | 20 | | handler.go | Used for request processing return of response. | 21 | | kitex_gen | kitex generated code | 22 | | biz/service | The actual business logic. | 23 | | biz/dal | Logic for operating the storage layer | 24 | 25 | ## How to run 26 | 27 | ```shell 28 | sh build.sh 29 | sh output/bootstrap.sh 30 | ``` -------------------------------------------------------------------------------- /kitex/template/template/redis.yaml: -------------------------------------------------------------------------------- 1 | path: biz/dal/redis/init.go 2 | update_behavior: 3 | type: skip 4 | body: |- 5 | package redis 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/redis/go-redis/v9" 11 | "{{.Module}}/conf" 12 | ) 13 | 14 | var ( 15 | RedisClient *redis.Client 16 | ) 17 | 18 | func Init() { 19 | RedisClient = redis.NewClient(&redis.Options{ 20 | Addr: conf.GetConf().Redis.Address, 21 | Username: conf.GetConf().Redis.Username, 22 | Password: conf.GetConf().Redis.Password, 23 | DB: conf.GetConf().Redis.DB, 24 | }) 25 | if err := RedisClient.Ping(context.Background()).Err(); err != nil { 26 | panic(err) 27 | } 28 | } -------------------------------------------------------------------------------- /kitex/template/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="kitex_template" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | 27 | # 检查 server 是否仍在运行 28 | if kill -0 $server_pid ; then 29 | echo "Project run successfully: $project" 30 | echo "---------------------------------------" 31 | else 32 | echo "Project failed to run: $project" 33 | echo "---------------------------------------" 34 | status=1 35 | fi 36 | 37 | # 杀死 server 38 | kill -9 $server_pid $(lsof -t -i:8888) 39 | 40 | 41 | # 设置脚本的退出状态 42 | exit $status -------------------------------------------------------------------------------- /kitex/thrift/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="hello" 3 | 4 | mkdir -p output/bin 5 | cp script/* output/ 6 | chmod +x output/bootstrap.sh 7 | 8 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 9 | go build -o output/bin/${RUN_NAME} 10 | else 11 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 12 | fi 13 | -------------------------------------------------------------------------------- /kitex/thrift/handler.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | example "kitex-examples/kitex/thrift/kitex_gen/hello/example" 7 | ) 8 | 9 | // HelloServiceImpl implements the last service interface defined in the IDL. 10 | type HelloServiceImpl struct{} 11 | 12 | // HelloMethod implements the HelloServiceImpl interface. 13 | func (s *HelloServiceImpl) HelloMethod(ctx context.Context, request *example.HelloReq) (resp *example.HelloResp, err error) { 14 | resp = new(example.HelloResp) 15 | resp.RespBody = "hello " + request.Name 16 | return 17 | } 18 | -------------------------------------------------------------------------------- /kitex/thrift/idl/hello.thrift: -------------------------------------------------------------------------------- 1 | // idl/hello.proto 2 | namespace go hello.example 3 | 4 | struct HelloReq { 5 | 1: string Name; 6 | } 7 | 8 | struct HelloResp { 9 | 1: string RespBody; 10 | } 11 | 12 | 13 | service HelloService { 14 | HelloResp HelloMethod(1: HelloReq request); 15 | } 16 | -------------------------------------------------------------------------------- /kitex/thrift/kitex_gen/hello/example/helloservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.7.3. DO NOT EDIT. 2 | 3 | package helloservice 4 | 5 | import ( 6 | server "github.com/cloudwego/kitex/server" 7 | example "kitex-examples/kitex/thrift/kitex_gen/hello/example" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler example.HelloService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /kitex/thrift/kitex_gen/hello/example/helloservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.7.3. DO NOT EDIT. 2 | package helloservice 3 | 4 | import ( 5 | server "github.com/cloudwego/kitex/server" 6 | example "kitex-examples/kitex/thrift/kitex_gen/hello/example" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler example.HelloService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /kitex/thrift/kitex_gen/hello/example/k-consts.go: -------------------------------------------------------------------------------- 1 | package example 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /kitex/thrift/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'hello' 3 | ToolVersion: 'v0.7.3' 4 | -------------------------------------------------------------------------------- /kitex/thrift/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | example "kitex-examples/kitex/thrift/kitex_gen/hello/example/helloservice" 7 | ) 8 | 9 | func main() { 10 | svr := example.NewServer(new(HelloServiceImpl)) 11 | 12 | err := svr.Run() 13 | if err != nil { 14 | log.Println(err.Error()) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /kitex/thrift/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="kitex_thrift" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 当脚本退出时,停止 server 20 | trap 'kill $server_pid' EXIT 21 | 22 | # 等待 server 结束 23 | wait $server_pid -------------------------------------------------------------------------------- /kitex/thrift/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | CURDIR=$(cd $(dirname $0); pwd) 3 | 4 | if [ "X$1" != "X" ]; then 5 | RUNTIME_ROOT=$1 6 | else 7 | RUNTIME_ROOT=${CURDIR} 8 | fi 9 | 10 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 11 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 12 | 13 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 14 | mkdir -p "$KITEX_LOG_DIR/app" 15 | fi 16 | 17 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 18 | mkdir -p "$KITEX_LOG_DIR/rpc" 19 | fi 20 | 21 | exec "$CURDIR/bin/hello" 22 | -------------------------------------------------------------------------------- /kitex/thrift/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="kitex_thrift" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | 27 | # 检查 server 是否仍在运行 28 | if kill -0 $server_pid ; then 29 | echo "Project run successfully: $project" 30 | echo "---------------------------------------" 31 | else 32 | echo "Project failed to run: $project" 33 | echo "---------------------------------------" 34 | status=1 35 | fi 36 | 37 | # 杀死 server 38 | kill -9 $server_pid $(lsof -t -i:8888) 39 | 40 | 41 | # 设置脚本的退出状态 42 | exit $status -------------------------------------------------------------------------------- /kitex_gen/api/echo/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | 3 | package echo 4 | 5 | import ( 6 | api "github.com/cloudwego/kitex-examples/kitex_gen/api" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler api.Echo, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /kitex_gen/api/echo/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package echo 3 | 4 | import ( 5 | api "github.com/cloudwego/kitex-examples/kitex_gen/api" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler api.Echo, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler api.Echo, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /kitex_gen/api/k-consts.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /kitex_gen/pbapi/echo/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.7.1. DO NOT EDIT. 2 | 3 | package echo 4 | 5 | import ( 6 | pbapi "github.com/cloudwego/kitex-examples/kitex_gen/pbapi" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler pbapi.Echo, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /kitex_gen/pbapi/echo/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package echo 3 | 4 | import ( 5 | pbapi "github.com/cloudwego/kitex-examples/kitex_gen/pbapi" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler pbapi.Echo, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | 22 | func RegisterService(svr server.Server, handler pbapi.Echo, opts ...server.RegisterOption) error { 23 | return svr.RegisterService(serviceInfo(), handler, opts...) 24 | } 25 | -------------------------------------------------------------------------------- /kitex_gen/slim/api/echo/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.7.1. DO NOT EDIT. 2 | 3 | package echo 4 | 5 | import ( 6 | api "github.com/cloudwego/kitex-examples/kitex_gen/slim/api" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler api.Echo, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /kitex_gen/slim/api/echo/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package echo 3 | 4 | import ( 5 | api "github.com/cloudwego/kitex-examples/kitex_gen/slim/api" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler api.Echo, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler api.Echo, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /kitex_gen/slim/api/k-consts.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /klog/README_CN.md: -------------------------------------------------------------------------------- 1 | # klog 2 | [English](./README.md) | 中文 3 | 4 | 您可以了解如何使用 Kitex klog 5 | 6 | 1. 默认情况下,默认使用 kitex 实现的 logger。 7 | 默认的 logger 输出也可以使用 `SetOutput` 接口进行重定向,后续的中间件和框架的其他部分可以使用 klog 中的全局方法来输出日志。 8 | 2. Kitex 提供 `SetLogger` 接口来允许注入您自己的 logger。 9 | 10 | ## 接口定义 11 | 12 | Kitex 中,pkg/klog 中定义了 Logger、CtxLogger、FormatLogger 接口,这些接口用于以不同的方式输出日志,并定义了一个 Control 接口来控制 logger。 如果您想注入自己的记录器实现,则必须实现上述所有接口(即 FullLogger)。Kitex 已经提供了 FullLogger 的默认实现。 13 | 14 | ```go 15 | // FullLogger 是 Logger、FormatLogger、CtxLogger 和 Control 的组合。 16 | type FullLogger interface { 17 | Logger 18 | FormatLogger 19 | CtxLogger 20 | Control 21 | } 22 | ```` 23 | 24 | ## 日志扩展 25 | 26 | 扩展提供了 zap 、logrus 和 slog 的使用 27 | 28 | klog 拓展耦合在 otel 的拓展里 29 | 30 | 关于日志扩展的详细信息,[参见](https://cloudwego.cn/zh/docs/kitex/tutorials/observability/logging/) -------------------------------------------------------------------------------- /klog/custom/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="klog_custom" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 21 | trap 'kill $server_pid' EXIT 22 | 23 | # 等待 server 结束 24 | wait $server_pid -------------------------------------------------------------------------------- /klog/custom/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="klog_custom" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | 27 | # 检查 server 是否仍在运行 28 | if kill -0 $server_pid ; then 29 | echo "Project run successfully: $project" 30 | echo "---------------------------------------" 31 | else 32 | echo "Project failed to run: $project" 33 | echo "---------------------------------------" 34 | status=1 35 | fi 36 | 37 | # 杀死 server 38 | kill -9 $server_pid $(lsof -t -i:8888) 39 | 40 | 41 | # 设置脚本的退出状态 42 | exit $status -------------------------------------------------------------------------------- /klog/logrus/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="klog_logrus" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 21 | trap 'kill $server_pid' EXIT 22 | 23 | # 等待 server 结束 24 | wait $server_pid -------------------------------------------------------------------------------- /klog/logrus/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="klog_logrus" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | 27 | # 检查 server 是否仍在运行 28 | if kill -0 $server_pid ; then 29 | echo "Project run successfully: $project" 30 | echo "---------------------------------------" 31 | else 32 | echo "Project failed to run: $project" 33 | echo "---------------------------------------" 34 | status=1 35 | fi 36 | 37 | # 杀死 server 38 | kill -9 $server_pid $(lsof -t -i:8888) 39 | 40 | 41 | # 设置脚本的退出状态 42 | exit $status -------------------------------------------------------------------------------- /klog/slog/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="klog_slog" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 21 | trap 'kill $server_pid' EXIT 22 | 23 | # 等待 server 结束 24 | wait $server_pid -------------------------------------------------------------------------------- /klog/slog/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="klog_slog" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | 27 | # 检查 server 是否仍在运行 28 | if kill -0 $server_pid ; then 29 | echo "Project run successfully: $project" 30 | echo "---------------------------------------" 31 | else 32 | echo "Project failed to run: $project" 33 | echo "---------------------------------------" 34 | status=1 35 | fi 36 | 37 | # 杀死 server 38 | kill -9 $server_pid $(lsof -t -i:8888) 39 | 40 | 41 | # 设置脚本的退出状态 42 | exit $status -------------------------------------------------------------------------------- /klog/standard/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="klog_standard" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 21 | trap 'kill $server_pid' EXIT 22 | 23 | # 等待 server 结束 24 | wait $server_pid -------------------------------------------------------------------------------- /klog/standard/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="klog_standard" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | 27 | # 检查 server 是否仍在运行 28 | if kill -0 $server_pid ; then 29 | echo "Project run successfully: $project" 30 | echo "---------------------------------------" 31 | else 32 | echo "Project failed to run: $project" 33 | echo "---------------------------------------" 34 | status=1 35 | fi 36 | 37 | # 杀死 server 38 | kill -9 $server_pid $(lsof -t -i:8888) 39 | 40 | 41 | # 设置脚本的退出状态 42 | exit $status -------------------------------------------------------------------------------- /klog/zap/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="klog_zap" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH" || exit 15 | go run . > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | 20 | # 当脚本退出时,停止 server 21 | trap 'kill $server_pid' EXIT 22 | 23 | # 等待 server 结束 24 | wait $server_pid -------------------------------------------------------------------------------- /klog/zap/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="klog_zap" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH" || exit 18 | go run . > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | 27 | # 检查 server 是否仍在运行 28 | if kill -0 $server_pid ; then 29 | echo "Project run successfully: $project" 30 | echo "---------------------------------------" 31 | else 32 | echo "Project failed to run: $project" 33 | echo "---------------------------------------" 34 | status=1 35 | fi 36 | 37 | # 杀死 server 38 | kill -9 $server_pid $(lsof -t -i:8888) 39 | 40 | 41 | # 设置脚本的退出状态 42 | exit $status -------------------------------------------------------------------------------- /longconnection/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="longconnection" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /metainfo/backward/README.md: -------------------------------------------------------------------------------- 1 | # Backward Meta Information Transmitting 2 | 3 | ## Running the example 4 | 5 | ### step 1 6 | 7 | ``` 8 | go run server/main.go 9 | ``` 10 | 11 | ### step 2 12 | 13 | ``` 14 | go run client/main.go 15 | ``` 16 | 17 | ## NOTE 18 | 19 | - Must use certain transport protocols that can transmit meta information,such as TTHeader, HTTP. -------------------------------------------------------------------------------- /metainfo/backward/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="metainfo_backward" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /metainfo/forward/README.md: -------------------------------------------------------------------------------- 1 | # Forward Meta Information Transmitting 2 | 3 | ## Running the example 4 | 5 | ### running server-2 6 | 7 | `server-2` will be called by `server-1`, so we must run it firstly. 8 | `server-2` checks the metainfo from `server-1`. 9 | 10 | ``` 11 | go run server-2/main.go 12 | ``` 13 | 14 | ### running server-1 15 | 16 | `server-1` will be called by `client`. 17 | `server-1` checks the metainfo from `client`. 18 | 19 | ``` 20 | go run server-1/main.go 21 | ``` 22 | 23 | ### running client 24 | 25 | run `client`,and set some metainfo into context. 26 | 27 | ``` 28 | go run client/main.go 29 | ``` 30 | 31 | ## NOTE 32 | 33 | - Must use certain transport protocols that can transmit meta information,such as TTHeader, HTTP. -------------------------------------------------------------------------------- /metainfo/forward/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="metainfo_backward" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server2 14 | cd "$REPO_PATH/server-2" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid_1=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 server1 20 | cd "$REPO_PATH/server-1" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | server_pid_2=$! 23 | cd - > /dev/null || exit 24 | 25 | # 启动 client 26 | cd "$REPO_PATH/client" || exit 27 | go run main.go > /dev/null 2>&1 & 28 | client_pid=$! 29 | cd - > /dev/null || exit 30 | 31 | # 当脚本退出时,停止 server 和 client 32 | trap 'kill $server_pid_2 $server_pid_1 $client_pid' EXIT 33 | 34 | # 等待 server 和 client 结束 35 | wait $server_pid_1 $server_pid_2 $client_pid -------------------------------------------------------------------------------- /middleware/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="middleware" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /opentelemetry/client/run.sh: -------------------------------------------------------------------------------- 1 | export OTEL_EXPORTER_OTLP_ENDPOINT=":4317" 2 | export OTEL_EXPORTER_OTLP_PROTOCOL=grpc 3 | export OTEL_EXPORTER_OTLP_HEADERS=authorization="Bearer oidc_token",foo=bar 4 | export OTEL_EXPORTER_OTLP_COMPRESSION=gzip 5 | 6 | go run ./main.go 7 | -------------------------------------------------------------------------------- /opentelemetry/jaeger-arch/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwego/kitex-examples/0f8011b1ef15db252b2bf6ca6e7bd6248da6adaa/opentelemetry/jaeger-arch/img.png -------------------------------------------------------------------------------- /opentelemetry/otel-collector-config.yaml: -------------------------------------------------------------------------------- 1 | receivers: 2 | otlp: 3 | protocols: 4 | grpc: 5 | endpoint: 0.0.0.0:4317 6 | 7 | exporters: 8 | prometheusremotewrite: 9 | endpoint: "http://victoriametrics:8428/api/v1/write" 10 | 11 | debug: 12 | 13 | otlp/jaeger: 14 | endpoint: jaeger-all-in-one:4317 15 | tls: 16 | insecure: true 17 | 18 | processors: 19 | batch: 20 | 21 | extensions: 22 | health_check: 23 | pprof: 24 | endpoint: :1888 25 | zpages: 26 | endpoint: :55679 27 | 28 | service: 29 | extensions: [ pprof, zpages, health_check ] 30 | pipelines: 31 | traces: 32 | receivers: [ otlp ] 33 | processors: [ batch ] 34 | exporters: [ debug, otlp/jaeger ] 35 | metrics: 36 | receivers: [ otlp ] 37 | processors: [ batch ] 38 | exporters: [ debug, prometheusremotewrite ] 39 | -------------------------------------------------------------------------------- /opentelemetry/server/run.sh: -------------------------------------------------------------------------------- 1 | export OTEL_EXPORTER_OTLP_ENDPOINT=":4317" 2 | export OTEL_EXPORTER_OTLP_PROTOCOL=grpc 3 | export OTEL_EXPORTER_OTLP_HEADERS=authorization="Bearer oidc_token",foo=bar 4 | export OTEL_EXPORTER_OTLP_COMPRESSION=gzip 5 | 6 | go run ./main.go -------------------------------------------------------------------------------- /opentelemetry/static/grafana.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwego/kitex-examples/0f8011b1ef15db252b2bf6ca6e7bd6248da6adaa/opentelemetry/static/grafana.png -------------------------------------------------------------------------------- /opentelemetry/static/jaeger-otlp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwego/kitex-examples/0f8011b1ef15db252b2bf6ca6e7bd6248da6adaa/opentelemetry/static/jaeger-otlp.png -------------------------------------------------------------------------------- /opentelemetry/static/jaeger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwego/kitex-examples/0f8011b1ef15db252b2bf6ca6e7bd6248da6adaa/opentelemetry/static/jaeger.png -------------------------------------------------------------------------------- /opentelemetry/static/panel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwego/kitex-examples/0f8011b1ef15db252b2bf6ca6e7bd6248da6adaa/opentelemetry/static/panel.png -------------------------------------------------------------------------------- /profiler/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="profiler" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 和 client 26 | trap 'kill $server_pid $client_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /prometheus/custom/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="prometheus_custom" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 26 | trap 'kill $server_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /prometheus/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | prometheus: 4 | image: prom/prometheus:latest 5 | volumes: 6 | - ./prometheus.yml:/etc/prometheus/prometheus.yml 7 | # - ./alert.rules:/etc/prometheus/alert.rules 8 | - prometheus_data:/prometheus 9 | command: 10 | - "--config.file=/etc/prometheus/prometheus.yml" 11 | ports: 12 | - "9090:9090" 13 | grafana: 14 | image: grafana/grafana:latest 15 | volumes: 16 | - grafana_data:/var/lib/grafana 17 | environment: 18 | - GF_SECURITY_ADMIN_PASSWORD=admin 19 | depends_on: 20 | - prometheus 21 | ports: 22 | - "3000:3000" 23 | volumes: 24 | grafana_data: { } 25 | prometheus_data: { } 26 | -------------------------------------------------------------------------------- /prometheus/simple/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="prometheus_simple" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | client_pid=$! 23 | cd - > /dev/null || exit 24 | 25 | # 当脚本退出时,停止 server 26 | trap 'kill $server_pid' EXIT 27 | 28 | # 等待 server 和 client 结束 29 | wait $server_pid $client_pid -------------------------------------------------------------------------------- /protobuf_multi_service/kitex_gen/multi/service/servicea/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.0. DO NOT EDIT. 2 | 3 | package servicea 4 | 5 | import ( 6 | service "github.com/cloudwego/kitex-examples/protobuf_multi_service/kitex_gen/multi/service" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler service.ServiceA, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /protobuf_multi_service/kitex_gen/multi/service/servicea/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.0. DO NOT EDIT. 2 | package servicea 3 | 4 | import ( 5 | service "github.com/cloudwego/kitex-examples/protobuf_multi_service/kitex_gen/multi/service" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler service.ServiceA, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | 22 | func RegisterService(svr server.Server, handler service.ServiceA, opts ...server.RegisterOption) error { 23 | return svr.RegisterService(serviceInfo(), handler, opts...) 24 | } 25 | -------------------------------------------------------------------------------- /protobuf_multi_service/kitex_gen/multi/service/serviceb/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.0. DO NOT EDIT. 2 | 3 | package serviceb 4 | 5 | import ( 6 | service "github.com/cloudwego/kitex-examples/protobuf_multi_service/kitex_gen/multi/service" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler service.ServiceB, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /protobuf_multi_service/kitex_gen/multi/service/serviceb/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.0. DO NOT EDIT. 2 | package serviceb 3 | 4 | import ( 5 | service "github.com/cloudwego/kitex-examples/protobuf_multi_service/kitex_gen/multi/service" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler service.ServiceB, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | 22 | func RegisterService(svr server.Server, handler service.ServiceB, opts ...server.RegisterOption) error { 23 | return svr.RegisterService(serviceInfo(), handler, opts...) 24 | } 25 | -------------------------------------------------------------------------------- /protobuf_multi_service/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="protobuf_multi_service" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | cd - > /dev/null || exit 23 | 24 | # 当脚本退出时,停止 server 25 | trap 'kill $server_pid' EXIT 26 | 27 | # 等待 server 结束 28 | wait $server_pid -------------------------------------------------------------------------------- /proxyless/cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright 2022 CloudWeGo Authors 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | kubectl delete -f "./yaml/server/kitex_server.yaml" --namespace=proxyless 20 | kubectl delete -f "./yaml/client/kitex_client.yaml" --namespace=proxyless 21 | kubectl delete -f "./yaml/testutil/controller.yaml" --namespace=proxyless 22 | kubectl delete namespace proxyless -------------------------------------------------------------------------------- /proxyless/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright 2022 CloudWeGo Authors 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | kubectl create namespace proxyless 20 | kubectl apply -f "./yaml/server/kitex_server.yaml" --namespace=proxyless 21 | kubectl apply -f "./yaml/client/kitex_client.yaml" --namespace=proxyless 22 | kubectl apply -f "./yaml/testutil/controller.yaml" --namespace=proxyless -------------------------------------------------------------------------------- /proxyless/service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest AS final 2 | 3 | ENV APP_PATH="/app" 4 | WORKDIR "/app" 5 | 6 | # 拷贝程序 7 | COPY output ${APP_PATH} 8 | 9 | RUN pwd 10 | RUN chmod +x ./bootstrap.sh 11 | CMD ["sh","./bootstrap.sh"] -------------------------------------------------------------------------------- /proxyless/service/bootstrap.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2022 CloudWeGo Authors 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | ./bin/kitex -------------------------------------------------------------------------------- /proxyless/service/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright 2022 CloudWeGo Authors 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | set -e 20 | CURDIR=$(cd $(dirname $0); pwd) 21 | 22 | # build 23 | go mod tidy 24 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $CURDIR/output/bin/kitex $CURDIR 25 | #go build -o output/bin/kitex 26 | cp $CURDIR/bootstrap.sh $CURDIR/output/ -------------------------------------------------------------------------------- /proxyless/service/codec/thrift/gen.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2022 CloudWeGo Authors 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | kitex -module github.com/cloudwego/kitex-proxyless-test -service kitex-server idl/greet.thrift -------------------------------------------------------------------------------- /proxyless/service/codec/thrift/kitex_gen/proxyless/greetservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.3.4. DO NOT EDIT. 2 | 3 | package greetservice 4 | 5 | import ( 6 | proxyless "github.com/cloudwego/kitex-examples/proxyless/service/codec/thrift/kitex_gen/proxyless" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler proxyless.GreetService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /proxyless/service/codec/thrift/kitex_gen/proxyless/greetservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.3.4. DO NOT EDIT. 2 | package greetservice 3 | 4 | import ( 5 | proxyless "github.com/cloudwego/kitex-examples/proxyless/service/codec/thrift/kitex_gen/proxyless" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler proxyless.GreetService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /proxyless/service/codec/thrift/kitex_gen/proxyless/k-consts.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 CloudWeGo Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package proxyless 18 | 19 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 20 | var KitexUnusedProtection = struct{}{} 21 | -------------------------------------------------------------------------------- /proxyless/service/src/service.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 CloudWeGo Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package src 18 | 19 | const ( 20 | PodNameKey = "POD_NAME" 21 | ) 22 | 23 | type TestService interface { 24 | Run() error 25 | } 26 | -------------------------------------------------------------------------------- /proxyless/testutil/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | WORKDIR "/app" 3 | COPY output /app 4 | ENTRYPOINT ["./bin/test-controller"] -------------------------------------------------------------------------------- /proxyless/testutil/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright 2022 CloudWeGo Authors 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | # build 20 | go mod tidy 21 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o output/bin/test-controller -------------------------------------------------------------------------------- /proxyless/testutil/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 CloudWeGo Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import "github.com/cloudwego/kitex-examples/proxyless/testutil/testSuite" 20 | 21 | func main() { 22 | tc := testSuite.NewController() 23 | tc.Run() 24 | } 25 | -------------------------------------------------------------------------------- /proxyless/yaml/server/virtualService_default.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.istio.io/v1alpha3 2 | kind: VirtualService 3 | metadata: 4 | name: kitex-server 5 | spec: 6 | hosts: 7 | - kitex-server 8 | http: 9 | - name: "default-route" 10 | route: 11 | - destination: 12 | host: kitex-server 13 | subset: v1 14 | weight: 100 15 | -------------------------------------------------------------------------------- /proxyless/yaml/server/virtualService_match_path.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.istio.io/v1alpha3 2 | kind: VirtualService 3 | metadata: 4 | name: kitex-server 5 | spec: 6 | hosts: 7 | - kitex-server 8 | http: 9 | - name: "route-based-on-path" 10 | match: 11 | - uri: 12 | # /${PackageName}.${ServiceName}/${MethodName} 13 | exact: /proxyless.GreetService/SayHello2 14 | route: 15 | - destination: 16 | host: kitex-server 17 | subset: v2 18 | weight: 100 19 | timeout: 0.5s -------------------------------------------------------------------------------- /proxyless/yaml/server/virtualService_match_tag.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.istio.io/v1alpha3 2 | kind: VirtualService 3 | metadata: 4 | name: kitex-server 5 | spec: 6 | hosts: 7 | - kitex-server 8 | http: 9 | - name: "route-based-on-tags" 10 | match: 11 | - headers: 12 | stage: 13 | exact: "canary" 14 | route: 15 | - destination: 16 | host: kitex-server 17 | subset: v1 18 | weight: 100 19 | timeout: 0.5s -------------------------------------------------------------------------------- /proxyless/yaml/server/virtualService_traffic_split.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.istio.io/v1alpha3 2 | kind: VirtualService 3 | metadata: 4 | name: kitex-server 5 | spec: 6 | hosts: 7 | - kitex-server 8 | http: 9 | - name: "traffic-split-route" 10 | route: 11 | - destination: 12 | host: kitex-server 13 | subset: v1 14 | weight: 90 15 | - destination: 16 | host: kitex-server 17 | subset: v2 18 | weight: 10 19 | -------------------------------------------------------------------------------- /regenerate-dependabot-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function gen_dependabot_config () { 4 | dependabot_config=".github/dependabot.yml" 5 | 6 | mkdir -p .github 7 | { 8 | echo "version: 2" 9 | echo "updates:" 10 | echo " - package-ecosystem: gomod" 11 | echo " schedule:" 12 | echo " interval: weekly" 13 | echo " allow:" 14 | echo " - dependency-name: github.com/cloudwego/kitex" 15 | echo " groups:" 16 | echo " kitex-dependencies:" 17 | echo " patterns:" 18 | echo " - github.com/cloudwego/kitex" 19 | echo " directories:" 20 | } > $dependabot_config 21 | 22 | find . -type d -not -path '*/\.*' | sort | while read -r dir; do 23 | if [ -f "$dir/go.mod" ]; then 24 | dir="${dir/#.//}" 25 | dir="${dir/#\/\///}" 26 | echo " - $dir" >> $dependabot_config 27 | fi 28 | done 29 | } 30 | 31 | gen_dependabot_config 32 | -------------------------------------------------------------------------------- /server_hook/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="server_hook" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 当脚本退出时,停止 server 20 | trap 'kill $server_pid' EXIT 21 | 22 | # 等待 server 结束 23 | wait $server_pid -------------------------------------------------------------------------------- /server_hook/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | status=0 10 | project="server_hook" 11 | 12 | echo "---------------------------------------" 13 | echo "Running project: $project" 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH/server" || exit 18 | go run main.go > /dev/null 2>&1 & 19 | server_pid=$! 20 | cd - > /dev/null || exit 21 | 22 | 23 | # 等待 server 启动 24 | sleep 1 25 | 26 | 27 | # 检查 server 是否仍在运行 28 | if kill -0 $server_pid ; then 29 | echo "Project run successfully: $project" 30 | echo "---------------------------------------" 31 | else 32 | echo "Project failed to run: $project" 33 | echo "---------------------------------------" 34 | status=1 35 | fi 36 | 37 | # 杀死 server 38 | kill -9 $server_pid $(lsof -t -i:8888) 39 | 40 | 41 | # 设置脚本的退出状态 42 | exit $status -------------------------------------------------------------------------------- /server_sdk/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="metainfo_backward" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/thrift" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 当脚本退出时,停止 server 20 | trap 'kill $server_pid' EXIT 21 | 22 | # 等待 server 结束 23 | wait $server_pid -------------------------------------------------------------------------------- /server_sdk/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | # 初始化状态变量 9 | project="metainfo_backward" 10 | 11 | echo "---------------------------------------" 12 | echo "Running project: $project" 13 | 14 | 15 | # 启动 server 16 | 17 | cd "$REPO_PATH/thrift" || exit 18 | go run main.go > /dev/null 2>&1 & 19 | cd - > /dev/null || exit 20 | 21 | -------------------------------------------------------------------------------- /streaming/kitex_gen/pbapi/echo/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.0.6. DO NOT EDIT. 2 | 3 | package echo 4 | 5 | import ( 6 | "github.com/cloudwego/kitex-examples/streaming/kitex_gen/pbapi" 7 | "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler pbapi.Echo, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /streaming/kitex_gen/pbapi/echo/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.0.6. DO NOT EDIT. 2 | package echo 3 | 4 | import ( 5 | "github.com/cloudwego/kitex-examples/streaming/kitex_gen/pbapi" 6 | "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler pbapi.Echo, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /streaming/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="streaming" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | cd - > /dev/null || exit 23 | 24 | # 当脚本退出时,停止 server 25 | trap 'kill $server_pid' EXIT 26 | 27 | # 等待 server 结束 28 | wait $server_pid -------------------------------------------------------------------------------- /thrift_multi_service/idl/demo.thrift: -------------------------------------------------------------------------------- 1 | // Copyright 2024 CloudWeGo Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | namespace go api 17 | 18 | struct Request { 19 | 1: string message 20 | } 21 | 22 | struct Response { 23 | 1: string message 24 | } 25 | 26 | service ServiceA { 27 | Response echoA(1: Request req) 28 | } 29 | 30 | service ServiceB { 31 | Response echoB(1: Request req) 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /thrift_multi_service/kitex_gen/api/k-consts.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /thrift_multi_service/kitex_gen/api/servicea/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.0. DO NOT EDIT. 2 | 3 | package servicea 4 | 5 | import ( 6 | api "github.com/cloudwego/kitex-examples/thrift_multi_service/kitex_gen/api" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler api.ServiceA, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /thrift_multi_service/kitex_gen/api/servicea/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package servicea 3 | 4 | import ( 5 | api "github.com/cloudwego/kitex-examples/thrift_multi_service/kitex_gen/api" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler api.ServiceA, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler api.ServiceA, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /thrift_multi_service/kitex_gen/api/serviceb/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.0. DO NOT EDIT. 2 | 3 | package serviceb 4 | 5 | import ( 6 | api "github.com/cloudwego/kitex-examples/thrift_multi_service/kitex_gen/api" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler api.ServiceB, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /thrift_multi_service/kitex_gen/api/serviceb/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package serviceb 3 | 4 | import ( 5 | api "github.com/cloudwego/kitex-examples/thrift_multi_service/kitex_gen/api" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler api.ServiceB, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler api.ServiceB, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /thrift_multi_service/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="thrift_multi_service" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | cd - > /dev/null || exit 23 | 24 | # 当脚本退出时,停止 server 25 | trap 'kill $server_pid' EXIT 26 | 27 | # 等待 server 结束 28 | wait $server_pid -------------------------------------------------------------------------------- /thrift_streaming/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2024 CloudWeGo Authors 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | RUN_NAME="demo-server" 17 | 18 | mkdir -p output/bin 19 | cp script/* output/ 20 | chmod +x output/bootstrap.sh 21 | 22 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 23 | go build -o output/bin/${RUN_NAME} 24 | else 25 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 26 | fi 27 | -------------------------------------------------------------------------------- /thrift_streaming/kitex_gen/echo/k-consts.go: -------------------------------------------------------------------------------- 1 | package echo 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /thrift_streaming/kitex_gen/echo/testservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.9.0. DO NOT EDIT. 2 | 3 | package testservice 4 | 5 | import ( 6 | echo "github.com/cloudwego/kitex-examples/thrift_streaming/kitex_gen/echo" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler echo.TestService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /thrift_streaming/kitex_gen/echo/testservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.12.0. DO NOT EDIT. 2 | package testservice 3 | 4 | import ( 5 | echo "github.com/cloudwego/kitex-examples/thrift_streaming/kitex_gen/echo" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler echo.TestService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | options = append(options, server.WithCompatibleMiddlewareForUnary()) 15 | 16 | svr := server.NewServer(options...) 17 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | return svr 21 | } 22 | 23 | func RegisterService(svr server.Server, handler echo.TestService, opts ...server.RegisterOption) error { 24 | return svr.RegisterService(serviceInfo(), handler, opts...) 25 | } 26 | -------------------------------------------------------------------------------- /thrift_streaming/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'demo-server' 3 | ToolVersion: 'v0.9.0' 4 | -------------------------------------------------------------------------------- /thrift_streaming/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 设置工作目录为项目目录 4 | cd ./ 5 | 6 | REPO_PATH="." 7 | 8 | project="test.sh" 9 | 10 | echo "---------------------------------------" 11 | echo "Running project: $project" 12 | 13 | # 启动 server 14 | cd "$REPO_PATH/server" || exit 15 | go run main.go > /dev/null 2>&1 & 16 | server_pid=$! 17 | cd - > /dev/null || exit 18 | 19 | # 启动 client 20 | cd "$REPO_PATH/client" || exit 21 | go run main.go > /dev/null 2>&1 & 22 | cd - > /dev/null || exit 23 | 24 | # 当脚本退出时,停止 server 25 | trap 'kill $server_pid' EXIT 26 | 27 | # 等待 server 结束 28 | wait $server_pid -------------------------------------------------------------------------------- /thrift_streaming/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | CURDIR=$(cd $(dirname $0); pwd) 3 | 4 | if [ "X$1" != "X" ]; then 5 | RUNTIME_ROOT=$1 6 | else 7 | RUNTIME_ROOT=${CURDIR} 8 | fi 9 | 10 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 11 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 12 | 13 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 14 | mkdir -p "$KITEX_LOG_DIR/app" 15 | fi 16 | 17 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 18 | mkdir -p "$KITEX_LOG_DIR/rpc" 19 | fi 20 | 21 | exec "$CURDIR/bin/demo-server" 22 | --------------------------------------------------------------------------------