From 13d3da62acce70d8a7f7af8c01cef559ecead648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=85=E5=AD=90?= <906604588@qq.com> Date: Mon, 14 Mar 2022 14:34:46 +0800 Subject: [PATCH] chore: remove examples (#1871) --- .github/workflows/go.yml | 6 - README.md | 2 +- README_zh.md | 24 +- examples/LICENSE | 21 - examples/README.md | 15 - examples/auth/jwt/main.go | 68 - examples/benchmark/README.md | 14 - examples/benchmark/libs.sh | 3 - examples/benchmark/main.go | 197 -- examples/benchmark/test.sh | 86 - examples/benchmark/testresults/benchmark.gnu | 22 - examples/benchmark/testresults/plot.sh | 10 - examples/benchmark/testresults/plot_mac.sh | 10 - examples/benchmark/testresults/transpose.sh | 6 - examples/benchmark/testresults/tst.awk | 15 - examples/blog/.gitignore | 36 - examples/blog/LICENSE | 21 - examples/blog/Makefile | 106 - examples/blog/README.md | 19 - examples/blog/api/blog/v1/blog.pb.go | 870 --------- examples/blog/api/blog/v1/blog.pb.validate.go | 846 -------- examples/blog/api/blog/v1/blog.proto | 89 - examples/blog/api/blog/v1/blog_grpc.pb.go | 245 --- examples/blog/api/blog/v1/blog_http.pb.go | 220 --- examples/blog/cmd/blog/main.go | 103 - examples/blog/cmd/blog/wire.go | 22 - examples/blog/cmd/blog/wire_gen.go | 36 - examples/blog/configs/config.yaml | 18 - examples/blog/generate.go | 3 - examples/blog/internal/biz/README.md | 1 - examples/blog/internal/biz/article.go | 74 - examples/blog/internal/biz/biz.go | 6 - examples/blog/internal/conf/conf.pb.go | 763 -------- examples/blog/internal/conf/conf.proto | 49 - examples/blog/internal/data/README.md | 5 - examples/blog/internal/data/article.go | 80 - examples/blog/internal/data/data.go | 86 - examples/blog/internal/data/ent/article.go | 174 -- .../blog/internal/data/ent/article/article.go | 74 - .../blog/internal/data/ent/article/where.go | 584 ------ .../blog/internal/data/ent/article_create.go | 350 ---- .../blog/internal/data/ent/article_delete.go | 108 - .../blog/internal/data/ent/article_query.go | 1068 ---------- .../blog/internal/data/ent/article_update.go | 711 ------- examples/blog/internal/data/ent/client.go | 465 ----- examples/blog/internal/data/ent/comment.go | 174 -- .../blog/internal/data/ent/comment/comment.go | 71 - .../blog/internal/data/ent/comment/where.go | 556 ------ .../blog/internal/data/ent/comment_create.go | 319 --- .../blog/internal/data/ent/comment_delete.go | 108 - .../blog/internal/data/ent/comment_query.go | 970 --------- .../blog/internal/data/ent/comment_update.go | 470 ----- examples/blog/internal/data/ent/config.go | 61 - examples/blog/internal/data/ent/context.go | 33 - examples/blog/internal/data/ent/ent.go | 270 --- .../blog/internal/data/ent/enttest/enttest.go | 78 - examples/blog/internal/data/ent/hook/hook.go | 230 --- .../blog/internal/data/ent/migrate/migrate.go | 72 - .../blog/internal/data/ent/migrate/schema.go | 105 - examples/blog/internal/data/ent/mutation.go | 1731 ----------------- .../internal/data/ent/predicate/predicate.go | 16 - examples/blog/internal/data/ent/runtime.go | 48 - .../blog/internal/data/ent/runtime/runtime.go | 10 - .../blog/internal/data/ent/schema/article.go | 41 - .../blog/internal/data/ent/schema/comment.go | 41 - examples/blog/internal/data/ent/schema/tag.go | 39 - examples/blog/internal/data/ent/tag.go | 158 -- examples/blog/internal/data/ent/tag/tag.go | 65 - examples/blog/internal/data/ent/tag/where.go | 556 ------ examples/blog/internal/data/ent/tag_create.go | 315 --- examples/blog/internal/data/ent/tag_delete.go | 108 - examples/blog/internal/data/ent/tag_query.go | 1002 ---------- examples/blog/internal/data/ent/tag_update.go | 530 ----- examples/blog/internal/data/ent/tx.go | 216 -- examples/blog/internal/data/redis.go | 26 - examples/blog/internal/server/grpc.go | 37 - examples/blog/internal/server/http.go | 37 - examples/blog/internal/server/server.go | 8 - examples/blog/internal/service/README.md | 1 - examples/blog/internal/service/article.go | 67 - examples/blog/internal/service/service.go | 20 - examples/blog/openapi.yaml | 126 -- examples/config/apollo/README.md | 10 - .../docker-quick-start/docker-compose.yml | 50 - .../docker-quick-start/sql/apolloconfigdb.sql | 448 ----- .../docker-quick-start/sql/apolloportaldb.sql | 408 ---- examples/config/apollo/main.go | 81 - examples/config/config.yaml | 11 - examples/config/main.go | 57 - examples/config/t/a.yaml | 5 - examples/config/t/b.yaml | 6 - examples/errors/api/error_reason.pb.go | 136 -- examples/errors/api/error_reason.proto | 18 - examples/errors/api/error_reason_errors.pb.go | 30 - examples/errors/client/main.go | 64 - examples/errors/server/main.go | 65 - examples/event/event/event.go | 20 - examples/event/kafka/kafka.go | 114 -- examples/event/memory/memory.go | 88 - examples/event/memory/memory_test.go | 33 - examples/event/receiver/main.go | 36 - examples/event/sender/main.go | 31 - examples/go.mod | 66 - examples/go.sum | 1340 ------------- examples/header/client/main.go | 55 - examples/header/server/main.go | 60 - examples/helloworld/README.md | 10 - examples/helloworld/client/main.go | 75 - .../helloworld/helloworld/helloworld.pb.go | 222 --- .../helloworld/helloworld/helloworld.proto | 27 - .../helloworld/helloworld_grpc.pb.go | 103 - .../helloworld/helloworld_http.pb.go | 74 - examples/helloworld/server/main.go | 68 - examples/http/README.md | 33 - examples/http/cors/main.go | 36 - examples/http/echo/main.go | 29 - examples/http/errors/main.go | 65 - examples/http/gin/main.go | 55 - examples/http/middlewares/handlers.go | 26 - examples/http/middlewares/main.go | 46 - examples/http/middlewares/middlewares.go | 75 - examples/http/middlewares/services.go | 25 - examples/http/mux/main.go | 31 - examples/http/redirect/main.go | 60 - examples/http/static/assets/index.html | 9 - examples/http/static/main.go | 33 - examples/http/upload/main.go | 48 - examples/i18n/.gitignore | 36 - examples/i18n/Dockerfile | 24 - examples/i18n/LICENSE | 21 - examples/i18n/Makefile | 70 - examples/i18n/README.md | 136 -- examples/i18n/active.en.toml | 4 - examples/i18n/active.zh.toml | 4 - .../i18n/api/helloworld/v1/error_reason.pb.go | 138 -- .../helloworld/v1/error_reason.pb.validate.go | 34 - .../i18n/api/helloworld/v1/error_reason.proto | 17 - .../helloworld/v1/error_reason.swagger.json | 46 - .../helloworld/v1/error_reason_errors.pb.go | 30 - examples/i18n/api/helloworld/v1/greeter.pb.go | 226 --- .../api/helloworld/v1/greeter.pb.validate.go | 167 -- examples/i18n/api/helloworld/v1/greeter.proto | 30 - .../api/helloworld/v1/greeter.swagger.json | 92 - .../i18n/api/helloworld/v1/greeter_grpc.pb.go | 103 - .../i18n/api/helloworld/v1/greeter_http.pb.go | 74 - examples/i18n/cmd/i18n/main.go | 79 - examples/i18n/cmd/i18n/wire.go | 22 - examples/i18n/cmd/i18n/wire_gen.go | 36 - examples/i18n/configs/config.yaml | 15 - examples/i18n/generate.go | 3 - examples/i18n/internal/biz/README.md | 1 - examples/i18n/internal/biz/biz.go | 6 - examples/i18n/internal/biz/greeter.go | 33 - examples/i18n/internal/conf/conf.pb.go | 653 ------- examples/i18n/internal/conf/conf.proto | 41 - examples/i18n/internal/data/README.md | 1 - examples/i18n/internal/data/data.go | 22 - examples/i18n/internal/data/greeter.go | 29 - .../pkg/middleware/localize/localize.go | 36 - examples/i18n/internal/server/grpc.go | 39 - examples/i18n/internal/server/http.go | 41 - examples/i18n/internal/server/server.go | 8 - examples/i18n/internal/service/README.md | 1 - examples/i18n/internal/service/greeter.go | 50 - examples/i18n/internal/service/service.go | 6 - examples/i18n/third_party/README.md | 1 - examples/i18n/third_party/errors/errors.proto | 18 - .../third_party/google/api/annotations.proto | 31 - .../i18n/third_party/google/api/http.proto | 375 ---- .../third_party/google/api/httpbody.proto | 77 - examples/i18n/third_party/validate/README.md | 3 - .../i18n/third_party/validate/validate.proto | 863 -------- examples/log/logrus.go | 100 - examples/log/logrus_test.go | 53 - examples/log/zap.go | 53 - examples/log/zap_test.go | 40 - examples/metadata/client/main.go | 61 - examples/metadata/server/main.go | 66 - examples/metrics/main.go | 92 - examples/middleware/main.go | 69 - examples/registry/consul/client/main.go | 71 - examples/registry/consul/server/main.go | 70 - examples/registry/discovery/client/main.go | 58 - examples/registry/discovery/server/main.go | 70 - examples/registry/etcd/client/main.go | 69 - examples/registry/etcd/cmuxServer/main.go | 80 - examples/registry/etcd/server/main.go | 64 - examples/registry/nacos/client/main.go | 57 - examples/registry/nacos/server/main.go | 84 - examples/registry/polaris/client/main.go | 82 - examples/registry/polaris/server/main.go | 78 - examples/registry/registry_test.go | 129 -- examples/registry/zookeeper/client/main.go | 61 - examples/registry/zookeeper/server/main.go | 60 - examples/selector/client/main.go | 84 - examples/selector/server/main.go | 79 - examples/stream/client/main.go | 102 - examples/stream/hello/hello.pb.go | 479 ----- examples/stream/hello/hello_grpc.pb.go | 266 --- examples/stream/server/main.go | 31 - examples/stream/service/hello.go | 60 - examples/swagger/helloworld/helloworld.pb.go | 251 --- examples/swagger/helloworld/helloworld.proto | 57 - .../swagger/helloworld/helloworld_grpc.pb.go | 103 - .../swagger/helloworld/helloworld_http.pb.go | 74 - examples/swagger/reply/reply.pb.go | 145 -- examples/swagger/reply/reply.proto | 9 - examples/swagger/server/main.go | 67 - examples/tls/README.md | 10 - examples/tls/cert/ca.crt | 32 - examples/tls/cert/server.crt | 64 - examples/tls/cert/server.key | 51 - examples/tls/client/main.go | 64 - examples/tls/server/main.go | 63 - examples/tls/tls_test.go | 135 -- examples/traces/Dockerfile | 16 - examples/traces/README.md | 21 - examples/traces/api/message/message.pb.go | 300 --- examples/traces/api/message/message.proto | 32 - .../traces/api/message/message_grpc.pb.go | 101 - .../traces/api/message/message_http.pb.go | 74 - examples/traces/api/user/user.pb.go | 289 --- examples/traces/api/user/user.proto | 30 - examples/traces/api/user/user_grpc.pb.go | 101 - examples/traces/api/user/user_http.pb.go | 74 - examples/traces/app/message/main.go | 104 - examples/traces/app/user/main.go | 127 -- examples/traces/docker-compose.yml | 20 - examples/traces/service.sh | 2 - examples/traces/start-windows.bat | 6 - examples/traces/start.sh | 6 - .../api/transaction/v1/transaction.pb.go | 233 --- .../api/transaction/v1/transaction.proto | 27 - .../api/transaction/v1/transaction_grpc.pb.go | 105 - .../api/transaction/v1/transaction_http.pb.go | 71 - examples/transaction/ent/Makefile | 80 - examples/transaction/ent/README.md | 19 - examples/transaction/ent/cmd/ent/main.go | 103 - examples/transaction/ent/cmd/ent/wire.go | 22 - examples/transaction/ent/cmd/ent/wire_gen.go | 37 - examples/transaction/ent/configs/config.yaml | 18 - examples/transaction/ent/generate.go | 3 - .../transaction/ent/internal/biz/README.md | 1 - examples/transaction/ent/internal/biz/biz.go | 14 - .../ent/internal/biz/transaction.go | 50 - .../transaction/ent/internal/conf/conf.pb.go | 763 -------- .../transaction/ent/internal/conf/conf.proto | 49 - .../transaction/ent/internal/data/README.md | 5 - .../transaction/ent/internal/data/data.go | 88 - .../transaction/ent/internal/data/ent/card.go | 109 -- .../ent/internal/data/ent/card/card.go | 33 - .../ent/internal/data/ent/card/where.go | 359 ---- .../ent/internal/data/ent/card_create.go | 249 --- .../ent/internal/data/ent/card_delete.go | 111 -- .../ent/internal/data/ent/card_query.go | 915 --------- .../ent/internal/data/ent/card_update.go | 290 --- .../ent/internal/data/ent/client.go | 309 --- .../ent/internal/data/ent/config.go | 60 - .../ent/internal/data/ent/context.go | 33 - .../transaction/ent/internal/data/ent/ent.go | 261 --- .../ent/internal/data/ent/enttest/enttest.go | 78 - .../ent/internal/data/ent/generate.go | 3 - .../ent/internal/data/ent/hook/hook.go | 217 --- .../ent/internal/data/ent/migrate/migrate.go | 72 - .../ent/internal/data/ent/migrate/schema.go | 43 - .../ent/internal/data/ent/mutation.go | 732 ------- .../internal/data/ent/predicate/predicate.go | 13 - .../ent/internal/data/ent/runtime.go | 24 - .../ent/internal/data/ent/runtime/runtime.go | 10 - .../ent/internal/data/ent/schema/card.go | 25 - .../ent/internal/data/ent/schema/user.go | 25 - .../transaction/ent/internal/data/ent/tx.go | 213 -- .../transaction/ent/internal/data/ent/user.go | 109 -- .../ent/internal/data/ent/user/user.go | 40 - .../ent/internal/data/ent/user/where.go | 359 ---- .../ent/internal/data/ent/user_create.go | 279 --- .../ent/internal/data/ent/user_delete.go | 111 -- .../ent/internal/data/ent/user_query.go | 915 --------- .../ent/internal/data/ent/user_update.go | 322 --- .../ent/internal/data/transaction.go | 58 - .../transaction/ent/internal/server/grpc.go | 37 - .../transaction/ent/internal/server/http.go | 37 - .../transaction/ent/internal/server/server.go | 8 - .../ent/internal/service/README.md | 1 - .../ent/internal/service/service.go | 20 - .../ent/internal/service/transaction.go | 31 - examples/transaction/ent/openapi.yaml | 126 -- examples/transaction/gorm/Makefile | 79 - examples/transaction/gorm/README.md | 19 - examples/transaction/gorm/cmd/gorm/main.go | 103 - examples/transaction/gorm/cmd/gorm/wire.go | 22 - .../transaction/gorm/cmd/gorm/wire_gen.go | 39 - examples/transaction/gorm/configs/config.yaml | 18 - examples/transaction/gorm/generate.go | 3 - .../transaction/gorm/internal/biz/README.md | 1 - examples/transaction/gorm/internal/biz/biz.go | 14 - .../gorm/internal/biz/transaction.go | 52 - .../transaction/gorm/internal/conf/conf.pb.go | 763 -------- .../transaction/gorm/internal/conf/conf.proto | 49 - .../transaction/gorm/internal/data/README.md | 5 - .../transaction/gorm/internal/data/data.go | 71 - .../gorm/internal/data/transaction.go | 64 - .../transaction/gorm/internal/server/grpc.go | 37 - .../transaction/gorm/internal/server/http.go | 37 - .../gorm/internal/server/server.go | 8 - .../gorm/internal/service/README.md | 1 - .../gorm/internal/service/service.go | 20 - .../gorm/internal/service/transaction.go | 31 - examples/transaction/gorm/openapi.yaml | 126 -- examples/transaction/openapi.yaml | 42 - examples/validate/api/example.pb.go | 387 ---- examples/validate/api/example.pb.validate.go | 493 ----- examples/validate/api/example.proto | 43 - examples/validate/api/example_grpc.pb.go | 101 - examples/validate/api/example_http.pb.go | 71 - examples/validate/main.go | 55 - examples/ws/client/client.go | 76 - examples/ws/handler/handler.go | 32 - examples/ws/main.go | 28 - 319 files changed, 13 insertions(+), 40868 deletions(-) delete mode 100644 examples/LICENSE delete mode 100644 examples/README.md delete mode 100644 examples/auth/jwt/main.go delete mode 100644 examples/benchmark/README.md delete mode 100644 examples/benchmark/libs.sh delete mode 100644 examples/benchmark/main.go delete mode 100755 examples/benchmark/test.sh delete mode 100644 examples/benchmark/testresults/benchmark.gnu delete mode 100644 examples/benchmark/testresults/plot.sh delete mode 100644 examples/benchmark/testresults/plot_mac.sh delete mode 100644 examples/benchmark/testresults/transpose.sh delete mode 100644 examples/benchmark/testresults/tst.awk delete mode 100644 examples/blog/.gitignore delete mode 100644 examples/blog/LICENSE delete mode 100644 examples/blog/Makefile delete mode 100644 examples/blog/README.md delete mode 100644 examples/blog/api/blog/v1/blog.pb.go delete mode 100644 examples/blog/api/blog/v1/blog.pb.validate.go delete mode 100644 examples/blog/api/blog/v1/blog.proto delete mode 100644 examples/blog/api/blog/v1/blog_grpc.pb.go delete mode 100644 examples/blog/api/blog/v1/blog_http.pb.go delete mode 100644 examples/blog/cmd/blog/main.go delete mode 100644 examples/blog/cmd/blog/wire.go delete mode 100644 examples/blog/cmd/blog/wire_gen.go delete mode 100644 examples/blog/configs/config.yaml delete mode 100644 examples/blog/generate.go delete mode 100644 examples/blog/internal/biz/README.md delete mode 100644 examples/blog/internal/biz/article.go delete mode 100644 examples/blog/internal/biz/biz.go delete mode 100644 examples/blog/internal/conf/conf.pb.go delete mode 100644 examples/blog/internal/conf/conf.proto delete mode 100644 examples/blog/internal/data/README.md delete mode 100644 examples/blog/internal/data/article.go delete mode 100644 examples/blog/internal/data/data.go delete mode 100644 examples/blog/internal/data/ent/article.go delete mode 100644 examples/blog/internal/data/ent/article/article.go delete mode 100644 examples/blog/internal/data/ent/article/where.go delete mode 100644 examples/blog/internal/data/ent/article_create.go delete mode 100644 examples/blog/internal/data/ent/article_delete.go delete mode 100644 examples/blog/internal/data/ent/article_query.go delete mode 100644 examples/blog/internal/data/ent/article_update.go delete mode 100644 examples/blog/internal/data/ent/client.go delete mode 100644 examples/blog/internal/data/ent/comment.go delete mode 100644 examples/blog/internal/data/ent/comment/comment.go delete mode 100644 examples/blog/internal/data/ent/comment/where.go delete mode 100644 examples/blog/internal/data/ent/comment_create.go delete mode 100644 examples/blog/internal/data/ent/comment_delete.go delete mode 100644 examples/blog/internal/data/ent/comment_query.go delete mode 100644 examples/blog/internal/data/ent/comment_update.go delete mode 100644 examples/blog/internal/data/ent/config.go delete mode 100644 examples/blog/internal/data/ent/context.go delete mode 100644 examples/blog/internal/data/ent/ent.go delete mode 100644 examples/blog/internal/data/ent/enttest/enttest.go delete mode 100644 examples/blog/internal/data/ent/hook/hook.go delete mode 100644 examples/blog/internal/data/ent/migrate/migrate.go delete mode 100644 examples/blog/internal/data/ent/migrate/schema.go delete mode 100644 examples/blog/internal/data/ent/mutation.go delete mode 100644 examples/blog/internal/data/ent/predicate/predicate.go delete mode 100644 examples/blog/internal/data/ent/runtime.go delete mode 100644 examples/blog/internal/data/ent/runtime/runtime.go delete mode 100644 examples/blog/internal/data/ent/schema/article.go delete mode 100644 examples/blog/internal/data/ent/schema/comment.go delete mode 100644 examples/blog/internal/data/ent/schema/tag.go delete mode 100644 examples/blog/internal/data/ent/tag.go delete mode 100644 examples/blog/internal/data/ent/tag/tag.go delete mode 100644 examples/blog/internal/data/ent/tag/where.go delete mode 100644 examples/blog/internal/data/ent/tag_create.go delete mode 100644 examples/blog/internal/data/ent/tag_delete.go delete mode 100644 examples/blog/internal/data/ent/tag_query.go delete mode 100644 examples/blog/internal/data/ent/tag_update.go delete mode 100644 examples/blog/internal/data/ent/tx.go delete mode 100644 examples/blog/internal/data/redis.go delete mode 100644 examples/blog/internal/server/grpc.go delete mode 100644 examples/blog/internal/server/http.go delete mode 100644 examples/blog/internal/server/server.go delete mode 100644 examples/blog/internal/service/README.md delete mode 100644 examples/blog/internal/service/article.go delete mode 100644 examples/blog/internal/service/service.go delete mode 100644 examples/blog/openapi.yaml delete mode 100644 examples/config/apollo/README.md delete mode 100644 examples/config/apollo/docker-quick-start/docker-compose.yml delete mode 100644 examples/config/apollo/docker-quick-start/sql/apolloconfigdb.sql delete mode 100644 examples/config/apollo/docker-quick-start/sql/apolloportaldb.sql delete mode 100644 examples/config/apollo/main.go delete mode 100644 examples/config/config.yaml delete mode 100644 examples/config/main.go delete mode 100644 examples/config/t/a.yaml delete mode 100644 examples/config/t/b.yaml delete mode 100644 examples/errors/api/error_reason.pb.go delete mode 100644 examples/errors/api/error_reason.proto delete mode 100644 examples/errors/api/error_reason_errors.pb.go delete mode 100644 examples/errors/client/main.go delete mode 100644 examples/errors/server/main.go delete mode 100644 examples/event/event/event.go delete mode 100644 examples/event/kafka/kafka.go delete mode 100644 examples/event/memory/memory.go delete mode 100644 examples/event/memory/memory_test.go delete mode 100644 examples/event/receiver/main.go delete mode 100644 examples/event/sender/main.go delete mode 100644 examples/go.mod delete mode 100644 examples/go.sum delete mode 100644 examples/header/client/main.go delete mode 100644 examples/header/server/main.go delete mode 100644 examples/helloworld/README.md delete mode 100644 examples/helloworld/client/main.go delete mode 100644 examples/helloworld/helloworld/helloworld.pb.go delete mode 100644 examples/helloworld/helloworld/helloworld.proto delete mode 100644 examples/helloworld/helloworld/helloworld_grpc.pb.go delete mode 100644 examples/helloworld/helloworld/helloworld_http.pb.go delete mode 100644 examples/helloworld/server/main.go delete mode 100644 examples/http/README.md delete mode 100644 examples/http/cors/main.go delete mode 100644 examples/http/echo/main.go delete mode 100644 examples/http/errors/main.go delete mode 100644 examples/http/gin/main.go delete mode 100644 examples/http/middlewares/handlers.go delete mode 100644 examples/http/middlewares/main.go delete mode 100644 examples/http/middlewares/middlewares.go delete mode 100644 examples/http/middlewares/services.go delete mode 100644 examples/http/mux/main.go delete mode 100644 examples/http/redirect/main.go delete mode 100644 examples/http/static/assets/index.html delete mode 100644 examples/http/static/main.go delete mode 100644 examples/http/upload/main.go delete mode 100644 examples/i18n/.gitignore delete mode 100644 examples/i18n/Dockerfile delete mode 100644 examples/i18n/LICENSE delete mode 100644 examples/i18n/Makefile delete mode 100644 examples/i18n/README.md delete mode 100644 examples/i18n/active.en.toml delete mode 100644 examples/i18n/active.zh.toml delete mode 100644 examples/i18n/api/helloworld/v1/error_reason.pb.go delete mode 100644 examples/i18n/api/helloworld/v1/error_reason.pb.validate.go delete mode 100644 examples/i18n/api/helloworld/v1/error_reason.proto delete mode 100644 examples/i18n/api/helloworld/v1/error_reason.swagger.json delete mode 100644 examples/i18n/api/helloworld/v1/error_reason_errors.pb.go delete mode 100644 examples/i18n/api/helloworld/v1/greeter.pb.go delete mode 100644 examples/i18n/api/helloworld/v1/greeter.pb.validate.go delete mode 100644 examples/i18n/api/helloworld/v1/greeter.proto delete mode 100644 examples/i18n/api/helloworld/v1/greeter.swagger.json delete mode 100644 examples/i18n/api/helloworld/v1/greeter_grpc.pb.go delete mode 100644 examples/i18n/api/helloworld/v1/greeter_http.pb.go delete mode 100644 examples/i18n/cmd/i18n/main.go delete mode 100644 examples/i18n/cmd/i18n/wire.go delete mode 100644 examples/i18n/cmd/i18n/wire_gen.go delete mode 100644 examples/i18n/configs/config.yaml delete mode 100644 examples/i18n/generate.go delete mode 100644 examples/i18n/internal/biz/README.md delete mode 100644 examples/i18n/internal/biz/biz.go delete mode 100644 examples/i18n/internal/biz/greeter.go delete mode 100644 examples/i18n/internal/conf/conf.pb.go delete mode 100644 examples/i18n/internal/conf/conf.proto delete mode 100644 examples/i18n/internal/data/README.md delete mode 100644 examples/i18n/internal/data/data.go delete mode 100644 examples/i18n/internal/data/greeter.go delete mode 100644 examples/i18n/internal/pkg/middleware/localize/localize.go delete mode 100644 examples/i18n/internal/server/grpc.go delete mode 100644 examples/i18n/internal/server/http.go delete mode 100644 examples/i18n/internal/server/server.go delete mode 100644 examples/i18n/internal/service/README.md delete mode 100644 examples/i18n/internal/service/greeter.go delete mode 100644 examples/i18n/internal/service/service.go delete mode 100644 examples/i18n/third_party/README.md delete mode 100644 examples/i18n/third_party/errors/errors.proto delete mode 100644 examples/i18n/third_party/google/api/annotations.proto delete mode 100644 examples/i18n/third_party/google/api/http.proto delete mode 100644 examples/i18n/third_party/google/api/httpbody.proto delete mode 100644 examples/i18n/third_party/validate/README.md delete mode 100644 examples/i18n/third_party/validate/validate.proto delete mode 100644 examples/log/logrus.go delete mode 100644 examples/log/logrus_test.go delete mode 100644 examples/log/zap.go delete mode 100644 examples/log/zap_test.go delete mode 100644 examples/metadata/client/main.go delete mode 100644 examples/metadata/server/main.go delete mode 100644 examples/metrics/main.go delete mode 100644 examples/middleware/main.go delete mode 100644 examples/registry/consul/client/main.go delete mode 100644 examples/registry/consul/server/main.go delete mode 100644 examples/registry/discovery/client/main.go delete mode 100644 examples/registry/discovery/server/main.go delete mode 100644 examples/registry/etcd/client/main.go delete mode 100644 examples/registry/etcd/cmuxServer/main.go delete mode 100644 examples/registry/etcd/server/main.go delete mode 100644 examples/registry/nacos/client/main.go delete mode 100644 examples/registry/nacos/server/main.go delete mode 100644 examples/registry/polaris/client/main.go delete mode 100644 examples/registry/polaris/server/main.go delete mode 100644 examples/registry/registry_test.go delete mode 100644 examples/registry/zookeeper/client/main.go delete mode 100644 examples/registry/zookeeper/server/main.go delete mode 100644 examples/selector/client/main.go delete mode 100644 examples/selector/server/main.go delete mode 100644 examples/stream/client/main.go delete mode 100644 examples/stream/hello/hello.pb.go delete mode 100644 examples/stream/hello/hello_grpc.pb.go delete mode 100644 examples/stream/server/main.go delete mode 100644 examples/stream/service/hello.go delete mode 100644 examples/swagger/helloworld/helloworld.pb.go delete mode 100644 examples/swagger/helloworld/helloworld.proto delete mode 100644 examples/swagger/helloworld/helloworld_grpc.pb.go delete mode 100644 examples/swagger/helloworld/helloworld_http.pb.go delete mode 100644 examples/swagger/reply/reply.pb.go delete mode 100644 examples/swagger/reply/reply.proto delete mode 100644 examples/swagger/server/main.go delete mode 100644 examples/tls/README.md delete mode 100644 examples/tls/cert/ca.crt delete mode 100644 examples/tls/cert/server.crt delete mode 100644 examples/tls/cert/server.key delete mode 100644 examples/tls/client/main.go delete mode 100644 examples/tls/server/main.go delete mode 100644 examples/tls/tls_test.go delete mode 100644 examples/traces/Dockerfile delete mode 100644 examples/traces/README.md delete mode 100644 examples/traces/api/message/message.pb.go delete mode 100644 examples/traces/api/message/message.proto delete mode 100644 examples/traces/api/message/message_grpc.pb.go delete mode 100644 examples/traces/api/message/message_http.pb.go delete mode 100644 examples/traces/api/user/user.pb.go delete mode 100644 examples/traces/api/user/user.proto delete mode 100644 examples/traces/api/user/user_grpc.pb.go delete mode 100644 examples/traces/api/user/user_http.pb.go delete mode 100644 examples/traces/app/message/main.go delete mode 100644 examples/traces/app/user/main.go delete mode 100644 examples/traces/docker-compose.yml delete mode 100644 examples/traces/service.sh delete mode 100644 examples/traces/start-windows.bat delete mode 100644 examples/traces/start.sh delete mode 100644 examples/transaction/api/transaction/v1/transaction.pb.go delete mode 100644 examples/transaction/api/transaction/v1/transaction.proto delete mode 100644 examples/transaction/api/transaction/v1/transaction_grpc.pb.go delete mode 100644 examples/transaction/api/transaction/v1/transaction_http.pb.go delete mode 100644 examples/transaction/ent/Makefile delete mode 100644 examples/transaction/ent/README.md delete mode 100644 examples/transaction/ent/cmd/ent/main.go delete mode 100644 examples/transaction/ent/cmd/ent/wire.go delete mode 100644 examples/transaction/ent/cmd/ent/wire_gen.go delete mode 100644 examples/transaction/ent/configs/config.yaml delete mode 100644 examples/transaction/ent/generate.go delete mode 100644 examples/transaction/ent/internal/biz/README.md delete mode 100644 examples/transaction/ent/internal/biz/biz.go delete mode 100644 examples/transaction/ent/internal/biz/transaction.go delete mode 100644 examples/transaction/ent/internal/conf/conf.pb.go delete mode 100644 examples/transaction/ent/internal/conf/conf.proto delete mode 100644 examples/transaction/ent/internal/data/README.md delete mode 100644 examples/transaction/ent/internal/data/data.go delete mode 100644 examples/transaction/ent/internal/data/ent/card.go delete mode 100644 examples/transaction/ent/internal/data/ent/card/card.go delete mode 100644 examples/transaction/ent/internal/data/ent/card/where.go delete mode 100644 examples/transaction/ent/internal/data/ent/card_create.go delete mode 100644 examples/transaction/ent/internal/data/ent/card_delete.go delete mode 100644 examples/transaction/ent/internal/data/ent/card_query.go delete mode 100644 examples/transaction/ent/internal/data/ent/card_update.go delete mode 100644 examples/transaction/ent/internal/data/ent/client.go delete mode 100644 examples/transaction/ent/internal/data/ent/config.go delete mode 100644 examples/transaction/ent/internal/data/ent/context.go delete mode 100644 examples/transaction/ent/internal/data/ent/ent.go delete mode 100644 examples/transaction/ent/internal/data/ent/enttest/enttest.go delete mode 100644 examples/transaction/ent/internal/data/ent/generate.go delete mode 100644 examples/transaction/ent/internal/data/ent/hook/hook.go delete mode 100644 examples/transaction/ent/internal/data/ent/migrate/migrate.go delete mode 100644 examples/transaction/ent/internal/data/ent/migrate/schema.go delete mode 100644 examples/transaction/ent/internal/data/ent/mutation.go delete mode 100644 examples/transaction/ent/internal/data/ent/predicate/predicate.go delete mode 100644 examples/transaction/ent/internal/data/ent/runtime.go delete mode 100644 examples/transaction/ent/internal/data/ent/runtime/runtime.go delete mode 100644 examples/transaction/ent/internal/data/ent/schema/card.go delete mode 100644 examples/transaction/ent/internal/data/ent/schema/user.go delete mode 100644 examples/transaction/ent/internal/data/ent/tx.go delete mode 100644 examples/transaction/ent/internal/data/ent/user.go delete mode 100644 examples/transaction/ent/internal/data/ent/user/user.go delete mode 100644 examples/transaction/ent/internal/data/ent/user/where.go delete mode 100644 examples/transaction/ent/internal/data/ent/user_create.go delete mode 100644 examples/transaction/ent/internal/data/ent/user_delete.go delete mode 100644 examples/transaction/ent/internal/data/ent/user_query.go delete mode 100644 examples/transaction/ent/internal/data/ent/user_update.go delete mode 100644 examples/transaction/ent/internal/data/transaction.go delete mode 100644 examples/transaction/ent/internal/server/grpc.go delete mode 100644 examples/transaction/ent/internal/server/http.go delete mode 100644 examples/transaction/ent/internal/server/server.go delete mode 100644 examples/transaction/ent/internal/service/README.md delete mode 100644 examples/transaction/ent/internal/service/service.go delete mode 100644 examples/transaction/ent/internal/service/transaction.go delete mode 100644 examples/transaction/ent/openapi.yaml delete mode 100644 examples/transaction/gorm/Makefile delete mode 100644 examples/transaction/gorm/README.md delete mode 100644 examples/transaction/gorm/cmd/gorm/main.go delete mode 100644 examples/transaction/gorm/cmd/gorm/wire.go delete mode 100644 examples/transaction/gorm/cmd/gorm/wire_gen.go delete mode 100644 examples/transaction/gorm/configs/config.yaml delete mode 100644 examples/transaction/gorm/generate.go delete mode 100644 examples/transaction/gorm/internal/biz/README.md delete mode 100644 examples/transaction/gorm/internal/biz/biz.go delete mode 100644 examples/transaction/gorm/internal/biz/transaction.go delete mode 100644 examples/transaction/gorm/internal/conf/conf.pb.go delete mode 100644 examples/transaction/gorm/internal/conf/conf.proto delete mode 100644 examples/transaction/gorm/internal/data/README.md delete mode 100644 examples/transaction/gorm/internal/data/data.go delete mode 100644 examples/transaction/gorm/internal/data/transaction.go delete mode 100644 examples/transaction/gorm/internal/server/grpc.go delete mode 100644 examples/transaction/gorm/internal/server/http.go delete mode 100644 examples/transaction/gorm/internal/server/server.go delete mode 100644 examples/transaction/gorm/internal/service/README.md delete mode 100644 examples/transaction/gorm/internal/service/service.go delete mode 100644 examples/transaction/gorm/internal/service/transaction.go delete mode 100644 examples/transaction/gorm/openapi.yaml delete mode 100644 examples/transaction/openapi.yaml delete mode 100644 examples/validate/api/example.pb.go delete mode 100644 examples/validate/api/example.pb.validate.go delete mode 100644 examples/validate/api/example.proto delete mode 100644 examples/validate/api/example_grpc.pb.go delete mode 100644 examples/validate/api/example_http.pb.go delete mode 100644 examples/validate/main.go delete mode 100644 examples/ws/client/client.go delete mode 100644 examples/ws/handler/handler.go delete mode 100644 examples/ws/main.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2a3841cfc..396af7e11 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -67,9 +67,3 @@ jobs: cd cmd/protoc-gen-go-http go build ./... go test ./... - - - name: Examples - run: | - cd examples - go build ./... - go test ./... diff --git a/README.md b/README.md index 70eae38a4..c08a74c39 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Kratos is accessible, powerful, and provides tools required for large, robust ap ## Learning Kratos -Kratos has the most extensive and thorough [documentation](https://go-kratos.dev/en/docs/getting-started/start) and [example](./examples) library of all modern web application frameworks, making it a breeze to get started with the framework. +Kratos has the most extensive and thorough [documentation](https://go-kratos.dev/en/docs/getting-started/start) and [example](https://github.com/go-kratos/examples) library of all modern web application frameworks, making it a breeze to get started with the framework. We also provide a [modern template](https://github.com/go-kratos/kratos-layout), This template should help reduce the work required to setup up a modern project. diff --git a/README_zh.md b/README_zh.md index 8f53cb99c..b3ff21c36 100644 --- a/README_zh.md +++ b/README_zh.md @@ -38,18 +38,18 @@ Kratos 一套轻量级 Go 微服务框架,包含大量微服务相关功能及 * 工具链:包含大量工具链,比如 cache 代码生成,lint 工具等等; ## Features -* [APIs](examples/helloworld/helloworld):协议通信以 HTTP/gRPC 为基础,通过 Protobuf 进行定义; -* [Errors](examples/errors/api):通过 Protobuf 的 Enum 作为错误码定义,以及工具生成判定接口; -* [Metadata](examples/metadata):在协议通信 HTTP/gRPC 中,通过 Middleware 规范化服务元信息传递; -* [Config](examples/config):支持多数据源方式,进行配置合并铺平,通过 Atomic 方式支持动态配置; -* [Logger](examples/log):标准日志接口,可方便集成三方 log 库,并可通过 fluentd 收集日志; -* [Metrics](examples/metrics):统一指标接口,可以实现各种指标系统,默认集成 Prometheus; -* [Tracing](examples/traces):遵循 OpenTelemetry 规范定义,以实现微服务链路追踪; +* [APIs](https://github.com/go-kratos/examples/helloworld/helloworld) :协议通信以 HTTP/gRPC 为基础,通过 Protobuf 进行定义; +* [Errors](https://github.com/go-kratos/examples/errors/api) :通过 Protobuf 的 Enum 作为错误码定义,以及工具生成判定接口; +* [Metadata](https://github.com/go-kratos/examples/metadata) :在协议通信 HTTP/gRPC 中,通过 Middleware 规范化服务元信息传递; +* [Config](https://github.com/go-kratos/examples/config) :支持多数据源方式,进行配置合并铺平,通过 Atomic 方式支持动态配置; +* [Logger](https://github.com/go-kratos/examples/log) :标准日志接口,可方便集成三方 log 库,并可通过 fluentd 收集日志; +* [Metrics](https://github.com/go-kratos/examples/metrics) :统一指标接口,可以实现各种指标系统,默认集成 Prometheus; +* [Tracing](https://github.com/go-kratos/examples/traces) :遵循 OpenTelemetry 规范定义,以实现微服务链路追踪; * [Encoding](encoding):支持 Accept 和 Content-Type 进行自动选择内容编码; -* [Transport](transport/transport.go):通用的 [HTTP](examples/http/middlewares)/[gRPC](examples/middleware/main.go) 传输层,实现统一的 [Middleware](middleware) 插件支持; -* [Registry](examples/registry):实现统一注册中心接口,可插件化对接各种注册中心; -* [Validation](examples/validate): 通过Protobuf统一定义校验规则,并同时适用于HTTP/gRPC服务. -* [SwaggerAPI](https://github.com/go-kratos/swagger-api/blob/main/examples/helloworld/server/main.go): 通过集成第三方[Swagger插件](https://github.com/go-kratos/swagger-api)能够自动生成Swagger API json并启动一个内置的Swaager UI服务. +* [Transport](transport/transport.go) :通用的 [HTTP](https://github.com/go-kratos/examples/http/middlewares) /[gRPC](https://github.com/go-kratos/examples/middleware/main.go) 传输层,实现统一的 [Middleware](middleware) 插件支持; +* [Registry](https://github.com/go-kratos/examples/registry) :实现统一注册中心接口,可插件化对接各种注册中心; +* [Validation](https://github.com/go-kratos/examples/validate): 通过Protobuf统一定义校验规则,并同时适用于HTTP/gRPC服务. +* [SwaggerAPI](https://github.com/go-kratos/swagger-api/blob/main/examples/helloworld/server/main.go): 通过集成第三方[Swagger插件](https://github.com/go-kratos/swagger-api) 能够自动生成Swagger API json并启动一个内置的Swaager UI服务. ## Getting Started ### Required @@ -113,7 +113,7 @@ app.Run() ## Related * [Docs](https://go-kratos.dev/) -* [Examples](./examples) +* [Examples](https://github.com/go-kratos/examples) * [Service Layout](https://github.com/go-kratos/kratos-layout) ## Community diff --git a/examples/LICENSE b/examples/LICENSE deleted file mode 100644 index fa53a35fa..000000000 --- a/examples/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Kratos - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/examples/README.md b/examples/README.md deleted file mode 100644 index 458059d2a..000000000 --- a/examples/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# examples - -- examples/blog is simple crud project. -- examples/config is kratos config example. -- examples/errors is kratos errors example, it is generated through proto-gen-go-errors. -- examples/helloworld is helloworld example. -- examples/http is transport/http some examples of usage. -- examples/log is log example, including、logger、helper、filter、valuer, etc. -- examples/metadata is metadata example. -- examples/metrics is metrics example, in the example, prom is used to collect data. -- examples/registry is registration and discovery examples,including Etcd, Consul, Nacos. -- examples/traces is middleware/tracing example,middleware/tracing is implemented by opentelemetry. -- examples/validate is middleware/validate example, the verification code is generated by proto-gen-validate. -- examples/ws is implementation of transport interface with websocket example. -- examples/swagger is implementation of server with embed swagger api. diff --git a/examples/auth/jwt/main.go b/examples/auth/jwt/main.go deleted file mode 100644 index b1cd22eb0..000000000 --- a/examples/auth/jwt/main.go +++ /dev/null @@ -1,68 +0,0 @@ -package main - -import ( - "context" - "log" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/middleware/auth/jwt" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - jwtv4 "github.com/golang-jwt/jwt/v4" -) - -type server struct { - helloworld.UnimplementedGreeterServer - - hc helloworld.GreeterClient -} - -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - return &helloworld.HelloReply{Message: "hello from service"}, nil -} - -func main() { - testKey := "testKey" - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - jwt.Server(func(token *jwtv4.Token) (interface{}, error) { - return []byte(testKey), nil - }), - ), - ) - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - jwt.Server(func(token *jwtv4.Token) (interface{}, error) { - return []byte(testKey), nil - }), - ), - ) - serviceTestKey := "serviceTestKey" - con, _ := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("dns:///127.0.0.1:9001"), - grpc.WithMiddleware( - jwt.Client(func(token *jwtv4.Token) (interface{}, error) { - return []byte(serviceTestKey), nil - }), - ), - ) - s := &server{ - hc: helloworld.NewGreeterClient(con), - } - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - app := kratos.New( - kratos.Name("helloworld"), - kratos.Server( - httpSrv, - grpcSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/benchmark/README.md b/examples/benchmark/README.md deleted file mode 100644 index 7cec7a561..000000000 --- a/examples/benchmark/README.md +++ /dev/null @@ -1,14 +0,0 @@ - -### Explain -This example is condensed by [go-web-framework-benchmark](https://github.com/smallnest/go-web-framework-benchmark) - -### Dependent -- wrk https://github.com/wg/wrk -- gnuplot http://www.gnuplot.info/ - -### Run -```bash -go build -o gowebbenchmark *.go -./test.sh -./testresults/plot.sh or plot_mac.sh -``` diff --git a/examples/benchmark/libs.sh b/examples/benchmark/libs.sh deleted file mode 100644 index 3a9ec9b08..000000000 --- a/examples/benchmark/libs.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -web_frameworks=("kratos" "gin" "echo" "mux") diff --git a/examples/benchmark/main.go b/examples/benchmark/main.go deleted file mode 100644 index 08021c774..000000000 --- a/examples/benchmark/main.go +++ /dev/null @@ -1,197 +0,0 @@ -package main - -import ( - "crypto/sha256" - "fmt" - "log" - "math/big" - http2 "net/http" - "os" - "runtime" - "strconv" - "time" - - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/transport/http" - - "github.com/gin-gonic/gin" - "github.com/gorilla/mux" - "github.com/labstack/echo/v4" -) - -var ( - port = 8080 - sleepTime = 0 - cpuBound bool - target = 15 - sleepTimeDuration time.Duration - message = []byte("hello world") - samplingPoint = 20 // seconds -) - -func main() { - args := os.Args - argsLen := len(args) - webFramework := "kratos" - if argsLen > 1 { - webFramework = args[1] - } - if argsLen > 2 { //nolint:gomnd - sleepTime, _ = strconv.Atoi(args[2]) - if sleepTime == -1 { - cpuBound = true - sleepTime = 0 - } - } - if argsLen > 3 { //nolint:gomnd - port, _ = strconv.Atoi(args[3]) - } - if argsLen > 4 { //nolint:gomnd - samplingPoint, _ = strconv.Atoi(args[4]) - } - sleepTimeDuration = time.Duration(sleepTime) * time.Millisecond - samplingPointDuration := time.Duration(samplingPoint) * time.Second - - go func() { - time.Sleep(samplingPointDuration) - var mem runtime.MemStats - runtime.ReadMemStats(&mem) - var u uint64 = 1024 * 1024 - fmt.Printf("TotalAlloc: %d\n", mem.TotalAlloc/u) - fmt.Printf("Alloc: %d\n", mem.Alloc/u) - fmt.Printf("HeapAlloc: %d\n", mem.HeapAlloc/u) - fmt.Printf("HeapSys: %d\n", mem.HeapSys/u) - }() - - switch webFramework { - case "kratos": - KratosServer() - case "gin": - GinServer() - case "echo": - EchoServer() - case "mux": - MuxServer() - default: - fmt.Println("--------------------------------------------------------------------") - fmt.Println("------------- Unknown framework given!!! Check libs.sh -------------") - fmt.Println("------------- Unknown framework given!!! Check libs.sh -------------") - fmt.Println("------------- Unknown framework given!!! Check libs.sh -------------") - fmt.Println("--------------------------------------------------------------------") - } -} - -func KratosServer() { - httpSrv := http.NewServer( - http.Address(":" + strconv.Itoa(port)), - ) - httpSrv.HandleFunc("/", kratosHandle) - app := kratos.New( - kratos.Name("benchmark"), - kratos.Server( - httpSrv, - ), - ) - - if err := app.Run(); err != nil { - log.Fatal(err) - } -} - -func kratosHandle(w http2.ResponseWriter, q *http2.Request) { - if cpuBound { - pow(target) - } else { - if sleepTime > 0 { - time.Sleep(sleepTimeDuration) - } else { - runtime.Gosched() - } - } - _, _ = w.Write(message) -} - -func GinServer() { - gin.SetMode(gin.ReleaseMode) - mux := gin.New() - mux.GET("/", ginHandler) - _ = mux.Run(":" + strconv.Itoa(port)) -} - -func ginHandler(c *gin.Context) { - if cpuBound { - pow(target) - } else { - if sleepTime > 0 { - time.Sleep(sleepTimeDuration) - } else { - runtime.Gosched() - } - } - _, _ = c.Writer.Write(message) -} - -func EchoServer() { - e := echo.New() - e.GET("/", echoHandler) - _ = e.Start(":" + strconv.Itoa(port)) -} - -func echoHandler(c echo.Context) error { - if cpuBound { - pow(target) - } else { - if sleepTime > 0 { - time.Sleep(sleepTimeDuration) - } else { - runtime.Gosched() - } - } - _, _ = c.Response().Write(message) - return nil -} - -func MuxServer() { - r := mux.NewRouter() - r.HandleFunc("/", muxHandle) - http2.Handle("/", r) - _ = http2.ListenAndServe(":"+strconv.Itoa(port), r) -} - -func muxHandle(w http2.ResponseWriter, q *http2.Request) { - if cpuBound { - pow(target) - } else { - if sleepTime > 0 { - time.Sleep(sleepTimeDuration) - } else { - runtime.Gosched() - } - } - _, _ = w.Write(message) -} - -func pow(targetBits int) { - target := big.NewInt(1) - target.Lsh(target, uint(256-targetBits)) - - var hashInt big.Int - var hash [32]byte - nonce := 0 - - for { - data := "hello world " + strconv.Itoa(nonce) - hash = sha256.Sum256([]byte(data)) - hashInt.SetBytes(hash[:]) - - if hashInt.Cmp(target) == -1 { - break - } else { - nonce++ - } - - if nonce%100 == 0 { - runtime.Gosched() - } - } -} diff --git a/examples/benchmark/test.sh b/examples/benchmark/test.sh deleted file mode 100755 index 7df7ff425..000000000 --- a/examples/benchmark/test.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash - -server_bin_name="gowebbenchmark" - -. ./libs.sh - -length=${#web_frameworks[@]} - -test_result=() - -cpu_cores=`cat /proc/cpuinfo|grep processor|wc -l` -if [ $cpu_cores -eq 0 ] -then - cpu_cores=1 -fi - -test_web_framework() -{ - echo "testing web framework: $2" - ./$server_bin_name $2 $3 & - sleep 2 - - throughput=`wrk -t$cpu_cores -c$4 -d30s http://127.0.0.1:8080/ | grep Requests/sec | awk '{print $2}'` - echo "throughput: $throughput requests/second" - test_result[$1]=$throughput - - pkill -9 $server_bin_name - sleep 2 - echo "finished testing $2" - echo -} - -test_all() -{ - echo "###################################" - echo " " - echo " ProcessingTime $1ms " - echo " Concurrency $2 " - echo " " - echo "###################################" - for ((i=0; i<$length; i++)) - do - test_web_framework $i ${web_frameworks[$i]} $1 $2 - done -} - - -pkill -9 $server_bin_name - -echo ","$(IFS=$','; echo "${web_frameworks[*]}" ) > processtime.csv -test_all 0 5000 -echo "0 ms,"$(IFS=$','; echo "${test_result[*]}" ) >> processtime.csv -test_all 10 5000 -echo "10 ms,"$(IFS=$','; echo "${test_result[*]}" ) >> processtime.csv -test_all 100 5000 -echo "100 ms,"$(IFS=$','; echo "${test_result[*]}" ) >> processtime.csv -test_all 500 5000 -echo "500 ms,"$(IFS=$','; echo "${test_result[*]}" ) >> processtime.csv - - -echo ","$(IFS=$','; echo "${web_frameworks[*]}" ) > concurrency.csv -test_all 30 100 -echo "100,"$(IFS=$','; echo "${test_result[*]}" ) >> concurrency.csv -test_all 30 1000 -echo "1000,"$(IFS=$','; echo "${test_result[*]}" ) >> concurrency.csv -test_all 30 5000 -echo "5000,"$(IFS=$','; echo "${test_result[*]}" ) >> concurrency.csv - - -test_all -1 5000 -echo ","$(IFS=$','; echo "${web_frameworks[*]}" ) > cpubound.csv -echo "cpu-bound,"$(IFS=$','; echo "${test_result[*]}" ) >> cpubound.csv - -echo ","$(IFS=$','; echo "${web_frameworks[*]}" ) > cpubound-concurrency.csv -test_all -1 100 -echo "100,"$(IFS=$','; echo "${test_result[*]}" ) >> cpubound-concurrency.csv -test_all -1 1000 -echo "1000,"$(IFS=$','; echo "${test_result[*]}" ) >> cpubound-concurrency.csv -test_all -1 5000 -echo "5000,"$(IFS=$','; echo "${test_result[*]}" ) >> cpubound-concurrency.csv - - -mv -f processtime.csv ./testresults -mv -f concurrency.csv ./testresults -mv -f cpubound.csv ./testresults -mv -f cpubound-concurrency.csv ./testresults diff --git a/examples/benchmark/testresults/benchmark.gnu b/examples/benchmark/testresults/benchmark.gnu deleted file mode 100644 index a7eee7a26..000000000 --- a/examples/benchmark/testresults/benchmark.gnu +++ /dev/null @@ -1,22 +0,0 @@ -reset -set title "Benchmark of different processing time" -set boxwidth 0.9 -set datafile separator "," -set style data histogram -set style histogram clustered gap 2 -set style fill solid 0.7 border -set border lw 0.8 - -set ylabel "requests / second" -set xtics nomirror rotate by -45 -set ytics nomirror - -set border 1+2 back -set boxwidth -2 - -set grid - -set term pngcairo font "Times Roman,14" enhanced size 1024,600 background rgb "gray80" -set output "../benchmark.png" - -plot 't_processtime.csv' using 2:xticlabels(1) title columnheader(2), '' using 3:xticlabels(1) title columnheader(3), '' using 4:xticlabels(1) title columnheader(4), '' using 5:xticlabels(1) title columnheader(5) diff --git a/examples/benchmark/testresults/plot.sh b/examples/benchmark/testresults/plot.sh deleted file mode 100644 index 0eb7b9c55..000000000 --- a/examples/benchmark/testresults/plot.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -m_path=$(dirname $0) -m_path=${m_path/\./$(pwd)} -cd $m_path - -./transpose.sh - -gnuplot benchmark.gnu - -rm -fr t_*.csv diff --git a/examples/benchmark/testresults/plot_mac.sh b/examples/benchmark/testresults/plot_mac.sh deleted file mode 100644 index ab925e0cb..000000000 --- a/examples/benchmark/testresults/plot_mac.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -m_path=$(dirname $0) -m_path=${m_path/\./$(pwd)} -cd $m_path - -./transpose.sh - -gnuplot -c benchmark.gnu - -rm -fr t_*.csv diff --git a/examples/benchmark/testresults/transpose.sh b/examples/benchmark/testresults/transpose.sh deleted file mode 100644 index d7cddd144..000000000 --- a/examples/benchmark/testresults/transpose.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -for file in `ls *.csv` -do - awk -f tst.awk $file > t_$file -done diff --git a/examples/benchmark/testresults/tst.awk b/examples/benchmark/testresults/tst.awk deleted file mode 100644 index d9cca236c..000000000 --- a/examples/benchmark/testresults/tst.awk +++ /dev/null @@ -1,15 +0,0 @@ -BEGIN { FS=OFS="," } -{ - for (rowNr=1;rowNr<=NF;rowNr++) { - cell[rowNr,NR] = $rowNr - } - maxRows = (NF > maxRows ? NF : maxRows) - maxCols = NR -} -END { - for (rowNr=1;rowNr<=maxRows;rowNr++) { - for (colNr=1;colNr<=maxCols;colNr++) { - printf "%s%s", cell[rowNr,colNr], (colNr < maxCols ? OFS : ORS) - } - } -} diff --git a/examples/blog/.gitignore b/examples/blog/.gitignore deleted file mode 100644 index c29907463..000000000 --- a/examples/blog/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# Reference https://github.com/github/gitignore/blob/master/Go.gitignore -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories (remove the comment below to include it) -vendor/ - -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# OS General -Thumbs.db -.DS_Store - -# project -*.cert -*.key -*.log -bin/ - -# Develop tools -.vscode/ -.idea/ -*.swp diff --git a/examples/blog/LICENSE b/examples/blog/LICENSE deleted file mode 100644 index 684318c72..000000000 --- a/examples/blog/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 go-kratos - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/examples/blog/Makefile b/examples/blog/Makefile deleted file mode 100644 index ec133d4d6..000000000 --- a/examples/blog/Makefile +++ /dev/null @@ -1,106 +0,0 @@ -GOPATH:=$(shell go env GOPATH) -VERSION=$(shell git describe --tags --always) -INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) -API_PROTO_FILES=$(shell find api -name *.proto) -KRATOS_VERSION=$(shell go mod graph |grep go-kratos/kratos/v2 |head -n 1 |awk -F '@' '{print $$2}') -KRATOS=$(GOPATH)/pkg/mod/github.com/go-kratos/kratos/v2@$(KRATOS_VERSION) - -.PHONY: init -# init env -init: - go get -u github.com/go-kratos/kratos/cmd/kratos/v2 - go get -u google.golang.org/protobuf/cmd/protoc-gen-go - go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc - go get -u github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2 - go get -u github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 - go get -u github.com/google/wire/cmd/wire - -.PHONY: grpc -# generate grpc code -grpc: - protoc --proto_path=. \ - --proto_path=$(KRATOS)/third_party \ - --go_out=paths=source_relative:. \ - --go-grpc_out=paths=source_relative:. \ - $(API_PROTO_FILES) - -.PHONY: http -# generate http code -http: - protoc --proto_path=. \ - --proto_path=$(KRATOS)/third_party \ - --go_out=paths=source_relative:. \ - --go-http_out=paths=source_relative:. \ - $(API_PROTO_FILES) - -.PHONY: errors -# generate errors code -errors: - protoc --proto_path=. \ - --proto_path=$(KRATOS)/third_party \ - --go_out=paths=source_relative:. \ - --go-errors_out=paths=source_relative:. \ - $(API_PROTO_FILES) - -.PHONY: proto -# generate internal proto -proto: - protoc --proto_path=. \ - --proto_path=$(KRATOS)/third_party \ - --go_out=paths=source_relative:. \ - $(INTERNAL_PROTO_FILES) - -.PHONY: swagger -# generate swagger file -swagger: - protoc --proto_path=. \ - --proto_path=$(KRATOS)/third_party \ - --openapiv2_out . \ - --openapiv2_opt logtostderr=true \ - $(API_PROTO_FILES) - -.PHONY: generate -# generate client code -generate: - go generate ./... - -.PHONY: build -# build -build: - mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./... - -.PHONY: test -# test -test: - go test -v ./... -cover - -.PHONY: all -# generate all -all: - make generate; - make grpc; - make http; - make proto; - make errors; - make swagger; - make build; - make test; - -# show help -help: - @echo '' - @echo 'Usage:' - @echo ' make [target]' - @echo '' - @echo 'Targets:' - @awk '/^[a-zA-Z\-\_0-9]+:/ { \ - helpMessage = match(lastLine, /^# (.*)/); \ - if (helpMessage) { \ - helpCommand = substr($$1, 0, index($$1, ":")-1); \ - helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \ - printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \ - } \ - } \ - { lastLine = $$0 }' $(MAKEFILE_LIST) - -.DEFAULT_GOAL := help diff --git a/examples/blog/README.md b/examples/blog/README.md deleted file mode 100644 index 4c85ae7cb..000000000 --- a/examples/blog/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# How to run this blog example server -1. You should ensure that your mysql server is running. -2. Ensure that the database named `testdb` has been created, - otherwise you should execute the following database script: -```mysql -create database testdb; -``` -3. Modify the `configs/config.yaml` file and add your mysql information in the data source: -```yaml -data: - database: - driver: mysql - source: root:password@tcp(127.0.0.1:3306)/testdb?parseTime=True -``` -4. Run your blog server: -```bash -$ go generate ./... -$ kratos run -``` diff --git a/examples/blog/api/blog/v1/blog.pb.go b/examples/blog/api/blog/v1/blog.pb.go deleted file mode 100644 index 6a720a53f..000000000 --- a/examples/blog/api/blog/v1/blog.pb.go +++ /dev/null @@ -1,870 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.17.0 -// source: blog.proto - -package v1 - -import ( - _ "github.com/envoyproxy/protoc-gen-validate/validate" - _ "google.golang.org/genproto/googleapis/api/annotations" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Article struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` - Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"` - Like int64 `protobuf:"varint,4,opt,name=like,proto3" json:"like,omitempty"` -} - -func (x *Article) Reset() { - *x = Article{} - if protoimpl.UnsafeEnabled { - mi := &file_blog_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Article) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Article) ProtoMessage() {} - -func (x *Article) ProtoReflect() protoreflect.Message { - mi := &file_blog_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Article.ProtoReflect.Descriptor instead. -func (*Article) Descriptor() ([]byte, []int) { - return file_blog_proto_rawDescGZIP(), []int{0} -} - -func (x *Article) GetId() int64 { - if x != nil { - return x.Id - } - return 0 -} - -func (x *Article) GetTitle() string { - if x != nil { - return x.Title - } - return "" -} - -func (x *Article) GetContent() string { - if x != nil { - return x.Content - } - return "" -} - -func (x *Article) GetLike() int64 { - if x != nil { - return x.Like - } - return 0 -} - -type CreateArticleRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` // the title of string must be between 5 and 50 character - Content string `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"` -} - -func (x *CreateArticleRequest) Reset() { - *x = CreateArticleRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_blog_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CreateArticleRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CreateArticleRequest) ProtoMessage() {} - -func (x *CreateArticleRequest) ProtoReflect() protoreflect.Message { - mi := &file_blog_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use CreateArticleRequest.ProtoReflect.Descriptor instead. -func (*CreateArticleRequest) Descriptor() ([]byte, []int) { - return file_blog_proto_rawDescGZIP(), []int{1} -} - -func (x *CreateArticleRequest) GetTitle() string { - if x != nil { - return x.Title - } - return "" -} - -func (x *CreateArticleRequest) GetContent() string { - if x != nil { - return x.Content - } - return "" -} - -type CreateArticleReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Article *Article `protobuf:"bytes,1,opt,name=Article,proto3" json:"Article,omitempty"` -} - -func (x *CreateArticleReply) Reset() { - *x = CreateArticleReply{} - if protoimpl.UnsafeEnabled { - mi := &file_blog_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CreateArticleReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CreateArticleReply) ProtoMessage() {} - -func (x *CreateArticleReply) ProtoReflect() protoreflect.Message { - mi := &file_blog_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use CreateArticleReply.ProtoReflect.Descriptor instead. -func (*CreateArticleReply) Descriptor() ([]byte, []int) { - return file_blog_proto_rawDescGZIP(), []int{2} -} - -func (x *CreateArticleReply) GetArticle() *Article { - if x != nil { - return x.Article - } - return nil -} - -type UpdateArticleRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` // the title of string must be between 5 and 50 character; - Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"` -} - -func (x *UpdateArticleRequest) Reset() { - *x = UpdateArticleRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_blog_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *UpdateArticleRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*UpdateArticleRequest) ProtoMessage() {} - -func (x *UpdateArticleRequest) ProtoReflect() protoreflect.Message { - mi := &file_blog_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use UpdateArticleRequest.ProtoReflect.Descriptor instead. -func (*UpdateArticleRequest) Descriptor() ([]byte, []int) { - return file_blog_proto_rawDescGZIP(), []int{3} -} - -func (x *UpdateArticleRequest) GetId() int64 { - if x != nil { - return x.Id - } - return 0 -} - -func (x *UpdateArticleRequest) GetTitle() string { - if x != nil { - return x.Title - } - return "" -} - -func (x *UpdateArticleRequest) GetContent() string { - if x != nil { - return x.Content - } - return "" -} - -type UpdateArticleReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Article *Article `protobuf:"bytes,1,opt,name=Article,proto3" json:"Article,omitempty"` -} - -func (x *UpdateArticleReply) Reset() { - *x = UpdateArticleReply{} - if protoimpl.UnsafeEnabled { - mi := &file_blog_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *UpdateArticleReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*UpdateArticleReply) ProtoMessage() {} - -func (x *UpdateArticleReply) ProtoReflect() protoreflect.Message { - mi := &file_blog_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use UpdateArticleReply.ProtoReflect.Descriptor instead. -func (*UpdateArticleReply) Descriptor() ([]byte, []int) { - return file_blog_proto_rawDescGZIP(), []int{4} -} - -func (x *UpdateArticleReply) GetArticle() *Article { - if x != nil { - return x.Article - } - return nil -} - -type DeleteArticleRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (x *DeleteArticleRequest) Reset() { - *x = DeleteArticleRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_blog_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DeleteArticleRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DeleteArticleRequest) ProtoMessage() {} - -func (x *DeleteArticleRequest) ProtoReflect() protoreflect.Message { - mi := &file_blog_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DeleteArticleRequest.ProtoReflect.Descriptor instead. -func (*DeleteArticleRequest) Descriptor() ([]byte, []int) { - return file_blog_proto_rawDescGZIP(), []int{5} -} - -func (x *DeleteArticleRequest) GetId() int64 { - if x != nil { - return x.Id - } - return 0 -} - -type DeleteArticleReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *DeleteArticleReply) Reset() { - *x = DeleteArticleReply{} - if protoimpl.UnsafeEnabled { - mi := &file_blog_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DeleteArticleReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DeleteArticleReply) ProtoMessage() {} - -func (x *DeleteArticleReply) ProtoReflect() protoreflect.Message { - mi := &file_blog_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DeleteArticleReply.ProtoReflect.Descriptor instead. -func (*DeleteArticleReply) Descriptor() ([]byte, []int) { - return file_blog_proto_rawDescGZIP(), []int{6} -} - -type GetArticleRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (x *GetArticleRequest) Reset() { - *x = GetArticleRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_blog_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetArticleRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetArticleRequest) ProtoMessage() {} - -func (x *GetArticleRequest) ProtoReflect() protoreflect.Message { - mi := &file_blog_proto_msgTypes[7] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetArticleRequest.ProtoReflect.Descriptor instead. -func (*GetArticleRequest) Descriptor() ([]byte, []int) { - return file_blog_proto_rawDescGZIP(), []int{7} -} - -func (x *GetArticleRequest) GetId() int64 { - if x != nil { - return x.Id - } - return 0 -} - -type GetArticleReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Article *Article `protobuf:"bytes,1,opt,name=Article,proto3" json:"Article,omitempty"` -} - -func (x *GetArticleReply) Reset() { - *x = GetArticleReply{} - if protoimpl.UnsafeEnabled { - mi := &file_blog_proto_msgTypes[8] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetArticleReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetArticleReply) ProtoMessage() {} - -func (x *GetArticleReply) ProtoReflect() protoreflect.Message { - mi := &file_blog_proto_msgTypes[8] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetArticleReply.ProtoReflect.Descriptor instead. -func (*GetArticleReply) Descriptor() ([]byte, []int) { - return file_blog_proto_rawDescGZIP(), []int{8} -} - -func (x *GetArticleReply) GetArticle() *Article { - if x != nil { - return x.Article - } - return nil -} - -type ListArticleRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *ListArticleRequest) Reset() { - *x = ListArticleRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_blog_proto_msgTypes[9] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ListArticleRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ListArticleRequest) ProtoMessage() {} - -func (x *ListArticleRequest) ProtoReflect() protoreflect.Message { - mi := &file_blog_proto_msgTypes[9] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ListArticleRequest.ProtoReflect.Descriptor instead. -func (*ListArticleRequest) Descriptor() ([]byte, []int) { - return file_blog_proto_rawDescGZIP(), []int{9} -} - -type ListArticleReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Results []*Article `protobuf:"bytes,1,rep,name=results,proto3" json:"results,omitempty"` -} - -func (x *ListArticleReply) Reset() { - *x = ListArticleReply{} - if protoimpl.UnsafeEnabled { - mi := &file_blog_proto_msgTypes[10] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ListArticleReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ListArticleReply) ProtoMessage() {} - -func (x *ListArticleReply) ProtoReflect() protoreflect.Message { - mi := &file_blog_proto_msgTypes[10] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ListArticleReply.ProtoReflect.Descriptor instead. -func (*ListArticleReply) Descriptor() ([]byte, []int) { - return file_blog_proto_rawDescGZIP(), []int{10} -} - -func (x *ListArticleReply) GetResults() []*Article { - if x != nil { - return x.Results - } - return nil -} - -var File_blog_proto protoreflect.FileDescriptor - -var file_blog_proto_rawDesc = []byte{ - 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x62, 0x6c, - 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, - 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0x5d, 0x0a, 0x07, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x74, - 0x69, 0x74, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, - 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6c, - 0x69, 0x6b, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x6c, 0x69, 0x6b, 0x65, 0x22, - 0x51, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x09, 0xfa, 0x42, 0x06, 0x72, 0x04, 0x10, 0x05, 0x18, - 0x32, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, - 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, - 0x6e, 0x74, 0x22, 0x44, 0x0a, 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, - 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x2e, 0x0a, 0x07, 0x41, 0x72, 0x74, 0x69, - 0x63, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x62, 0x6c, 0x6f, 0x67, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, - 0x07, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x22, 0x6a, 0x0a, 0x14, 0x55, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, 0xfa, 0x42, - 0x04, 0x22, 0x02, 0x20, 0x00, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1f, 0x0a, 0x05, 0x74, 0x69, 0x74, - 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x09, 0xfa, 0x42, 0x06, 0x72, 0x04, 0x10, - 0x05, 0x18, 0x32, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, - 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, - 0x74, 0x65, 0x6e, 0x74, 0x22, 0x44, 0x0a, 0x12, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x72, - 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x2e, 0x0a, 0x07, 0x41, 0x72, - 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x62, 0x6c, - 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, - 0x65, 0x52, 0x07, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x22, 0x26, 0x0a, 0x14, 0x44, 0x65, - 0x6c, 0x65, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, - 0x69, 0x64, 0x22, 0x14, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, - 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x23, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x41, - 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0x41, 0x0a, - 0x0f, 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, - 0x12, 0x2e, 0x0a, 0x07, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x14, 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, - 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x07, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, - 0x22, 0x14, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x42, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x72, - 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x2e, 0x0a, 0x07, 0x72, 0x65, - 0x73, 0x75, 0x6c, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x62, 0x6c, - 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, - 0x65, 0x52, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x32, 0xa7, 0x04, 0x0a, 0x0b, 0x42, - 0x6c, 0x6f, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6c, 0x0a, 0x0d, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x21, 0x2e, 0x62, 0x6c, - 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, - 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, - 0x17, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x11, 0x22, 0x0c, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x72, 0x74, - 0x69, 0x63, 0x6c, 0x65, 0x2f, 0x3a, 0x01, 0x2a, 0x12, 0x70, 0x0a, 0x0d, 0x55, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x21, 0x2e, 0x62, 0x6c, 0x6f, 0x67, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x72, - 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x62, - 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, - 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x1b, 0x82, - 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x1a, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x72, 0x74, 0x69, 0x63, - 0x6c, 0x65, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x3a, 0x01, 0x2a, 0x12, 0x6d, 0x0a, 0x0d, 0x44, 0x65, - 0x6c, 0x65, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x21, 0x2e, 0x62, 0x6c, - 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, - 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, - 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, - 0x65, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, - 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x2a, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x72, 0x74, - 0x69, 0x63, 0x6c, 0x65, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x64, 0x0a, 0x0a, 0x47, 0x65, 0x74, - 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, - 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, - 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, - 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, - 0x76, 0x31, 0x2f, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, - 0x63, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x1f, - 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, - 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1d, 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, - 0x73, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x14, - 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x12, 0x0c, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x72, 0x74, 0x69, - 0x63, 0x6c, 0x65, 0x2f, 0x42, 0x44, 0x0a, 0x0b, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x76, 0x31, 0x50, 0x01, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, 0x74, - 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x62, 0x6c, 0x6f, 0x67, - 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, -} - -var ( - file_blog_proto_rawDescOnce sync.Once - file_blog_proto_rawDescData = file_blog_proto_rawDesc -) - -func file_blog_proto_rawDescGZIP() []byte { - file_blog_proto_rawDescOnce.Do(func() { - file_blog_proto_rawDescData = protoimpl.X.CompressGZIP(file_blog_proto_rawDescData) - }) - return file_blog_proto_rawDescData -} - -var file_blog_proto_msgTypes = make([]protoimpl.MessageInfo, 11) -var file_blog_proto_goTypes = []interface{}{ - (*Article)(nil), // 0: blog.api.v1.Article - (*CreateArticleRequest)(nil), // 1: blog.api.v1.CreateArticleRequest - (*CreateArticleReply)(nil), // 2: blog.api.v1.CreateArticleReply - (*UpdateArticleRequest)(nil), // 3: blog.api.v1.UpdateArticleRequest - (*UpdateArticleReply)(nil), // 4: blog.api.v1.UpdateArticleReply - (*DeleteArticleRequest)(nil), // 5: blog.api.v1.DeleteArticleRequest - (*DeleteArticleReply)(nil), // 6: blog.api.v1.DeleteArticleReply - (*GetArticleRequest)(nil), // 7: blog.api.v1.GetArticleRequest - (*GetArticleReply)(nil), // 8: blog.api.v1.GetArticleReply - (*ListArticleRequest)(nil), // 9: blog.api.v1.ListArticleRequest - (*ListArticleReply)(nil), // 10: blog.api.v1.ListArticleReply -} -var file_blog_proto_depIdxs = []int32{ - 0, // 0: blog.api.v1.CreateArticleReply.Article:type_name -> blog.api.v1.Article - 0, // 1: blog.api.v1.UpdateArticleReply.Article:type_name -> blog.api.v1.Article - 0, // 2: blog.api.v1.GetArticleReply.Article:type_name -> blog.api.v1.Article - 0, // 3: blog.api.v1.ListArticleReply.results:type_name -> blog.api.v1.Article - 1, // 4: blog.api.v1.BlogService.CreateArticle:input_type -> blog.api.v1.CreateArticleRequest - 3, // 5: blog.api.v1.BlogService.UpdateArticle:input_type -> blog.api.v1.UpdateArticleRequest - 5, // 6: blog.api.v1.BlogService.DeleteArticle:input_type -> blog.api.v1.DeleteArticleRequest - 7, // 7: blog.api.v1.BlogService.GetArticle:input_type -> blog.api.v1.GetArticleRequest - 9, // 8: blog.api.v1.BlogService.ListArticle:input_type -> blog.api.v1.ListArticleRequest - 2, // 9: blog.api.v1.BlogService.CreateArticle:output_type -> blog.api.v1.CreateArticleReply - 4, // 10: blog.api.v1.BlogService.UpdateArticle:output_type -> blog.api.v1.UpdateArticleReply - 6, // 11: blog.api.v1.BlogService.DeleteArticle:output_type -> blog.api.v1.DeleteArticleReply - 8, // 12: blog.api.v1.BlogService.GetArticle:output_type -> blog.api.v1.GetArticleReply - 10, // 13: blog.api.v1.BlogService.ListArticle:output_type -> blog.api.v1.ListArticleReply - 9, // [9:14] is the sub-list for method output_type - 4, // [4:9] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name -} - -func init() { file_blog_proto_init() } -func file_blog_proto_init() { - if File_blog_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_blog_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Article); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_blog_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateArticleRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_blog_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateArticleReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_blog_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*UpdateArticleRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_blog_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*UpdateArticleReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_blog_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DeleteArticleRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_blog_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DeleteArticleReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_blog_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetArticleRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_blog_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetArticleReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_blog_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListArticleRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_blog_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListArticleReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_blog_proto_rawDesc, - NumEnums: 0, - NumMessages: 11, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_blog_proto_goTypes, - DependencyIndexes: file_blog_proto_depIdxs, - MessageInfos: file_blog_proto_msgTypes, - }.Build() - File_blog_proto = out.File - file_blog_proto_rawDesc = nil - file_blog_proto_goTypes = nil - file_blog_proto_depIdxs = nil -} diff --git a/examples/blog/api/blog/v1/blog.pb.validate.go b/examples/blog/api/blog/v1/blog.pb.validate.go deleted file mode 100644 index 82481fe94..000000000 --- a/examples/blog/api/blog/v1/blog.pb.validate.go +++ /dev/null @@ -1,846 +0,0 @@ -// Code generated by protoc-gen-validate. DO NOT EDIT. -// source: blog.proto - -package v1 - -import ( - "bytes" - "errors" - "fmt" - "net" - "net/mail" - "net/url" - "regexp" - "strings" - "time" - "unicode/utf8" - - "google.golang.org/protobuf/types/known/anypb" -) - -// ensure the imports are used -var ( - _ = bytes.MinRead - _ = errors.New("") - _ = fmt.Print - _ = utf8.UTFMax - _ = (*regexp.Regexp)(nil) - _ = (*strings.Reader)(nil) - _ = net.IPv4len - _ = time.Duration(0) - _ = (*url.URL)(nil) - _ = (*mail.Address)(nil) - _ = anypb.Any{} -) - -// Validate checks the field values on Article with the rules defined in the -// proto definition for this message. If any rules are violated, an error is returned. -func (m *Article) Validate() error { - if m == nil { - return nil - } - - // no validation rules for Id - - // no validation rules for Title - - // no validation rules for Content - - // no validation rules for Like - - return nil -} - -// ArticleValidationError is the validation error returned by Article.Validate -// if the designated constraints aren't met. -type ArticleValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e ArticleValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e ArticleValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e ArticleValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e ArticleValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e ArticleValidationError) ErrorName() string { return "ArticleValidationError" } - -// Error satisfies the builtin error interface -func (e ArticleValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sArticle.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = ArticleValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = ArticleValidationError{} - -// Validate checks the field values on CreateArticleRequest with the rules -// defined in the proto definition for this message. If any rules are -// violated, an error is returned. -func (m *CreateArticleRequest) Validate() error { - if m == nil { - return nil - } - - if l := utf8.RuneCountInString(m.GetTitle()); l < 5 || l > 50 { - return CreateArticleRequestValidationError{ - field: "Title", - reason: "value length must be between 5 and 50 runes, inclusive", - } - } - - // no validation rules for Content - - return nil -} - -// CreateArticleRequestValidationError is the validation error returned by -// CreateArticleRequest.Validate if the designated constraints aren't met. -type CreateArticleRequestValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e CreateArticleRequestValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e CreateArticleRequestValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e CreateArticleRequestValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e CreateArticleRequestValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e CreateArticleRequestValidationError) ErrorName() string { - return "CreateArticleRequestValidationError" -} - -// Error satisfies the builtin error interface -func (e CreateArticleRequestValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sCreateArticleRequest.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = CreateArticleRequestValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = CreateArticleRequestValidationError{} - -// Validate checks the field values on CreateArticleReply with the rules -// defined in the proto definition for this message. If any rules are -// violated, an error is returned. -func (m *CreateArticleReply) Validate() error { - if m == nil { - return nil - } - - if v, ok := interface{}(m.GetArticle()).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return CreateArticleReplyValidationError{ - field: "Article", - reason: "embedded message failed validation", - cause: err, - } - } - } - - return nil -} - -// CreateArticleReplyValidationError is the validation error returned by -// CreateArticleReply.Validate if the designated constraints aren't met. -type CreateArticleReplyValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e CreateArticleReplyValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e CreateArticleReplyValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e CreateArticleReplyValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e CreateArticleReplyValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e CreateArticleReplyValidationError) ErrorName() string { - return "CreateArticleReplyValidationError" -} - -// Error satisfies the builtin error interface -func (e CreateArticleReplyValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sCreateArticleReply.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = CreateArticleReplyValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = CreateArticleReplyValidationError{} - -// Validate checks the field values on UpdateArticleRequest with the rules -// defined in the proto definition for this message. If any rules are -// violated, an error is returned. -func (m *UpdateArticleRequest) Validate() error { - if m == nil { - return nil - } - - if m.GetId() <= 0 { - return UpdateArticleRequestValidationError{ - field: "Id", - reason: "value must be greater than 0", - } - } - - if l := utf8.RuneCountInString(m.GetTitle()); l < 5 || l > 50 { - return UpdateArticleRequestValidationError{ - field: "Title", - reason: "value length must be between 5 and 50 runes, inclusive", - } - } - - // no validation rules for Content - - return nil -} - -// UpdateArticleRequestValidationError is the validation error returned by -// UpdateArticleRequest.Validate if the designated constraints aren't met. -type UpdateArticleRequestValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e UpdateArticleRequestValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e UpdateArticleRequestValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e UpdateArticleRequestValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e UpdateArticleRequestValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e UpdateArticleRequestValidationError) ErrorName() string { - return "UpdateArticleRequestValidationError" -} - -// Error satisfies the builtin error interface -func (e UpdateArticleRequestValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sUpdateArticleRequest.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = UpdateArticleRequestValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = UpdateArticleRequestValidationError{} - -// Validate checks the field values on UpdateArticleReply with the rules -// defined in the proto definition for this message. If any rules are -// violated, an error is returned. -func (m *UpdateArticleReply) Validate() error { - if m == nil { - return nil - } - - if v, ok := interface{}(m.GetArticle()).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return UpdateArticleReplyValidationError{ - field: "Article", - reason: "embedded message failed validation", - cause: err, - } - } - } - - return nil -} - -// UpdateArticleReplyValidationError is the validation error returned by -// UpdateArticleReply.Validate if the designated constraints aren't met. -type UpdateArticleReplyValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e UpdateArticleReplyValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e UpdateArticleReplyValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e UpdateArticleReplyValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e UpdateArticleReplyValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e UpdateArticleReplyValidationError) ErrorName() string { - return "UpdateArticleReplyValidationError" -} - -// Error satisfies the builtin error interface -func (e UpdateArticleReplyValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sUpdateArticleReply.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = UpdateArticleReplyValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = UpdateArticleReplyValidationError{} - -// Validate checks the field values on DeleteArticleRequest with the rules -// defined in the proto definition for this message. If any rules are -// violated, an error is returned. -func (m *DeleteArticleRequest) Validate() error { - if m == nil { - return nil - } - - // no validation rules for Id - - return nil -} - -// DeleteArticleRequestValidationError is the validation error returned by -// DeleteArticleRequest.Validate if the designated constraints aren't met. -type DeleteArticleRequestValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e DeleteArticleRequestValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e DeleteArticleRequestValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e DeleteArticleRequestValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e DeleteArticleRequestValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e DeleteArticleRequestValidationError) ErrorName() string { - return "DeleteArticleRequestValidationError" -} - -// Error satisfies the builtin error interface -func (e DeleteArticleRequestValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sDeleteArticleRequest.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = DeleteArticleRequestValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = DeleteArticleRequestValidationError{} - -// Validate checks the field values on DeleteArticleReply with the rules -// defined in the proto definition for this message. If any rules are -// violated, an error is returned. -func (m *DeleteArticleReply) Validate() error { - if m == nil { - return nil - } - - return nil -} - -// DeleteArticleReplyValidationError is the validation error returned by -// DeleteArticleReply.Validate if the designated constraints aren't met. -type DeleteArticleReplyValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e DeleteArticleReplyValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e DeleteArticleReplyValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e DeleteArticleReplyValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e DeleteArticleReplyValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e DeleteArticleReplyValidationError) ErrorName() string { - return "DeleteArticleReplyValidationError" -} - -// Error satisfies the builtin error interface -func (e DeleteArticleReplyValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sDeleteArticleReply.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = DeleteArticleReplyValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = DeleteArticleReplyValidationError{} - -// Validate checks the field values on GetArticleRequest with the rules defined -// in the proto definition for this message. If any rules are violated, an -// error is returned. -func (m *GetArticleRequest) Validate() error { - if m == nil { - return nil - } - - // no validation rules for Id - - return nil -} - -// GetArticleRequestValidationError is the validation error returned by -// GetArticleRequest.Validate if the designated constraints aren't met. -type GetArticleRequestValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e GetArticleRequestValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e GetArticleRequestValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e GetArticleRequestValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e GetArticleRequestValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e GetArticleRequestValidationError) ErrorName() string { - return "GetArticleRequestValidationError" -} - -// Error satisfies the builtin error interface -func (e GetArticleRequestValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sGetArticleRequest.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = GetArticleRequestValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = GetArticleRequestValidationError{} - -// Validate checks the field values on GetArticleReply with the rules defined -// in the proto definition for this message. If any rules are violated, an -// error is returned. -func (m *GetArticleReply) Validate() error { - if m == nil { - return nil - } - - if v, ok := interface{}(m.GetArticle()).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return GetArticleReplyValidationError{ - field: "Article", - reason: "embedded message failed validation", - cause: err, - } - } - } - - return nil -} - -// GetArticleReplyValidationError is the validation error returned by -// GetArticleReply.Validate if the designated constraints aren't met. -type GetArticleReplyValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e GetArticleReplyValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e GetArticleReplyValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e GetArticleReplyValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e GetArticleReplyValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e GetArticleReplyValidationError) ErrorName() string { return "GetArticleReplyValidationError" } - -// Error satisfies the builtin error interface -func (e GetArticleReplyValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sGetArticleReply.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = GetArticleReplyValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = GetArticleReplyValidationError{} - -// Validate checks the field values on ListArticleRequest with the rules -// defined in the proto definition for this message. If any rules are -// violated, an error is returned. -func (m *ListArticleRequest) Validate() error { - if m == nil { - return nil - } - - return nil -} - -// ListArticleRequestValidationError is the validation error returned by -// ListArticleRequest.Validate if the designated constraints aren't met. -type ListArticleRequestValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e ListArticleRequestValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e ListArticleRequestValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e ListArticleRequestValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e ListArticleRequestValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e ListArticleRequestValidationError) ErrorName() string { - return "ListArticleRequestValidationError" -} - -// Error satisfies the builtin error interface -func (e ListArticleRequestValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sListArticleRequest.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = ListArticleRequestValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = ListArticleRequestValidationError{} - -// Validate checks the field values on ListArticleReply with the rules defined -// in the proto definition for this message. If any rules are violated, an -// error is returned. -func (m *ListArticleReply) Validate() error { - if m == nil { - return nil - } - - for idx, item := range m.GetResults() { - _, _ = idx, item - - if v, ok := interface{}(item).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return ListArticleReplyValidationError{ - field: fmt.Sprintf("Results[%v]", idx), - reason: "embedded message failed validation", - cause: err, - } - } - } - - } - - return nil -} - -// ListArticleReplyValidationError is the validation error returned by -// ListArticleReply.Validate if the designated constraints aren't met. -type ListArticleReplyValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e ListArticleReplyValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e ListArticleReplyValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e ListArticleReplyValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e ListArticleReplyValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e ListArticleReplyValidationError) ErrorName() string { return "ListArticleReplyValidationError" } - -// Error satisfies the builtin error interface -func (e ListArticleReplyValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sListArticleReply.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = ListArticleReplyValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = ListArticleReplyValidationError{} diff --git a/examples/blog/api/blog/v1/blog.proto b/examples/blog/api/blog/v1/blog.proto deleted file mode 100644 index 9587d71c7..000000000 --- a/examples/blog/api/blog/v1/blog.proto +++ /dev/null @@ -1,89 +0,0 @@ -syntax = "proto3"; - -package blog.api.v1; - -option go_package = "github.com/go-kratos/kratos/examples/blog/api/v1;v1"; -option java_multiple_files = true; -option java_package = "blog.api.v1"; - -import "google/api/annotations.proto"; -// the validate rules: -// https://github.com/envoyproxy/protoc-gen-validate -import "validate/validate.proto"; - -service BlogService { - rpc CreateArticle (CreateArticleRequest) returns (CreateArticleReply) { - option (google.api.http) = { - post: "/v1/article/" - body: "*" - }; - } - rpc UpdateArticle (UpdateArticleRequest) returns (UpdateArticleReply) { - option (google.api.http) = { - put: "/v1/article/{id}" - body: "*" - }; - } - rpc DeleteArticle (DeleteArticleRequest) returns (DeleteArticleReply) { - option (google.api.http) = { - delete: "/v1/article/{id}" - }; - } - rpc GetArticle (GetArticleRequest) returns (GetArticleReply) { - option (google.api.http) = { - get: "/v1/article/{id}" - }; - } - rpc ListArticle (ListArticleRequest) returns (ListArticleReply) { - option (google.api.http) = { - get: "/v1/article/" - }; - } -} - -message Article { - int64 id = 1; - string title = 2; - string content = 3; - int64 like = 4; -} - -message CreateArticleRequest { - string title = 1 [(validate.rules).string = {min_len: 5, max_len: 50}]; // the title of string must be between 5 and 50 character - string content = 2; -} - -message CreateArticleReply { - Article Article = 1; -} - -message UpdateArticleRequest { - int64 id = 1 [(validate.rules).int64 = {gt: 0}]; - string title = 2 [(validate.rules).string = {min_len: 5, max_len: 50}]; // the title of string must be between 5 and 50 character; - string content = 3; -} - -message UpdateArticleReply { - Article Article = 1; -} - -message DeleteArticleRequest { - int64 id = 1; -} -message DeleteArticleReply { -} - -message GetArticleRequest { - int64 id = 1; -} - -message GetArticleReply { - Article Article = 1; -} - -message ListArticleRequest { -} - -message ListArticleReply { - repeated Article results = 1; -} diff --git a/examples/blog/api/blog/v1/blog_grpc.pb.go b/examples/blog/api/blog/v1/blog_grpc.pb.go deleted file mode 100644 index 2402edeff..000000000 --- a/examples/blog/api/blog/v1/blog_grpc.pb.go +++ /dev/null @@ -1,245 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package v1 - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// BlogServiceClient is the client API for BlogService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type BlogServiceClient interface { - CreateArticle(ctx context.Context, in *CreateArticleRequest, opts ...grpc.CallOption) (*CreateArticleReply, error) - UpdateArticle(ctx context.Context, in *UpdateArticleRequest, opts ...grpc.CallOption) (*UpdateArticleReply, error) - DeleteArticle(ctx context.Context, in *DeleteArticleRequest, opts ...grpc.CallOption) (*DeleteArticleReply, error) - GetArticle(ctx context.Context, in *GetArticleRequest, opts ...grpc.CallOption) (*GetArticleReply, error) - ListArticle(ctx context.Context, in *ListArticleRequest, opts ...grpc.CallOption) (*ListArticleReply, error) -} - -type blogServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewBlogServiceClient(cc grpc.ClientConnInterface) BlogServiceClient { - return &blogServiceClient{cc} -} - -func (c *blogServiceClient) CreateArticle(ctx context.Context, in *CreateArticleRequest, opts ...grpc.CallOption) (*CreateArticleReply, error) { - out := new(CreateArticleReply) - err := c.cc.Invoke(ctx, "/blog.api.v1.BlogService/CreateArticle", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *blogServiceClient) UpdateArticle(ctx context.Context, in *UpdateArticleRequest, opts ...grpc.CallOption) (*UpdateArticleReply, error) { - out := new(UpdateArticleReply) - err := c.cc.Invoke(ctx, "/blog.api.v1.BlogService/UpdateArticle", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *blogServiceClient) DeleteArticle(ctx context.Context, in *DeleteArticleRequest, opts ...grpc.CallOption) (*DeleteArticleReply, error) { - out := new(DeleteArticleReply) - err := c.cc.Invoke(ctx, "/blog.api.v1.BlogService/DeleteArticle", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *blogServiceClient) GetArticle(ctx context.Context, in *GetArticleRequest, opts ...grpc.CallOption) (*GetArticleReply, error) { - out := new(GetArticleReply) - err := c.cc.Invoke(ctx, "/blog.api.v1.BlogService/GetArticle", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *blogServiceClient) ListArticle(ctx context.Context, in *ListArticleRequest, opts ...grpc.CallOption) (*ListArticleReply, error) { - out := new(ListArticleReply) - err := c.cc.Invoke(ctx, "/blog.api.v1.BlogService/ListArticle", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// BlogServiceServer is the server API for BlogService service. -// All implementations must embed UnimplementedBlogServiceServer -// for forward compatibility -type BlogServiceServer interface { - CreateArticle(context.Context, *CreateArticleRequest) (*CreateArticleReply, error) - UpdateArticle(context.Context, *UpdateArticleRequest) (*UpdateArticleReply, error) - DeleteArticle(context.Context, *DeleteArticleRequest) (*DeleteArticleReply, error) - GetArticle(context.Context, *GetArticleRequest) (*GetArticleReply, error) - ListArticle(context.Context, *ListArticleRequest) (*ListArticleReply, error) - mustEmbedUnimplementedBlogServiceServer() -} - -// UnimplementedBlogServiceServer must be embedded to have forward compatible implementations. -type UnimplementedBlogServiceServer struct { -} - -func (UnimplementedBlogServiceServer) CreateArticle(context.Context, *CreateArticleRequest) (*CreateArticleReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method CreateArticle not implemented") -} -func (UnimplementedBlogServiceServer) UpdateArticle(context.Context, *UpdateArticleRequest) (*UpdateArticleReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpdateArticle not implemented") -} -func (UnimplementedBlogServiceServer) DeleteArticle(context.Context, *DeleteArticleRequest) (*DeleteArticleReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method DeleteArticle not implemented") -} -func (UnimplementedBlogServiceServer) GetArticle(context.Context, *GetArticleRequest) (*GetArticleReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetArticle not implemented") -} -func (UnimplementedBlogServiceServer) ListArticle(context.Context, *ListArticleRequest) (*ListArticleReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method ListArticle not implemented") -} -func (UnimplementedBlogServiceServer) mustEmbedUnimplementedBlogServiceServer() {} - -// UnsafeBlogServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to BlogServiceServer will -// result in compilation errors. -type UnsafeBlogServiceServer interface { - mustEmbedUnimplementedBlogServiceServer() -} - -func RegisterBlogServiceServer(s grpc.ServiceRegistrar, srv BlogServiceServer) { - s.RegisterService(&BlogService_ServiceDesc, srv) -} - -func _BlogService_CreateArticle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CreateArticleRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(BlogServiceServer).CreateArticle(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/blog.api.v1.BlogService/CreateArticle", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(BlogServiceServer).CreateArticle(ctx, req.(*CreateArticleRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _BlogService_UpdateArticle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UpdateArticleRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(BlogServiceServer).UpdateArticle(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/blog.api.v1.BlogService/UpdateArticle", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(BlogServiceServer).UpdateArticle(ctx, req.(*UpdateArticleRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _BlogService_DeleteArticle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DeleteArticleRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(BlogServiceServer).DeleteArticle(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/blog.api.v1.BlogService/DeleteArticle", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(BlogServiceServer).DeleteArticle(ctx, req.(*DeleteArticleRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _BlogService_GetArticle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetArticleRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(BlogServiceServer).GetArticle(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/blog.api.v1.BlogService/GetArticle", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(BlogServiceServer).GetArticle(ctx, req.(*GetArticleRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _BlogService_ListArticle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListArticleRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(BlogServiceServer).ListArticle(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/blog.api.v1.BlogService/ListArticle", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(BlogServiceServer).ListArticle(ctx, req.(*ListArticleRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// BlogService_ServiceDesc is the grpc.ServiceDesc for BlogService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var BlogService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "blog.api.v1.BlogService", - HandlerType: (*BlogServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "CreateArticle", - Handler: _BlogService_CreateArticle_Handler, - }, - { - MethodName: "UpdateArticle", - Handler: _BlogService_UpdateArticle_Handler, - }, - { - MethodName: "DeleteArticle", - Handler: _BlogService_DeleteArticle_Handler, - }, - { - MethodName: "GetArticle", - Handler: _BlogService_GetArticle_Handler, - }, - { - MethodName: "ListArticle", - Handler: _BlogService_ListArticle_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "blog.proto", -} diff --git a/examples/blog/api/blog/v1/blog_http.pb.go b/examples/blog/api/blog/v1/blog_http.pb.go deleted file mode 100644 index 5c8a8129f..000000000 --- a/examples/blog/api/blog/v1/blog_http.pb.go +++ /dev/null @@ -1,220 +0,0 @@ -// Code generated by protoc-gen-go-http. DO NOT EDIT. -// versions: -// protoc-gen-go-http v2.0.0 - -package v1 - -import ( - context "context" - http "github.com/go-kratos/kratos/v2/transport/http" - binding "github.com/go-kratos/kratos/v2/transport/http/binding" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the kratos package it is being compiled against. -var _ = new(context.Context) -var _ = binding.EncodeURL - -const _ = http.SupportPackageIsVersion1 - -type BlogServiceHTTPServer interface { - CreateArticle(context.Context, *CreateArticleRequest) (*CreateArticleReply, error) - DeleteArticle(context.Context, *DeleteArticleRequest) (*DeleteArticleReply, error) - GetArticle(context.Context, *GetArticleRequest) (*GetArticleReply, error) - ListArticle(context.Context, *ListArticleRequest) (*ListArticleReply, error) - UpdateArticle(context.Context, *UpdateArticleRequest) (*UpdateArticleReply, error) -} - -func RegisterBlogServiceHTTPServer(s *http.Server, srv BlogServiceHTTPServer) { - r := s.Route("/") - r.POST("/v1/article/", _BlogService_CreateArticle0_HTTP_Handler(srv)) - r.PUT("/v1/article/{id}", _BlogService_UpdateArticle0_HTTP_Handler(srv)) - r.DELETE("/v1/article/{id}", _BlogService_DeleteArticle0_HTTP_Handler(srv)) - r.GET("/v1/article/{id}", _BlogService_GetArticle0_HTTP_Handler(srv)) - r.GET("/v1/article/", _BlogService_ListArticle0_HTTP_Handler(srv)) -} - -func _BlogService_CreateArticle0_HTTP_Handler(srv BlogServiceHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in CreateArticleRequest - if err := ctx.Bind(&in); err != nil { - return err - } - http.SetOperation(ctx, "/blog.api.v1.BlogService/CreateArticle") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.CreateArticle(ctx, req.(*CreateArticleRequest)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*CreateArticleReply) - return ctx.Result(200, reply) - } -} - -func _BlogService_UpdateArticle0_HTTP_Handler(srv BlogServiceHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in UpdateArticleRequest - if err := ctx.Bind(&in); err != nil { - return err - } - if err := ctx.BindVars(&in); err != nil { - return err - } - http.SetOperation(ctx, "/blog.api.v1.BlogService/UpdateArticle") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.UpdateArticle(ctx, req.(*UpdateArticleRequest)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*UpdateArticleReply) - return ctx.Result(200, reply) - } -} - -func _BlogService_DeleteArticle0_HTTP_Handler(srv BlogServiceHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in DeleteArticleRequest - if err := ctx.BindQuery(&in); err != nil { - return err - } - if err := ctx.BindVars(&in); err != nil { - return err - } - http.SetOperation(ctx, "/blog.api.v1.BlogService/DeleteArticle") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.DeleteArticle(ctx, req.(*DeleteArticleRequest)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*DeleteArticleReply) - return ctx.Result(200, reply) - } -} - -func _BlogService_GetArticle0_HTTP_Handler(srv BlogServiceHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in GetArticleRequest - if err := ctx.BindQuery(&in); err != nil { - return err - } - if err := ctx.BindVars(&in); err != nil { - return err - } - http.SetOperation(ctx, "/blog.api.v1.BlogService/GetArticle") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.GetArticle(ctx, req.(*GetArticleRequest)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*GetArticleReply) - return ctx.Result(200, reply) - } -} - -func _BlogService_ListArticle0_HTTP_Handler(srv BlogServiceHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in ListArticleRequest - if err := ctx.BindQuery(&in); err != nil { - return err - } - http.SetOperation(ctx, "/blog.api.v1.BlogService/ListArticle") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.ListArticle(ctx, req.(*ListArticleRequest)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*ListArticleReply) - return ctx.Result(200, reply) - } -} - -type BlogServiceHTTPClient interface { - CreateArticle(ctx context.Context, req *CreateArticleRequest, opts ...http.CallOption) (rsp *CreateArticleReply, err error) - DeleteArticle(ctx context.Context, req *DeleteArticleRequest, opts ...http.CallOption) (rsp *DeleteArticleReply, err error) - GetArticle(ctx context.Context, req *GetArticleRequest, opts ...http.CallOption) (rsp *GetArticleReply, err error) - ListArticle(ctx context.Context, req *ListArticleRequest, opts ...http.CallOption) (rsp *ListArticleReply, err error) - UpdateArticle(ctx context.Context, req *UpdateArticleRequest, opts ...http.CallOption) (rsp *UpdateArticleReply, err error) -} - -type BlogServiceHTTPClientImpl struct { - cc *http.Client -} - -func NewBlogServiceHTTPClient(client *http.Client) BlogServiceHTTPClient { - return &BlogServiceHTTPClientImpl{client} -} - -func (c *BlogServiceHTTPClientImpl) CreateArticle(ctx context.Context, in *CreateArticleRequest, opts ...http.CallOption) (*CreateArticleReply, error) { - var out CreateArticleReply - pattern := "/v1/article/" - path := binding.EncodeURL(pattern, in, false) - opts = append(opts, http.Operation("/blog.api.v1.BlogService/CreateArticle")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} - -func (c *BlogServiceHTTPClientImpl) DeleteArticle(ctx context.Context, in *DeleteArticleRequest, opts ...http.CallOption) (*DeleteArticleReply, error) { - var out DeleteArticleReply - pattern := "/v1/article/{id}" - path := binding.EncodeURL(pattern, in, true) - opts = append(opts, http.Operation("/blog.api.v1.BlogService/DeleteArticle")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "DELETE", path, nil, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} - -func (c *BlogServiceHTTPClientImpl) GetArticle(ctx context.Context, in *GetArticleRequest, opts ...http.CallOption) (*GetArticleReply, error) { - var out GetArticleReply - pattern := "/v1/article/{id}" - path := binding.EncodeURL(pattern, in, true) - opts = append(opts, http.Operation("/blog.api.v1.BlogService/GetArticle")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} - -func (c *BlogServiceHTTPClientImpl) ListArticle(ctx context.Context, in *ListArticleRequest, opts ...http.CallOption) (*ListArticleReply, error) { - var out ListArticleReply - pattern := "/v1/article/" - path := binding.EncodeURL(pattern, in, true) - opts = append(opts, http.Operation("/blog.api.v1.BlogService/ListArticle")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} - -func (c *BlogServiceHTTPClientImpl) UpdateArticle(ctx context.Context, in *UpdateArticleRequest, opts ...http.CallOption) (*UpdateArticleReply, error) { - var out UpdateArticleReply - pattern := "/v1/article/{id}" - path := binding.EncodeURL(pattern, in, false) - opts = append(opts, http.Operation("/blog.api.v1.BlogService/UpdateArticle")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "PUT", path, in, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} diff --git a/examples/blog/cmd/blog/main.go b/examples/blog/cmd/blog/main.go deleted file mode 100644 index bb127488e..000000000 --- a/examples/blog/cmd/blog/main.go +++ /dev/null @@ -1,103 +0,0 @@ -package main - -import ( - "flag" - "os" - - "github.com/go-kratos/kratos/examples/blog/internal/conf" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/config" - "github.com/go-kratos/kratos/v2/config/file" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/exporters/jaeger" - "go.opentelemetry.io/otel/sdk/resource" - tracesdk "go.opentelemetry.io/otel/sdk/trace" - semconv "go.opentelemetry.io/otel/semconv/v1.4.0" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name string - // Version is the version of the compiled software. - Version string - // flagconf is the config flag. - flagconf string -) - -func init() { - flag.StringVar(&flagconf, "conf", "../../configs", "config path, eg: -conf config.yaml") -} - -func newApp(logger log.Logger, hs *http.Server, gs *grpc.Server) *kratos.App { - return kratos.New( - kratos.Name(Name), - kratos.Version(Version), - kratos.Metadata(map[string]string{}), - kratos.Logger(logger), - kratos.Server( - hs, - gs, - ), - ) -} - -// Set global trace provider -func setTracerProvider(url string) error { - // Create the Jaeger exporter - exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url))) - if err != nil { - return err - } - tp := tracesdk.NewTracerProvider( - // Set the sampling rate based on the parent span to 100% - tracesdk.WithSampler(tracesdk.ParentBased(tracesdk.TraceIDRatioBased(1.0))), - // Always be sure to batch in production. - tracesdk.WithBatcher(exp), - // Record information about this application in an Resource. - tracesdk.WithResource(resource.NewSchemaless( - semconv.ServiceNameKey.String(Name), - attribute.String("env", "dev"), - )), - ) - otel.SetTracerProvider(tp) - return nil -} - -func main() { - flag.Parse() - logger := log.NewStdLogger(os.Stdout) - - cfg := config.New( - config.WithSource( - file.NewSource(flagconf), - ), - ) - if err := cfg.Load(); err != nil { - panic(err) - } - - var bc conf.Bootstrap - if err := cfg.Scan(&bc); err != nil { - panic(err) - } - - if err := setTracerProvider(bc.Trace.Endpoint); err != nil { - panic(err) - } - - app, cleanup, err := initApp(bc.Server, bc.Data, logger) - if err != nil { - panic(err) - } - defer cleanup() - - // start and wait for stop signal - if err := app.Run(); err != nil { - panic(err) - } -} diff --git a/examples/blog/cmd/blog/wire.go b/examples/blog/cmd/blog/wire.go deleted file mode 100644 index 30e5ebc43..000000000 --- a/examples/blog/cmd/blog/wire.go +++ /dev/null @@ -1,22 +0,0 @@ -//go:build wireinject -// +build wireinject - -// The build tag makes sure the stub is not built in the final build. - -package main - -import ( - "github.com/go-kratos/kratos/examples/blog/internal/biz" - "github.com/go-kratos/kratos/examples/blog/internal/conf" - "github.com/go-kratos/kratos/examples/blog/internal/data" - "github.com/go-kratos/kratos/examples/blog/internal/server" - "github.com/go-kratos/kratos/examples/blog/internal/service" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" - "github.com/google/wire" -) - -// initApp init kratos application. -func initApp(*conf.Server, *conf.Data, log.Logger) (*kratos.App, func(), error) { - panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) -} diff --git a/examples/blog/cmd/blog/wire_gen.go b/examples/blog/cmd/blog/wire_gen.go deleted file mode 100644 index 844b7c8cb..000000000 --- a/examples/blog/cmd/blog/wire_gen.go +++ /dev/null @@ -1,36 +0,0 @@ -// Code generated by Wire. DO NOT EDIT. - -//go:generate go run github.com/google/wire/cmd/wire -//go:build !wireinject -// +build !wireinject - -package main - -import ( - "github.com/go-kratos/kratos/examples/blog/internal/biz" - "github.com/go-kratos/kratos/examples/blog/internal/conf" - "github.com/go-kratos/kratos/examples/blog/internal/data" - "github.com/go-kratos/kratos/examples/blog/internal/server" - "github.com/go-kratos/kratos/examples/blog/internal/service" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" -) - -// Injectors from wire.go: - -// initApp init kratos application. -func initApp(confServer *conf.Server, confData *conf.Data, logger log.Logger) (*kratos.App, func(), error) { - dataData, cleanup, err := data.NewData(confData, logger) - if err != nil { - return nil, nil, err - } - articleRepo := data.NewArticleRepo(dataData, logger) - articleUsecase := biz.NewArticleUsecase(articleRepo, logger) - blogService := service.NewBlogService(articleUsecase, logger) - httpServer := server.NewHTTPServer(confServer, logger, blogService) - grpcServer := server.NewGRPCServer(confServer, logger, blogService) - app := newApp(logger, httpServer, grpcServer) - return app, func() { - cleanup() - }, nil -} diff --git a/examples/blog/configs/config.yaml b/examples/blog/configs/config.yaml deleted file mode 100644 index 511aa725e..000000000 --- a/examples/blog/configs/config.yaml +++ /dev/null @@ -1,18 +0,0 @@ -trace: - endpoint: http://127.0.0.1:14268/api/traces -server: - http: - addr: 0.0.0.0:8000 - timeout: 1s - grpc: - addr: 0.0.0.0:9000 - timeout: 1s -data: - database: - driver: mysql - source: root:password@tcp(127.0.0.1:3306)/testdb?parseTime=True - redis: - addr: 127.0.0.1:6379 - dial_timeout: 1s - read_timeout: 0.4s - write_timeout: 0.6s \ No newline at end of file diff --git a/examples/blog/generate.go b/examples/blog/generate.go deleted file mode 100644 index 4aac2aa9f..000000000 --- a/examples/blog/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package generate - -//go:generate kratos proto client . diff --git a/examples/blog/internal/biz/README.md b/examples/blog/internal/biz/README.md deleted file mode 100644 index 26a66b630..000000000 --- a/examples/blog/internal/biz/README.md +++ /dev/null @@ -1 +0,0 @@ -# Biz diff --git a/examples/blog/internal/biz/article.go b/examples/blog/internal/biz/article.go deleted file mode 100644 index bf5a6bc57..000000000 --- a/examples/blog/internal/biz/article.go +++ /dev/null @@ -1,74 +0,0 @@ -package biz - -import ( - "context" - "time" - - "github.com/go-kratos/kratos/v2/log" -) - -type Article struct { - ID int64 - Title string - Content string - CreatedAt time.Time - UpdatedAt time.Time - Like int64 -} - -type ArticleRepo interface { - // db - ListArticle(ctx context.Context) ([]*Article, error) - GetArticle(ctx context.Context, id int64) (*Article, error) - CreateArticle(ctx context.Context, article *Article) error - UpdateArticle(ctx context.Context, id int64, article *Article) error - DeleteArticle(ctx context.Context, id int64) error - - // redis - GetArticleLike(ctx context.Context, id int64) (rv int64, err error) - IncArticleLike(ctx context.Context, id int64) error -} - -type ArticleUsecase struct { - repo ArticleRepo -} - -func NewArticleUsecase(repo ArticleRepo, logger log.Logger) *ArticleUsecase { - return &ArticleUsecase{repo: repo} -} - -func (uc *ArticleUsecase) List(ctx context.Context) (ps []*Article, err error) { - ps, err = uc.repo.ListArticle(ctx) - if err != nil { - return - } - return -} - -func (uc *ArticleUsecase) Get(ctx context.Context, id int64) (p *Article, err error) { - p, err = uc.repo.GetArticle(ctx, id) - if err != nil { - return - } - err = uc.repo.IncArticleLike(ctx, id) - if err != nil { - return - } - p.Like, err = uc.repo.GetArticleLike(ctx, id) - if err != nil { - return - } - return -} - -func (uc *ArticleUsecase) Create(ctx context.Context, article *Article) error { - return uc.repo.CreateArticle(ctx, article) -} - -func (uc *ArticleUsecase) Update(ctx context.Context, id int64, article *Article) error { - return uc.repo.UpdateArticle(ctx, id, article) -} - -func (uc *ArticleUsecase) Delete(ctx context.Context, id int64) error { - return uc.repo.DeleteArticle(ctx, id) -} diff --git a/examples/blog/internal/biz/biz.go b/examples/blog/internal/biz/biz.go deleted file mode 100644 index 57580fe9c..000000000 --- a/examples/blog/internal/biz/biz.go +++ /dev/null @@ -1,6 +0,0 @@ -package biz - -import "github.com/google/wire" - -// ProviderSet is biz providers. -var ProviderSet = wire.NewSet(NewArticleUsecase) diff --git a/examples/blog/internal/conf/conf.pb.go b/examples/blog/internal/conf/conf.pb.go deleted file mode 100644 index 995d029ef..000000000 --- a/examples/blog/internal/conf/conf.pb.go +++ /dev/null @@ -1,763 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.17.0 -// source: conf.proto - -package conf - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - durationpb "google.golang.org/protobuf/types/known/durationpb" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Bootstrap struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Trace *Trace `protobuf:"bytes,1,opt,name=trace,proto3" json:"trace,omitempty"` - Server *Server `protobuf:"bytes,2,opt,name=server,proto3" json:"server,omitempty"` - Data *Data `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` -} - -func (x *Bootstrap) Reset() { - *x = Bootstrap{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Bootstrap) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Bootstrap) ProtoMessage() {} - -func (x *Bootstrap) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Bootstrap.ProtoReflect.Descriptor instead. -func (*Bootstrap) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{0} -} - -func (x *Bootstrap) GetTrace() *Trace { - if x != nil { - return x.Trace - } - return nil -} - -func (x *Bootstrap) GetServer() *Server { - if x != nil { - return x.Server - } - return nil -} - -func (x *Bootstrap) GetData() *Data { - if x != nil { - return x.Data - } - return nil -} - -type Server struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Http *Server_HTTP `protobuf:"bytes,1,opt,name=http,proto3" json:"http,omitempty"` - Grpc *Server_GRPC `protobuf:"bytes,2,opt,name=grpc,proto3" json:"grpc,omitempty"` -} - -func (x *Server) Reset() { - *x = Server{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server) ProtoMessage() {} - -func (x *Server) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server.ProtoReflect.Descriptor instead. -func (*Server) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{1} -} - -func (x *Server) GetHttp() *Server_HTTP { - if x != nil { - return x.Http - } - return nil -} - -func (x *Server) GetGrpc() *Server_GRPC { - if x != nil { - return x.Grpc - } - return nil -} - -type Data struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Database *Data_Database `protobuf:"bytes,1,opt,name=database,proto3" json:"database,omitempty"` - Redis *Data_Redis `protobuf:"bytes,2,opt,name=redis,proto3" json:"redis,omitempty"` -} - -func (x *Data) Reset() { - *x = Data{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data) ProtoMessage() {} - -func (x *Data) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data.ProtoReflect.Descriptor instead. -func (*Data) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{2} -} - -func (x *Data) GetDatabase() *Data_Database { - if x != nil { - return x.Database - } - return nil -} - -func (x *Data) GetRedis() *Data_Redis { - if x != nil { - return x.Redis - } - return nil -} - -type Trace struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Endpoint string `protobuf:"bytes,1,opt,name=endpoint,proto3" json:"endpoint,omitempty"` -} - -func (x *Trace) Reset() { - *x = Trace{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Trace) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Trace) ProtoMessage() {} - -func (x *Trace) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Trace.ProtoReflect.Descriptor instead. -func (*Trace) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{3} -} - -func (x *Trace) GetEndpoint() string { - if x != nil { - return x.Endpoint - } - return "" -} - -type Server_HTTP struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - Timeout *durationpb.Duration `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"` -} - -func (x *Server_HTTP) Reset() { - *x = Server_HTTP{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server_HTTP) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server_HTTP) ProtoMessage() {} - -func (x *Server_HTTP) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server_HTTP.ProtoReflect.Descriptor instead. -func (*Server_HTTP) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{1, 0} -} - -func (x *Server_HTTP) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Server_HTTP) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Server_HTTP) GetTimeout() *durationpb.Duration { - if x != nil { - return x.Timeout - } - return nil -} - -type Server_GRPC struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - Timeout *durationpb.Duration `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"` -} - -func (x *Server_GRPC) Reset() { - *x = Server_GRPC{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server_GRPC) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server_GRPC) ProtoMessage() {} - -func (x *Server_GRPC) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server_GRPC.ProtoReflect.Descriptor instead. -func (*Server_GRPC) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{1, 1} -} - -func (x *Server_GRPC) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Server_GRPC) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Server_GRPC) GetTimeout() *durationpb.Duration { - if x != nil { - return x.Timeout - } - return nil -} - -type Data_Database struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Driver string `protobuf:"bytes,1,opt,name=driver,proto3" json:"driver,omitempty"` - Source string `protobuf:"bytes,2,opt,name=source,proto3" json:"source,omitempty"` -} - -func (x *Data_Database) Reset() { - *x = Data_Database{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data_Database) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data_Database) ProtoMessage() {} - -func (x *Data_Database) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data_Database.ProtoReflect.Descriptor instead. -func (*Data_Database) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{2, 0} -} - -func (x *Data_Database) GetDriver() string { - if x != nil { - return x.Driver - } - return "" -} - -func (x *Data_Database) GetSource() string { - if x != nil { - return x.Source - } - return "" -} - -type Data_Redis struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - Password string `protobuf:"bytes,3,opt,name=password,proto3" json:"password,omitempty"` - Db int32 `protobuf:"varint,4,opt,name=db,proto3" json:"db,omitempty"` - DialTimeout *durationpb.Duration `protobuf:"bytes,5,opt,name=dial_timeout,json=dialTimeout,proto3" json:"dial_timeout,omitempty"` - ReadTimeout *durationpb.Duration `protobuf:"bytes,6,opt,name=read_timeout,json=readTimeout,proto3" json:"read_timeout,omitempty"` - WriteTimeout *durationpb.Duration `protobuf:"bytes,7,opt,name=write_timeout,json=writeTimeout,proto3" json:"write_timeout,omitempty"` -} - -func (x *Data_Redis) Reset() { - *x = Data_Redis{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data_Redis) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data_Redis) ProtoMessage() {} - -func (x *Data_Redis) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[7] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data_Redis.ProtoReflect.Descriptor instead. -func (*Data_Redis) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{2, 1} -} - -func (x *Data_Redis) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Data_Redis) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Data_Redis) GetPassword() string { - if x != nil { - return x.Password - } - return "" -} - -func (x *Data_Redis) GetDb() int32 { - if x != nil { - return x.Db - } - return 0 -} - -func (x *Data_Redis) GetDialTimeout() *durationpb.Duration { - if x != nil { - return x.DialTimeout - } - return nil -} - -func (x *Data_Redis) GetReadTimeout() *durationpb.Duration { - if x != nil { - return x.ReadTimeout - } - return nil -} - -func (x *Data_Redis) GetWriteTimeout() *durationpb.Duration { - if x != nil { - return x.WriteTimeout - } - return nil -} - -var File_conf_proto protoreflect.FileDescriptor - -var file_conf_proto_rawDesc = []byte{ - 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x6b, 0x72, - 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, - 0x6e, 0x66, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0xa4, 0x01, 0x0a, 0x09, 0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, - 0x12, 0x31, 0x0a, 0x05, 0x74, 0x72, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x1b, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x54, 0x72, 0x61, 0x63, 0x65, 0x52, 0x05, 0x74, 0x72, - 0x61, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, - 0x72, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x2e, 0x0a, 0x04, 0x64, 0x61, 0x74, - 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, - 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, - 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xcc, 0x02, 0x0a, 0x06, 0x53, 0x65, - 0x72, 0x76, 0x65, 0x72, 0x12, 0x35, 0x0a, 0x04, 0x68, 0x74, 0x74, 0x70, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, - 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x04, 0x68, 0x74, 0x74, 0x70, 0x12, 0x35, 0x0a, 0x04, 0x67, - 0x72, 0x70, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x6b, 0x72, 0x61, 0x74, - 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, - 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x47, 0x52, 0x50, 0x43, 0x52, 0x04, 0x67, 0x72, - 0x70, 0x63, 0x1a, 0x69, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, - 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, - 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x33, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, - 0x6f, 0x75, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x1a, 0x69, 0x0a, - 0x04, 0x47, 0x52, 0x50, 0x43, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, - 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, - 0x64, 0x64, 0x72, 0x12, 0x33, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, - 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x22, 0xdb, 0x03, 0x0a, 0x04, 0x44, 0x61, 0x74, - 0x61, 0x12, 0x3f, 0x0a, 0x08, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x2e, - 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, - 0x73, 0x65, 0x12, 0x36, 0x0a, 0x05, 0x72, 0x65, 0x64, 0x69, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x20, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, - 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x52, 0x65, - 0x64, 0x69, 0x73, 0x52, 0x05, 0x72, 0x65, 0x64, 0x69, 0x73, 0x1a, 0x3a, 0x0a, 0x08, 0x44, 0x61, - 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x12, 0x16, - 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, - 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0x9d, 0x02, 0x0a, 0x05, 0x52, 0x65, 0x64, 0x69, 0x73, - 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, - 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x1a, - 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x64, 0x62, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x64, 0x62, 0x12, 0x3c, 0x0a, 0x0c, 0x64, 0x69, - 0x61, 0x6c, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x64, 0x69, 0x61, - 0x6c, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3c, 0x0a, 0x0c, 0x72, 0x65, 0x61, 0x64, - 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x72, 0x65, 0x61, 0x64, 0x54, - 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3e, 0x0a, 0x0d, 0x77, 0x72, 0x69, 0x74, 0x65, 0x5f, - 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0c, 0x77, 0x72, 0x69, 0x74, 0x65, 0x54, - 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x22, 0x23, 0x0a, 0x05, 0x54, 0x72, 0x61, 0x63, 0x65, 0x12, - 0x1a, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x42, 0x3e, 0x5a, 0x3c, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, - 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x73, 0x2f, 0x62, 0x6c, 0x6f, 0x67, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, 0x63, 0x6f, 0x6e, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, -} - -var ( - file_conf_proto_rawDescOnce sync.Once - file_conf_proto_rawDescData = file_conf_proto_rawDesc -) - -func file_conf_proto_rawDescGZIP() []byte { - file_conf_proto_rawDescOnce.Do(func() { - file_conf_proto_rawDescData = protoimpl.X.CompressGZIP(file_conf_proto_rawDescData) - }) - return file_conf_proto_rawDescData -} - -var file_conf_proto_msgTypes = make([]protoimpl.MessageInfo, 8) -var file_conf_proto_goTypes = []interface{}{ - (*Bootstrap)(nil), // 0: kratos.internal.conf.Bootstrap - (*Server)(nil), // 1: kratos.internal.conf.Server - (*Data)(nil), // 2: kratos.internal.conf.Data - (*Trace)(nil), // 3: kratos.internal.conf.Trace - (*Server_HTTP)(nil), // 4: kratos.internal.conf.Server.HTTP - (*Server_GRPC)(nil), // 5: kratos.internal.conf.Server.GRPC - (*Data_Database)(nil), // 6: kratos.internal.conf.Data.Database - (*Data_Redis)(nil), // 7: kratos.internal.conf.Data.Redis - (*durationpb.Duration)(nil), // 8: google.protobuf.Duration -} -var file_conf_proto_depIdxs = []int32{ - 3, // 0: kratos.internal.conf.Bootstrap.trace:type_name -> kratos.internal.conf.Trace - 1, // 1: kratos.internal.conf.Bootstrap.server:type_name -> kratos.internal.conf.Server - 2, // 2: kratos.internal.conf.Bootstrap.data:type_name -> kratos.internal.conf.Data - 4, // 3: kratos.internal.conf.Server.http:type_name -> kratos.internal.conf.Server.HTTP - 5, // 4: kratos.internal.conf.Server.grpc:type_name -> kratos.internal.conf.Server.GRPC - 6, // 5: kratos.internal.conf.Data.database:type_name -> kratos.internal.conf.Data.Database - 7, // 6: kratos.internal.conf.Data.redis:type_name -> kratos.internal.conf.Data.Redis - 8, // 7: kratos.internal.conf.Server.HTTP.timeout:type_name -> google.protobuf.Duration - 8, // 8: kratos.internal.conf.Server.GRPC.timeout:type_name -> google.protobuf.Duration - 8, // 9: kratos.internal.conf.Data.Redis.dial_timeout:type_name -> google.protobuf.Duration - 8, // 10: kratos.internal.conf.Data.Redis.read_timeout:type_name -> google.protobuf.Duration - 8, // 11: kratos.internal.conf.Data.Redis.write_timeout:type_name -> google.protobuf.Duration - 12, // [12:12] is the sub-list for method output_type - 12, // [12:12] is the sub-list for method input_type - 12, // [12:12] is the sub-list for extension type_name - 12, // [12:12] is the sub-list for extension extendee - 0, // [0:12] is the sub-list for field type_name -} - -func init() { file_conf_proto_init() } -func file_conf_proto_init() { - if File_conf_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_conf_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Bootstrap); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Trace); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server_HTTP); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server_GRPC); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data_Database); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data_Redis); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_conf_proto_rawDesc, - NumEnums: 0, - NumMessages: 8, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_conf_proto_goTypes, - DependencyIndexes: file_conf_proto_depIdxs, - MessageInfos: file_conf_proto_msgTypes, - }.Build() - File_conf_proto = out.File - file_conf_proto_rawDesc = nil - file_conf_proto_goTypes = nil - file_conf_proto_depIdxs = nil -} diff --git a/examples/blog/internal/conf/conf.proto b/examples/blog/internal/conf/conf.proto deleted file mode 100644 index 491c21a13..000000000 --- a/examples/blog/internal/conf/conf.proto +++ /dev/null @@ -1,49 +0,0 @@ -syntax = "proto3"; -package kratos.internal.conf; - -option go_package = "github.com/go-kratos/kratos/examples/blog/internal/conf;conf"; - -import "google/protobuf/duration.proto"; - -message Bootstrap { - Trace trace = 1; - Server server = 2; - Data data = 3; -} - -message Server { - message HTTP { - string network = 1; - string addr = 2; - google.protobuf.Duration timeout = 3; - } - message GRPC { - string network = 1; - string addr = 2; - google.protobuf.Duration timeout = 3; - } - HTTP http = 1; - GRPC grpc = 2; -} - -message Data { - message Database { - string driver = 1; - string source = 2; - } - message Redis { - string network = 1; - string addr = 2; - string password = 3; - int32 db = 4; - google.protobuf.Duration dial_timeout = 5; - google.protobuf.Duration read_timeout = 6; - google.protobuf.Duration write_timeout = 7; - } - Database database = 1; - Redis redis = 2; -} - -message Trace { - string endpoint = 1; -} \ No newline at end of file diff --git a/examples/blog/internal/data/README.md b/examples/blog/internal/data/README.md deleted file mode 100644 index a9f7e8dad..000000000 --- a/examples/blog/internal/data/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Data - -``` -go generate ./ent -``` \ No newline at end of file diff --git a/examples/blog/internal/data/article.go b/examples/blog/internal/data/article.go deleted file mode 100644 index 14fc67526..000000000 --- a/examples/blog/internal/data/article.go +++ /dev/null @@ -1,80 +0,0 @@ -package data - -import ( - "context" - "time" - - "github.com/go-kratos/kratos/examples/blog/internal/biz" - "github.com/go-kratos/kratos/v2/log" -) - -type articleRepo struct { - data *Data - log *log.Helper -} - -// NewArticleRepo . -func NewArticleRepo(data *Data, logger log.Logger) biz.ArticleRepo { - return &articleRepo{ - data: data, - log: log.NewHelper(logger), - } -} - -func (ar *articleRepo) ListArticle(ctx context.Context) ([]*biz.Article, error) { - ps, err := ar.data.db.Article.Query().All(ctx) - if err != nil { - return nil, err - } - rv := make([]*biz.Article, 0, len(ps)) - for _, p := range ps { - rv = append(rv, &biz.Article{ - ID: p.ID, - Title: p.Title, - Content: p.Content, - CreatedAt: p.CreatedAt, - UpdatedAt: p.UpdatedAt, - }) - } - return rv, nil -} - -func (ar *articleRepo) GetArticle(ctx context.Context, id int64) (*biz.Article, error) { - p, err := ar.data.db.Article.Get(ctx, id) - if err != nil { - return nil, err - } - return &biz.Article{ - ID: p.ID, - Title: p.Title, - Content: p.Content, - CreatedAt: p.CreatedAt, - UpdatedAt: p.UpdatedAt, - }, nil -} - -func (ar *articleRepo) CreateArticle(ctx context.Context, article *biz.Article) error { - _, err := ar.data.db.Article. - Create(). - SetTitle(article.Title). - SetContent(article.Content). - Save(ctx) - return err -} - -func (ar *articleRepo) UpdateArticle(ctx context.Context, id int64, article *biz.Article) error { - p, err := ar.data.db.Article.Get(ctx, id) - if err != nil { - return err - } - _, err = p.Update(). - SetTitle(article.Title). - SetContent(article.Content). - SetUpdatedAt(time.Now()). - Save(ctx) - return err -} - -func (ar *articleRepo) DeleteArticle(ctx context.Context, id int64) error { - return ar.data.db.Article.DeleteOneID(id).Exec(ctx) -} diff --git a/examples/blog/internal/data/data.go b/examples/blog/internal/data/data.go deleted file mode 100644 index dc92829ed..000000000 --- a/examples/blog/internal/data/data.go +++ /dev/null @@ -1,86 +0,0 @@ -package data - -import ( - "context" - "fmt" - - "github.com/go-kratos/kratos/examples/blog/internal/conf" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-redis/redis/extra/redisotel" - "github.com/go-redis/redis/v8" - "github.com/google/wire" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" - - // init mysql driver - _ "github.com/go-sql-driver/mysql" -) - -// ProviderSet is data providers. -var ProviderSet = wire.NewSet(NewData, NewArticleRepo) - -// Data . -type Data struct { - db *ent.Client - rdb *redis.Client -} - -// NewData . -func NewData(conf *conf.Data, logger log.Logger) (*Data, func(), error) { - log := log.NewHelper(logger) - drv, err := sql.Open( - conf.Database.Driver, - conf.Database.Source, - ) - sqlDrv := dialect.DebugWithContext(drv, func(ctx context.Context, i ...interface{}) { - log.WithContext(ctx).Info(i...) - tracer := otel.Tracer("ent.") - kind := trace.SpanKindServer - _, span := tracer.Start(ctx, - "Query", - trace.WithAttributes( - attribute.String("sql", fmt.Sprint(i...)), - ), - trace.WithSpanKind(kind), - ) - span.End() - }) - client := ent.NewClient(ent.Driver(sqlDrv)) - if err != nil { - log.Errorf("failed opening connection to sqlite: %v", err) - return nil, nil, err - } - // Run the auto migration tool. - if err := client.Schema.Create(context.Background()); err != nil { - log.Errorf("failed creating schema resources: %v", err) - return nil, nil, err - } - - rdb := redis.NewClient(&redis.Options{ - Addr: conf.Redis.Addr, - Password: conf.Redis.Password, - DB: int(conf.Redis.Db), - DialTimeout: conf.Redis.DialTimeout.AsDuration(), - WriteTimeout: conf.Redis.WriteTimeout.AsDuration(), - ReadTimeout: conf.Redis.ReadTimeout.AsDuration(), - }) - rdb.AddHook(redisotel.TracingHook{}) - d := &Data{ - db: client, - rdb: rdb, - } - return d, func() { - log.Info("message", "closing the data resources") - if err := d.db.Close(); err != nil { - log.Error(err) - } - if err := d.rdb.Close(); err != nil { - log.Error(err) - } - }, nil -} diff --git a/examples/blog/internal/data/ent/article.go b/examples/blog/internal/data/ent/article.go deleted file mode 100644 index ccc45582a..000000000 --- a/examples/blog/internal/data/ent/article.go +++ /dev/null @@ -1,174 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent/dialect/sql" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" -) - -// Article is the model entity for the Article schema. -type Article struct { - config `json:"-"` - // ID of the ent. - ID int64 `json:"id,omitempty"` - // Title holds the value of the "title" field. - Title string `json:"title,omitempty"` - // Content holds the value of the "content" field. - Content string `json:"content,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // UpdatedAt holds the value of the "updated_at" field. - UpdatedAt time.Time `json:"updated_at,omitempty"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the ArticleQuery when eager-loading is set. - Edges ArticleEdges `json:"edges"` -} - -// ArticleEdges holds the relations/edges for other nodes in the graph. -type ArticleEdges struct { - // Comments holds the value of the comments edge. - Comments []*Comment `json:"comments,omitempty"` - // Tags holds the value of the tags edge. - Tags []*Tag `json:"tags,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [2]bool -} - -// CommentsOrErr returns the Comments value or an error if the edge -// was not loaded in eager-loading. -func (e ArticleEdges) CommentsOrErr() ([]*Comment, error) { - if e.loadedTypes[0] { - return e.Comments, nil - } - return nil, &NotLoadedError{edge: "comments"} -} - -// TagsOrErr returns the Tags value or an error if the edge -// was not loaded in eager-loading. -func (e ArticleEdges) TagsOrErr() ([]*Tag, error) { - if e.loadedTypes[1] { - return e.Tags, nil - } - return nil, &NotLoadedError{edge: "tags"} -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*Article) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) - for i := range columns { - switch columns[i] { - case article.FieldID: - values[i] = &sql.NullInt64{} - case article.FieldTitle, article.FieldContent: - values[i] = &sql.NullString{} - case article.FieldCreatedAt, article.FieldUpdatedAt: - values[i] = &sql.NullTime{} - default: - return nil, fmt.Errorf("unexpected column %q for type Article", columns[i]) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Article fields. -func (a *Article) assignValues(columns []string, values []interface{}) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case article.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - a.ID = int64(value.Int64) - case article.FieldTitle: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field title", values[i]) - } else if value.Valid { - a.Title = value.String - } - case article.FieldContent: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field content", values[i]) - } else if value.Valid { - a.Content = value.String - } - case article.FieldCreatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[i]) - } else if value.Valid { - a.CreatedAt = value.Time - } - case article.FieldUpdatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[i]) - } else if value.Valid { - a.UpdatedAt = value.Time - } - } - } - return nil -} - -// QueryComments queries the "comments" edge of the Article entity. -func (a *Article) QueryComments() *CommentQuery { - return (&ArticleClient{config: a.config}).QueryComments(a) -} - -// QueryTags queries the "tags" edge of the Article entity. -func (a *Article) QueryTags() *TagQuery { - return (&ArticleClient{config: a.config}).QueryTags(a) -} - -// Update returns a builder for updating this Article. -// Note that you need to call Article.Unwrap() before calling this method if this Article -// was returned from a transaction, and the transaction was committed or rolled back. -func (a *Article) Update() *ArticleUpdateOne { - return (&ArticleClient{config: a.config}).UpdateOne(a) -} - -// Unwrap unwraps the Article entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (a *Article) Unwrap() *Article { - tx, ok := a.config.driver.(*txDriver) - if !ok { - panic("ent: Article is not a transactional entity") - } - a.config.driver = tx.drv - return a -} - -// String implements the fmt.Stringer. -func (a *Article) String() string { - var builder strings.Builder - builder.WriteString("Article(") - builder.WriteString(fmt.Sprintf("id=%v", a.ID)) - builder.WriteString(", title=") - builder.WriteString(a.Title) - builder.WriteString(", content=") - builder.WriteString(a.Content) - builder.WriteString(", created_at=") - builder.WriteString(a.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", updated_at=") - builder.WriteString(a.UpdatedAt.Format(time.ANSIC)) - builder.WriteByte(')') - return builder.String() -} - -// Articles is a parsable slice of Article. -type Articles []*Article - -func (a Articles) config(cfg config) { - for _i := range a { - a[_i].config = cfg - } -} diff --git a/examples/blog/internal/data/ent/article/article.go b/examples/blog/internal/data/ent/article/article.go deleted file mode 100644 index 76dcf5487..000000000 --- a/examples/blog/internal/data/ent/article/article.go +++ /dev/null @@ -1,74 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package article - -import ( - "time" -) - -const ( - // Label holds the string label denoting the article type in the database. - Label = "article" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldTitle holds the string denoting the title field in the database. - FieldTitle = "title" - // FieldContent holds the string denoting the content field in the database. - FieldContent = "content" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldUpdatedAt holds the string denoting the updated_at field in the database. - FieldUpdatedAt = "updated_at" - - // EdgeComments holds the string denoting the comments edge name in mutations. - EdgeComments = "comments" - // EdgeTags holds the string denoting the tags edge name in mutations. - EdgeTags = "tags" - - // Table holds the table name of the article in the database. - Table = "articles" - // CommentsTable is the table the holds the comments relation/edge. - CommentsTable = "comments" - // CommentsInverseTable is the table name for the Comment entity. - // It exists in this package in order to avoid circular dependency with the "comment" package. - CommentsInverseTable = "comments" - // CommentsColumn is the table column denoting the comments relation/edge. - CommentsColumn = "article_comments" - // TagsTable is the table the holds the tags relation/edge. The primary key declared below. - TagsTable = "tag_posts" - // TagsInverseTable is the table name for the Tag entity. - // It exists in this package in order to avoid circular dependency with the "tag" package. - TagsInverseTable = "tags" -) - -// Columns holds all SQL columns for article fields. -var Columns = []string{ - FieldID, - FieldTitle, - FieldContent, - FieldCreatedAt, - FieldUpdatedAt, -} - -var ( - // TagsPrimaryKey and TagsColumn2 are the table columns denoting the - // primary key for the tags relation (M2M). - TagsPrimaryKey = []string{"tag_id", "article_id"} -) - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. - DefaultUpdatedAt func() time.Time -) diff --git a/examples/blog/internal/data/ent/article/where.go b/examples/blog/internal/data/ent/article/where.go deleted file mode 100644 index 4309258c8..000000000 --- a/examples/blog/internal/data/ent/article/where.go +++ /dev/null @@ -1,584 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package article - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int64) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int64) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int64) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int64) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int64) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int64) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int64) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int64) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int64) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) -} - -// Title applies equality check predicate on the "title" field. It's identical to TitleEQ. -func Title(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldTitle), v)) - }) -} - -// Content applies equality check predicate on the "content" field. It's identical to ContentEQ. -func Content(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldContent), v)) - }) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) -} - -// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. -func UpdatedAt(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) -} - -// TitleEQ applies the EQ predicate on the "title" field. -func TitleEQ(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldTitle), v)) - }) -} - -// TitleNEQ applies the NEQ predicate on the "title" field. -func TitleNEQ(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldTitle), v)) - }) -} - -// TitleIn applies the In predicate on the "title" field. -func TitleIn(vs ...string) predicate.Article { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Article(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldTitle), v...)) - }) -} - -// TitleNotIn applies the NotIn predicate on the "title" field. -func TitleNotIn(vs ...string) predicate.Article { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Article(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldTitle), v...)) - }) -} - -// TitleGT applies the GT predicate on the "title" field. -func TitleGT(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldTitle), v)) - }) -} - -// TitleGTE applies the GTE predicate on the "title" field. -func TitleGTE(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldTitle), v)) - }) -} - -// TitleLT applies the LT predicate on the "title" field. -func TitleLT(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldTitle), v)) - }) -} - -// TitleLTE applies the LTE predicate on the "title" field. -func TitleLTE(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldTitle), v)) - }) -} - -// TitleContains applies the Contains predicate on the "title" field. -func TitleContains(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldTitle), v)) - }) -} - -// TitleHasPrefix applies the HasPrefix predicate on the "title" field. -func TitleHasPrefix(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldTitle), v)) - }) -} - -// TitleHasSuffix applies the HasSuffix predicate on the "title" field. -func TitleHasSuffix(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldTitle), v)) - }) -} - -// TitleEqualFold applies the EqualFold predicate on the "title" field. -func TitleEqualFold(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldTitle), v)) - }) -} - -// TitleContainsFold applies the ContainsFold predicate on the "title" field. -func TitleContainsFold(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldTitle), v)) - }) -} - -// ContentEQ applies the EQ predicate on the "content" field. -func ContentEQ(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldContent), v)) - }) -} - -// ContentNEQ applies the NEQ predicate on the "content" field. -func ContentNEQ(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldContent), v)) - }) -} - -// ContentIn applies the In predicate on the "content" field. -func ContentIn(vs ...string) predicate.Article { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Article(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldContent), v...)) - }) -} - -// ContentNotIn applies the NotIn predicate on the "content" field. -func ContentNotIn(vs ...string) predicate.Article { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Article(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldContent), v...)) - }) -} - -// ContentGT applies the GT predicate on the "content" field. -func ContentGT(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldContent), v)) - }) -} - -// ContentGTE applies the GTE predicate on the "content" field. -func ContentGTE(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldContent), v)) - }) -} - -// ContentLT applies the LT predicate on the "content" field. -func ContentLT(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldContent), v)) - }) -} - -// ContentLTE applies the LTE predicate on the "content" field. -func ContentLTE(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldContent), v)) - }) -} - -// ContentContains applies the Contains predicate on the "content" field. -func ContentContains(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldContent), v)) - }) -} - -// ContentHasPrefix applies the HasPrefix predicate on the "content" field. -func ContentHasPrefix(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldContent), v)) - }) -} - -// ContentHasSuffix applies the HasSuffix predicate on the "content" field. -func ContentHasSuffix(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldContent), v)) - }) -} - -// ContentEqualFold applies the EqualFold predicate on the "content" field. -func ContentEqualFold(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldContent), v)) - }) -} - -// ContentContainsFold applies the ContainsFold predicate on the "content" field. -func ContentContainsFold(v string) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldContent), v)) - }) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.Article { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Article(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.Article { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Article(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) -} - -// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. -func UpdatedAtEQ(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. -func UpdatedAtNEQ(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtIn applies the In predicate on the "updated_at" field. -func UpdatedAtIn(vs ...time.Time) predicate.Article { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Article(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) -} - -// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. -func UpdatedAtNotIn(vs ...time.Time) predicate.Article { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Article(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) -} - -// UpdatedAtGT applies the GT predicate on the "updated_at" field. -func UpdatedAtGT(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. -func UpdatedAtGTE(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtLT applies the LT predicate on the "updated_at" field. -func UpdatedAtLT(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. -func UpdatedAtLTE(v time.Time) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) -} - -// HasComments applies the HasEdge predicate on the "comments" edge. -func HasComments() predicate.Article { - return predicate.Article(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(CommentsTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, CommentsTable, CommentsColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasCommentsWith applies the HasEdge predicate on the "comments" edge with a given conditions (other predicates). -func HasCommentsWith(preds ...predicate.Comment) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(CommentsInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, CommentsTable, CommentsColumn), - ) - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// HasTags applies the HasEdge predicate on the "tags" edge. -func HasTags() predicate.Article { - return predicate.Article(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TagsTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, TagsTable, TagsPrimaryKey...), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasTagsWith applies the HasEdge predicate on the "tags" edge with a given conditions (other predicates). -func HasTagsWith(preds ...predicate.Tag) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TagsInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, TagsTable, TagsPrimaryKey...), - ) - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.Article) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.Article) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.Article) predicate.Article { - return predicate.Article(func(s *sql.Selector) { - p(s.Not()) - }) -} diff --git a/examples/blog/internal/data/ent/article_create.go b/examples/blog/internal/data/ent/article_create.go deleted file mode 100644 index f319f0554..000000000 --- a/examples/blog/internal/data/ent/article_create.go +++ /dev/null @@ -1,350 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" -) - -// ArticleCreate is the builder for creating a Article entity. -type ArticleCreate struct { - config - mutation *ArticleMutation - hooks []Hook -} - -// SetTitle sets the "title" field. -func (ac *ArticleCreate) SetTitle(s string) *ArticleCreate { - ac.mutation.SetTitle(s) - return ac -} - -// SetContent sets the "content" field. -func (ac *ArticleCreate) SetContent(s string) *ArticleCreate { - ac.mutation.SetContent(s) - return ac -} - -// SetCreatedAt sets the "created_at" field. -func (ac *ArticleCreate) SetCreatedAt(t time.Time) *ArticleCreate { - ac.mutation.SetCreatedAt(t) - return ac -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (ac *ArticleCreate) SetNillableCreatedAt(t *time.Time) *ArticleCreate { - if t != nil { - ac.SetCreatedAt(*t) - } - return ac -} - -// SetUpdatedAt sets the "updated_at" field. -func (ac *ArticleCreate) SetUpdatedAt(t time.Time) *ArticleCreate { - ac.mutation.SetUpdatedAt(t) - return ac -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (ac *ArticleCreate) SetNillableUpdatedAt(t *time.Time) *ArticleCreate { - if t != nil { - ac.SetUpdatedAt(*t) - } - return ac -} - -// SetID sets the "id" field. -func (ac *ArticleCreate) SetID(i int64) *ArticleCreate { - ac.mutation.SetID(i) - return ac -} - -// AddCommentIDs adds the "comments" edge to the Comment entity by IDs. -func (ac *ArticleCreate) AddCommentIDs(ids ...int64) *ArticleCreate { - ac.mutation.AddCommentIDs(ids...) - return ac -} - -// AddComments adds the "comments" edges to the Comment entity. -func (ac *ArticleCreate) AddComments(c ...*Comment) *ArticleCreate { - ids := make([]int64, len(c)) - for i := range c { - ids[i] = c[i].ID - } - return ac.AddCommentIDs(ids...) -} - -// AddTagIDs adds the "tags" edge to the Tag entity by IDs. -func (ac *ArticleCreate) AddTagIDs(ids ...int64) *ArticleCreate { - ac.mutation.AddTagIDs(ids...) - return ac -} - -// AddTags adds the "tags" edges to the Tag entity. -func (ac *ArticleCreate) AddTags(t ...*Tag) *ArticleCreate { - ids := make([]int64, len(t)) - for i := range t { - ids[i] = t[i].ID - } - return ac.AddTagIDs(ids...) -} - -// Mutation returns the ArticleMutation object of the builder. -func (ac *ArticleCreate) Mutation() *ArticleMutation { - return ac.mutation -} - -// Save creates the Article in the database. -func (ac *ArticleCreate) Save(ctx context.Context) (*Article, error) { - var ( - err error - node *Article - ) - ac.defaults() - if len(ac.hooks) == 0 { - if err = ac.check(); err != nil { - return nil, err - } - node, err = ac.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ArticleMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = ac.check(); err != nil { - return nil, err - } - ac.mutation = mutation - node, err = ac.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(ac.hooks) - 1; i >= 0; i-- { - mut = ac.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ac.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX calls Save and panics if Save returns an error. -func (ac *ArticleCreate) SaveX(ctx context.Context) *Article { - v, err := ac.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// defaults sets the default values of the builder before save. -func (ac *ArticleCreate) defaults() { - if _, ok := ac.mutation.CreatedAt(); !ok { - v := article.DefaultCreatedAt() - ac.mutation.SetCreatedAt(v) - } - if _, ok := ac.mutation.UpdatedAt(); !ok { - v := article.DefaultUpdatedAt() - ac.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (ac *ArticleCreate) check() error { - if _, ok := ac.mutation.Title(); !ok { - return &ValidationError{Name: "title", err: errors.New("ent: missing required field \"title\"")} - } - if _, ok := ac.mutation.Content(); !ok { - return &ValidationError{Name: "content", err: errors.New("ent: missing required field \"content\"")} - } - if _, ok := ac.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New("ent: missing required field \"created_at\"")} - } - if _, ok := ac.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New("ent: missing required field \"updated_at\"")} - } - return nil -} - -func (ac *ArticleCreate) sqlSave(ctx context.Context) (*Article, error) { - _node, _spec := ac.createSpec() - if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil { - if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - return nil, err - } - if _node.ID == 0 { - id := _spec.ID.Value.(int64) - _node.ID = int64(id) - } - return _node, nil -} - -func (ac *ArticleCreate) createSpec() (*Article, *sqlgraph.CreateSpec) { - var ( - _node = &Article{config: ac.config} - _spec = &sqlgraph.CreateSpec{ - Table: article.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - } - ) - if id, ok := ac.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = id - } - if value, ok := ac.mutation.Title(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: article.FieldTitle, - }) - _node.Title = value - } - if value, ok := ac.mutation.Content(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: article.FieldContent, - }) - _node.Content = value - } - if value, ok := ac.mutation.CreatedAt(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: article.FieldCreatedAt, - }) - _node.CreatedAt = value - } - if value, ok := ac.mutation.UpdatedAt(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: article.FieldUpdatedAt, - }) - _node.UpdatedAt = value - } - if nodes := ac.mutation.CommentsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: article.CommentsTable, - Columns: []string{article.CommentsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - if nodes := ac.mutation.TagsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: article.TagsTable, - Columns: article.TagsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - return _node, _spec -} - -// ArticleCreateBulk is the builder for creating many Article entities in bulk. -type ArticleCreateBulk struct { - config - builders []*ArticleCreate -} - -// Save creates the Article entities in the database. -func (acb *ArticleCreateBulk) Save(ctx context.Context) ([]*Article, error) { - specs := make([]*sqlgraph.CreateSpec, len(acb.builders)) - nodes := make([]*Article, len(acb.builders)) - mutators := make([]Mutator, len(acb.builders)) - for i := range acb.builders { - func(i int, root context.Context) { - builder := acb.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ArticleMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() - var err error - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, acb.builders[i+1].mutation) - } else { - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, acb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil { - if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - } - } - mutation.done = true - if err != nil { - return nil, err - } - if nodes[i].ID == 0 { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int64(id) - } - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, acb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (acb *ArticleCreateBulk) SaveX(ctx context.Context) []*Article { - v, err := acb.Save(ctx) - if err != nil { - panic(err) - } - return v -} diff --git a/examples/blog/internal/data/ent/article_delete.go b/examples/blog/internal/data/ent/article_delete.go deleted file mode 100644 index c1520f96a..000000000 --- a/examples/blog/internal/data/ent/article_delete.go +++ /dev/null @@ -1,108 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" -) - -// ArticleDelete is the builder for deleting a Article entity. -type ArticleDelete struct { - config - hooks []Hook - mutation *ArticleMutation -} - -// Where adds a new predicate to the ArticleDelete builder. -func (ad *ArticleDelete) Where(ps ...predicate.Article) *ArticleDelete { - ad.mutation.predicates = append(ad.mutation.predicates, ps...) - return ad -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (ad *ArticleDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ad.hooks) == 0 { - affected, err = ad.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ArticleMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ad.mutation = mutation - affected, err = ad.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(ad.hooks) - 1; i >= 0; i-- { - mut = ad.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ad.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// ExecX is like Exec, but panics if an error occurs. -func (ad *ArticleDelete) ExecX(ctx context.Context) int { - n, err := ad.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (ad *ArticleDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: article.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - if ps := ad.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return sqlgraph.DeleteNodes(ctx, ad.driver, _spec) -} - -// ArticleDeleteOne is the builder for deleting a single Article entity. -type ArticleDeleteOne struct { - ad *ArticleDelete -} - -// Exec executes the deletion query. -func (ado *ArticleDeleteOne) Exec(ctx context.Context) error { - n, err := ado.ad.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{article.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (ado *ArticleDeleteOne) ExecX(ctx context.Context) { - ado.ad.ExecX(ctx) -} diff --git a/examples/blog/internal/data/ent/article_query.go b/examples/blog/internal/data/ent/article_query.go deleted file mode 100644 index 91b345e1c..000000000 --- a/examples/blog/internal/data/ent/article_query.go +++ /dev/null @@ -1,1068 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "database/sql/driver" - "errors" - "fmt" - "math" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" -) - -// ArticleQuery is the builder for querying Article entities. -type ArticleQuery struct { - config - limit *int - offset *int - order []OrderFunc - fields []string - predicates []predicate.Article - // eager-loading edges. - withComments *CommentQuery - withTags *TagQuery - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the ArticleQuery builder. -func (aq *ArticleQuery) Where(ps ...predicate.Article) *ArticleQuery { - aq.predicates = append(aq.predicates, ps...) - return aq -} - -// Limit adds a limit step to the query. -func (aq *ArticleQuery) Limit(limit int) *ArticleQuery { - aq.limit = &limit - return aq -} - -// Offset adds an offset step to the query. -func (aq *ArticleQuery) Offset(offset int) *ArticleQuery { - aq.offset = &offset - return aq -} - -// Order adds an order step to the query. -func (aq *ArticleQuery) Order(o ...OrderFunc) *ArticleQuery { - aq.order = append(aq.order, o...) - return aq -} - -// QueryComments chains the current query on the "comments" edge. -func (aq *ArticleQuery) QueryComments() *CommentQuery { - query := &CommentQuery{config: aq.config} - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := aq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := aq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(article.Table, article.FieldID, selector), - sqlgraph.To(comment.Table, comment.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, article.CommentsTable, article.CommentsColumn), - ) - fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryTags chains the current query on the "tags" edge. -func (aq *ArticleQuery) QueryTags() *TagQuery { - query := &TagQuery{config: aq.config} - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := aq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := aq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(article.Table, article.FieldID, selector), - sqlgraph.To(tag.Table, tag.FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, article.TagsTable, article.TagsPrimaryKey...), - ) - fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first Article entity from the query. -// Returns a *NotFoundError when no Article was found. -func (aq *ArticleQuery) First(ctx context.Context) (*Article, error) { - nodes, err := aq.Limit(1).All(ctx) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{article.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (aq *ArticleQuery) FirstX(ctx context.Context) *Article { - node, err := aq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first Article ID from the query. -// Returns a *NotFoundError when no Article ID was found. -func (aq *ArticleQuery) FirstID(ctx context.Context) (id int64, err error) { - var ids []int64 - if ids, err = aq.Limit(1).IDs(ctx); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{article.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (aq *ArticleQuery) FirstIDX(ctx context.Context) int64 { - id, err := aq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single Article entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one Article entity is not found. -// Returns a *NotFoundError when no Article entities are found. -func (aq *ArticleQuery) Only(ctx context.Context) (*Article, error) { - nodes, err := aq.Limit(2).All(ctx) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{article.Label} - default: - return nil, &NotSingularError{article.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (aq *ArticleQuery) OnlyX(ctx context.Context) *Article { - node, err := aq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only Article ID in the query. -// Returns a *NotSingularError when exactly one Article ID is not found. -// Returns a *NotFoundError when no entities are found. -func (aq *ArticleQuery) OnlyID(ctx context.Context) (id int64, err error) { - var ids []int64 - if ids, err = aq.Limit(2).IDs(ctx); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{article.Label} - default: - err = &NotSingularError{article.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (aq *ArticleQuery) OnlyIDX(ctx context.Context) int64 { - id, err := aq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of Articles. -func (aq *ArticleQuery) All(ctx context.Context) ([]*Article, error) { - if err := aq.prepareQuery(ctx); err != nil { - return nil, err - } - return aq.sqlAll(ctx) -} - -// AllX is like All, but panics if an error occurs. -func (aq *ArticleQuery) AllX(ctx context.Context) []*Article { - nodes, err := aq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of Article IDs. -func (aq *ArticleQuery) IDs(ctx context.Context) ([]int64, error) { - var ids []int64 - if err := aq.Select(article.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (aq *ArticleQuery) IDsX(ctx context.Context) []int64 { - ids, err := aq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (aq *ArticleQuery) Count(ctx context.Context) (int, error) { - if err := aq.prepareQuery(ctx); err != nil { - return 0, err - } - return aq.sqlCount(ctx) -} - -// CountX is like Count, but panics if an error occurs. -func (aq *ArticleQuery) CountX(ctx context.Context) int { - count, err := aq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (aq *ArticleQuery) Exist(ctx context.Context) (bool, error) { - if err := aq.prepareQuery(ctx); err != nil { - return false, err - } - return aq.sqlExist(ctx) -} - -// ExistX is like Exist, but panics if an error occurs. -func (aq *ArticleQuery) ExistX(ctx context.Context) bool { - exist, err := aq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the ArticleQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (aq *ArticleQuery) Clone() *ArticleQuery { - if aq == nil { - return nil - } - return &ArticleQuery{ - config: aq.config, - limit: aq.limit, - offset: aq.offset, - order: append([]OrderFunc{}, aq.order...), - predicates: append([]predicate.Article{}, aq.predicates...), - withComments: aq.withComments.Clone(), - withTags: aq.withTags.Clone(), - // clone intermediate query. - sql: aq.sql.Clone(), - path: aq.path, - } -} - -// WithComments tells the query-builder to eager-load the nodes that are connected to -// the "comments" edge. The optional arguments are used to configure the query builder of the edge. -func (aq *ArticleQuery) WithComments(opts ...func(*CommentQuery)) *ArticleQuery { - query := &CommentQuery{config: aq.config} - for _, opt := range opts { - opt(query) - } - aq.withComments = query - return aq -} - -// WithTags tells the query-builder to eager-load the nodes that are connected to -// the "tags" edge. The optional arguments are used to configure the query builder of the edge. -func (aq *ArticleQuery) WithTags(opts ...func(*TagQuery)) *ArticleQuery { - query := &TagQuery{config: aq.config} - for _, opt := range opts { - opt(query) - } - aq.withTags = query - return aq -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// Title string `json:"title,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.Article.Query(). -// GroupBy(article.FieldTitle). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -// -func (aq *ArticleQuery) GroupBy(field string, fields ...string) *ArticleGroupBy { - group := &ArticleGroupBy{config: aq.config} - group.fields = append([]string{field}, fields...) - group.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := aq.prepareQuery(ctx); err != nil { - return nil, err - } - return aq.sqlQuery(ctx), nil - } - return group -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// Title string `json:"title,omitempty"` -// } -// -// client.Article.Query(). -// Select(article.FieldTitle). -// Scan(ctx, &v) -// -func (aq *ArticleQuery) Select(field string, fields ...string) *ArticleSelect { - aq.fields = append([]string{field}, fields...) - return &ArticleSelect{ArticleQuery: aq} -} - -func (aq *ArticleQuery) prepareQuery(ctx context.Context) error { - for _, f := range aq.fields { - if !article.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if aq.path != nil { - prev, err := aq.path(ctx) - if err != nil { - return err - } - aq.sql = prev - } - return nil -} - -func (aq *ArticleQuery) sqlAll(ctx context.Context) ([]*Article, error) { - var ( - nodes = []*Article{} - _spec = aq.querySpec() - loadedTypes = [2]bool{ - aq.withComments != nil, - aq.withTags != nil, - } - ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { - node := &Article{config: aq.config} - nodes = append(nodes, node) - return node.scanValues(columns) - } - _spec.Assign = func(columns []string, values []interface{}) error { - if len(nodes) == 0 { - return fmt.Errorf("ent: Assign called without calling ScanValues") - } - node := nodes[len(nodes)-1] - node.Edges.loadedTypes = loadedTypes - return node.assignValues(columns, values) - } - if err := sqlgraph.QueryNodes(ctx, aq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - - if query := aq.withComments; query != nil { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int64]*Article) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - nodes[i].Edges.Comments = []*Comment{} - } - query.withFKs = true - query.Where(predicate.Comment(func(s *sql.Selector) { - s.Where(sql.InValues(article.CommentsColumn, fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return nil, err - } - for _, n := range neighbors { - fk := n.article_comments - if fk == nil { - return nil, fmt.Errorf(`foreign-key "article_comments" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "article_comments" returned %v for node %v`, *fk, n.ID) - } - node.Edges.Comments = append(node.Edges.Comments, n) - } - } - - if query := aq.withTags; query != nil { - fks := make([]driver.Value, 0, len(nodes)) - ids := make(map[int64]*Article, len(nodes)) - for _, node := range nodes { - ids[node.ID] = node - fks = append(fks, node.ID) - node.Edges.Tags = []*Tag{} - } - var ( - edgeids []int64 - edges = make(map[int64][]*Article) - ) - _spec := &sqlgraph.EdgeQuerySpec{ - Edge: &sqlgraph.EdgeSpec{ - Inverse: true, - Table: article.TagsTable, - Columns: article.TagsPrimaryKey, - }, - Predicate: func(s *sql.Selector) { - s.Where(sql.InValues(article.TagsPrimaryKey[1], fks...)) - }, - - ScanValues: func() [2]interface{} { - return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}} - }, - Assign: func(out, in interface{}) error { - eout, ok := out.(*sql.NullInt64) - if !ok || eout == nil { - return fmt.Errorf("unexpected id value for edge-out") - } - ein, ok := in.(*sql.NullInt64) - if !ok || ein == nil { - return fmt.Errorf("unexpected id value for edge-in") - } - outValue := eout.Int64 - inValue := ein.Int64 - node, ok := ids[outValue] - if !ok { - return fmt.Errorf("unexpected node id in edges: %v", outValue) - } - edgeids = append(edgeids, inValue) - edges[inValue] = append(edges[inValue], node) - return nil - }, - } - if err := sqlgraph.QueryEdges(ctx, aq.driver, _spec); err != nil { - return nil, fmt.Errorf(`query edges "tags": %v`, err) - } - query.Where(tag.IDIn(edgeids...)) - neighbors, err := query.All(ctx) - if err != nil { - return nil, err - } - for _, n := range neighbors { - nodes, ok := edges[n.ID] - if !ok { - return nil, fmt.Errorf(`unexpected "tags" node returned %v`, n.ID) - } - for i := range nodes { - nodes[i].Edges.Tags = append(nodes[i].Edges.Tags, n) - } - } - } - - return nodes, nil -} - -func (aq *ArticleQuery) sqlCount(ctx context.Context) (int, error) { - _spec := aq.querySpec() - return sqlgraph.CountNodes(ctx, aq.driver, _spec) -} - -func (aq *ArticleQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := aq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("ent: check existence: %v", err) - } - return n > 0, nil -} - -func (aq *ArticleQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: article.Table, - Columns: article.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - From: aq.sql, - Unique: true, - } - if fields := aq.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, article.FieldID) - for i := range fields { - if fields[i] != article.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := aq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := aq.limit; limit != nil { - _spec.Limit = *limit - } - if offset := aq.offset; offset != nil { - _spec.Offset = *offset - } - if ps := aq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector, article.ValidColumn) - } - } - } - return _spec -} - -func (aq *ArticleQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(aq.driver.Dialect()) - t1 := builder.Table(article.Table) - selector := builder.Select(t1.Columns(article.Columns...)...).From(t1) - if aq.sql != nil { - selector = aq.sql - selector.Select(selector.Columns(article.Columns...)...) - } - for _, p := range aq.predicates { - p(selector) - } - for _, p := range aq.order { - p(selector, article.ValidColumn) - } - if offset := aq.offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := aq.limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// ArticleGroupBy is the group-by builder for Article entities. -type ArticleGroupBy struct { - config - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (agb *ArticleGroupBy) Aggregate(fns ...AggregateFunc) *ArticleGroupBy { - agb.fns = append(agb.fns, fns...) - return agb -} - -// Scan applies the group-by query and scans the result into the given value. -func (agb *ArticleGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := agb.path(ctx) - if err != nil { - return err - } - agb.sql = query - return agb.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (agb *ArticleGroupBy) ScanX(ctx context.Context, v interface{}) { - if err := agb.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from group-by. -// It is only allowed when executing a group-by query with one field. -func (agb *ArticleGroupBy) Strings(ctx context.Context) ([]string, error) { - if len(agb.fields) > 1 { - return nil, errors.New("ent: ArticleGroupBy.Strings is not achievable when grouping more than 1 field") - } - var v []string - if err := agb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (agb *ArticleGroupBy) StringsX(ctx context.Context) []string { - v, err := agb.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (agb *ArticleGroupBy) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = agb.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{article.Label} - default: - err = fmt.Errorf("ent: ArticleGroupBy.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (agb *ArticleGroupBy) StringX(ctx context.Context) string { - v, err := agb.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from group-by. -// It is only allowed when executing a group-by query with one field. -func (agb *ArticleGroupBy) Ints(ctx context.Context) ([]int, error) { - if len(agb.fields) > 1 { - return nil, errors.New("ent: ArticleGroupBy.Ints is not achievable when grouping more than 1 field") - } - var v []int - if err := agb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (agb *ArticleGroupBy) IntsX(ctx context.Context) []int { - v, err := agb.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (agb *ArticleGroupBy) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = agb.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{article.Label} - default: - err = fmt.Errorf("ent: ArticleGroupBy.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (agb *ArticleGroupBy) IntX(ctx context.Context) int { - v, err := agb.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from group-by. -// It is only allowed when executing a group-by query with one field. -func (agb *ArticleGroupBy) Float64s(ctx context.Context) ([]float64, error) { - if len(agb.fields) > 1 { - return nil, errors.New("ent: ArticleGroupBy.Float64s is not achievable when grouping more than 1 field") - } - var v []float64 - if err := agb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (agb *ArticleGroupBy) Float64sX(ctx context.Context) []float64 { - v, err := agb.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (agb *ArticleGroupBy) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = agb.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{article.Label} - default: - err = fmt.Errorf("ent: ArticleGroupBy.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (agb *ArticleGroupBy) Float64X(ctx context.Context) float64 { - v, err := agb.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from group-by. -// It is only allowed when executing a group-by query with one field. -func (agb *ArticleGroupBy) Bools(ctx context.Context) ([]bool, error) { - if len(agb.fields) > 1 { - return nil, errors.New("ent: ArticleGroupBy.Bools is not achievable when grouping more than 1 field") - } - var v []bool - if err := agb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (agb *ArticleGroupBy) BoolsX(ctx context.Context) []bool { - v, err := agb.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (agb *ArticleGroupBy) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = agb.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{article.Label} - default: - err = fmt.Errorf("ent: ArticleGroupBy.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (agb *ArticleGroupBy) BoolX(ctx context.Context) bool { - v, err := agb.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (agb *ArticleGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range agb.fields { - if !article.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := agb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := agb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (agb *ArticleGroupBy) sqlQuery() *sql.Selector { - selector := agb.sql - columns := make([]string, 0, len(agb.fields)+len(agb.fns)) - columns = append(columns, agb.fields...) - for _, fn := range agb.fns { - columns = append(columns, fn(selector, article.ValidColumn)) - } - return selector.Select(columns...).GroupBy(agb.fields...) -} - -// ArticleSelect is the builder for selecting fields of Article entities. -type ArticleSelect struct { - *ArticleQuery - // intermediate query (i.e. traversal path). - sql *sql.Selector -} - -// Scan applies the selector query and scans the result into the given value. -func (as *ArticleSelect) Scan(ctx context.Context, v interface{}) error { - if err := as.prepareQuery(ctx); err != nil { - return err - } - as.sql = as.ArticleQuery.sqlQuery(ctx) - return as.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (as *ArticleSelect) ScanX(ctx context.Context, v interface{}) { - if err := as.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from a selector. It is only allowed when selecting one field. -func (as *ArticleSelect) Strings(ctx context.Context) ([]string, error) { - if len(as.fields) > 1 { - return nil, errors.New("ent: ArticleSelect.Strings is not achievable when selecting more than 1 field") - } - var v []string - if err := as.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (as *ArticleSelect) StringsX(ctx context.Context) []string { - v, err := as.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a selector. It is only allowed when selecting one field. -func (as *ArticleSelect) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = as.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{article.Label} - default: - err = fmt.Errorf("ent: ArticleSelect.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (as *ArticleSelect) StringX(ctx context.Context) string { - v, err := as.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from a selector. It is only allowed when selecting one field. -func (as *ArticleSelect) Ints(ctx context.Context) ([]int, error) { - if len(as.fields) > 1 { - return nil, errors.New("ent: ArticleSelect.Ints is not achievable when selecting more than 1 field") - } - var v []int - if err := as.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (as *ArticleSelect) IntsX(ctx context.Context) []int { - v, err := as.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a selector. It is only allowed when selecting one field. -func (as *ArticleSelect) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = as.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{article.Label} - default: - err = fmt.Errorf("ent: ArticleSelect.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (as *ArticleSelect) IntX(ctx context.Context) int { - v, err := as.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. -func (as *ArticleSelect) Float64s(ctx context.Context) ([]float64, error) { - if len(as.fields) > 1 { - return nil, errors.New("ent: ArticleSelect.Float64s is not achievable when selecting more than 1 field") - } - var v []float64 - if err := as.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (as *ArticleSelect) Float64sX(ctx context.Context) []float64 { - v, err := as.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. -func (as *ArticleSelect) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = as.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{article.Label} - default: - err = fmt.Errorf("ent: ArticleSelect.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (as *ArticleSelect) Float64X(ctx context.Context) float64 { - v, err := as.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from a selector. It is only allowed when selecting one field. -func (as *ArticleSelect) Bools(ctx context.Context) ([]bool, error) { - if len(as.fields) > 1 { - return nil, errors.New("ent: ArticleSelect.Bools is not achievable when selecting more than 1 field") - } - var v []bool - if err := as.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (as *ArticleSelect) BoolsX(ctx context.Context) []bool { - v, err := as.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a selector. It is only allowed when selecting one field. -func (as *ArticleSelect) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = as.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{article.Label} - default: - err = fmt.Errorf("ent: ArticleSelect.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (as *ArticleSelect) BoolX(ctx context.Context) bool { - v, err := as.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (as *ArticleSelect) sqlScan(ctx context.Context, v interface{}) error { - rows := &sql.Rows{} - query, args := as.sqlQuery().Query() - if err := as.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (as *ArticleSelect) sqlQuery() sql.Querier { - selector := as.sql - selector.Select(selector.Columns(as.fields...)...) - return selector -} diff --git a/examples/blog/internal/data/ent/article_update.go b/examples/blog/internal/data/ent/article_update.go deleted file mode 100644 index f6c22a9b8..000000000 --- a/examples/blog/internal/data/ent/article_update.go +++ /dev/null @@ -1,711 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" -) - -// ArticleUpdate is the builder for updating Article entities. -type ArticleUpdate struct { - config - hooks []Hook - mutation *ArticleMutation -} - -// Where adds a new predicate for the ArticleUpdate builder. -func (au *ArticleUpdate) Where(ps ...predicate.Article) *ArticleUpdate { - au.mutation.predicates = append(au.mutation.predicates, ps...) - return au -} - -// SetTitle sets the "title" field. -func (au *ArticleUpdate) SetTitle(s string) *ArticleUpdate { - au.mutation.SetTitle(s) - return au -} - -// SetContent sets the "content" field. -func (au *ArticleUpdate) SetContent(s string) *ArticleUpdate { - au.mutation.SetContent(s) - return au -} - -// SetCreatedAt sets the "created_at" field. -func (au *ArticleUpdate) SetCreatedAt(t time.Time) *ArticleUpdate { - au.mutation.SetCreatedAt(t) - return au -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (au *ArticleUpdate) SetNillableCreatedAt(t *time.Time) *ArticleUpdate { - if t != nil { - au.SetCreatedAt(*t) - } - return au -} - -// SetUpdatedAt sets the "updated_at" field. -func (au *ArticleUpdate) SetUpdatedAt(t time.Time) *ArticleUpdate { - au.mutation.SetUpdatedAt(t) - return au -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (au *ArticleUpdate) SetNillableUpdatedAt(t *time.Time) *ArticleUpdate { - if t != nil { - au.SetUpdatedAt(*t) - } - return au -} - -// AddCommentIDs adds the "comments" edge to the Comment entity by IDs. -func (au *ArticleUpdate) AddCommentIDs(ids ...int64) *ArticleUpdate { - au.mutation.AddCommentIDs(ids...) - return au -} - -// AddComments adds the "comments" edges to the Comment entity. -func (au *ArticleUpdate) AddComments(c ...*Comment) *ArticleUpdate { - ids := make([]int64, len(c)) - for i := range c { - ids[i] = c[i].ID - } - return au.AddCommentIDs(ids...) -} - -// AddTagIDs adds the "tags" edge to the Tag entity by IDs. -func (au *ArticleUpdate) AddTagIDs(ids ...int64) *ArticleUpdate { - au.mutation.AddTagIDs(ids...) - return au -} - -// AddTags adds the "tags" edges to the Tag entity. -func (au *ArticleUpdate) AddTags(t ...*Tag) *ArticleUpdate { - ids := make([]int64, len(t)) - for i := range t { - ids[i] = t[i].ID - } - return au.AddTagIDs(ids...) -} - -// Mutation returns the ArticleMutation object of the builder. -func (au *ArticleUpdate) Mutation() *ArticleMutation { - return au.mutation -} - -// ClearComments clears all "comments" edges to the Comment entity. -func (au *ArticleUpdate) ClearComments() *ArticleUpdate { - au.mutation.ClearComments() - return au -} - -// RemoveCommentIDs removes the "comments" edge to Comment entities by IDs. -func (au *ArticleUpdate) RemoveCommentIDs(ids ...int64) *ArticleUpdate { - au.mutation.RemoveCommentIDs(ids...) - return au -} - -// RemoveComments removes "comments" edges to Comment entities. -func (au *ArticleUpdate) RemoveComments(c ...*Comment) *ArticleUpdate { - ids := make([]int64, len(c)) - for i := range c { - ids[i] = c[i].ID - } - return au.RemoveCommentIDs(ids...) -} - -// ClearTags clears all "tags" edges to the Tag entity. -func (au *ArticleUpdate) ClearTags() *ArticleUpdate { - au.mutation.ClearTags() - return au -} - -// RemoveTagIDs removes the "tags" edge to Tag entities by IDs. -func (au *ArticleUpdate) RemoveTagIDs(ids ...int64) *ArticleUpdate { - au.mutation.RemoveTagIDs(ids...) - return au -} - -// RemoveTags removes "tags" edges to Tag entities. -func (au *ArticleUpdate) RemoveTags(t ...*Tag) *ArticleUpdate { - ids := make([]int64, len(t)) - for i := range t { - ids[i] = t[i].ID - } - return au.RemoveTagIDs(ids...) -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (au *ArticleUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(au.hooks) == 0 { - affected, err = au.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ArticleMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - au.mutation = mutation - affected, err = au.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(au.hooks) - 1; i >= 0; i-- { - mut = au.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, au.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// SaveX is like Save, but panics if an error occurs. -func (au *ArticleUpdate) SaveX(ctx context.Context) int { - affected, err := au.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (au *ArticleUpdate) Exec(ctx context.Context) error { - _, err := au.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (au *ArticleUpdate) ExecX(ctx context.Context) { - if err := au.Exec(ctx); err != nil { - panic(err) - } -} - -func (au *ArticleUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: article.Table, - Columns: article.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - if ps := au.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := au.mutation.Title(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: article.FieldTitle, - }) - } - if value, ok := au.mutation.Content(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: article.FieldContent, - }) - } - if value, ok := au.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: article.FieldCreatedAt, - }) - } - if value, ok := au.mutation.UpdatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: article.FieldUpdatedAt, - }) - } - if au.mutation.CommentsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: article.CommentsTable, - Columns: []string{article.CommentsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := au.mutation.RemovedCommentsIDs(); len(nodes) > 0 && !au.mutation.CommentsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: article.CommentsTable, - Columns: []string{article.CommentsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := au.mutation.CommentsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: article.CommentsTable, - Columns: []string{article.CommentsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if au.mutation.TagsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: article.TagsTable, - Columns: article.TagsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := au.mutation.RemovedTagsIDs(); len(nodes) > 0 && !au.mutation.TagsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: article.TagsTable, - Columns: article.TagsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := au.mutation.TagsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: article.TagsTable, - Columns: article.TagsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{article.Label} - } else if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - return 0, err - } - return n, nil -} - -// ArticleUpdateOne is the builder for updating a single Article entity. -type ArticleUpdateOne struct { - config - hooks []Hook - mutation *ArticleMutation -} - -// SetTitle sets the "title" field. -func (auo *ArticleUpdateOne) SetTitle(s string) *ArticleUpdateOne { - auo.mutation.SetTitle(s) - return auo -} - -// SetContent sets the "content" field. -func (auo *ArticleUpdateOne) SetContent(s string) *ArticleUpdateOne { - auo.mutation.SetContent(s) - return auo -} - -// SetCreatedAt sets the "created_at" field. -func (auo *ArticleUpdateOne) SetCreatedAt(t time.Time) *ArticleUpdateOne { - auo.mutation.SetCreatedAt(t) - return auo -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (auo *ArticleUpdateOne) SetNillableCreatedAt(t *time.Time) *ArticleUpdateOne { - if t != nil { - auo.SetCreatedAt(*t) - } - return auo -} - -// SetUpdatedAt sets the "updated_at" field. -func (auo *ArticleUpdateOne) SetUpdatedAt(t time.Time) *ArticleUpdateOne { - auo.mutation.SetUpdatedAt(t) - return auo -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (auo *ArticleUpdateOne) SetNillableUpdatedAt(t *time.Time) *ArticleUpdateOne { - if t != nil { - auo.SetUpdatedAt(*t) - } - return auo -} - -// AddCommentIDs adds the "comments" edge to the Comment entity by IDs. -func (auo *ArticleUpdateOne) AddCommentIDs(ids ...int64) *ArticleUpdateOne { - auo.mutation.AddCommentIDs(ids...) - return auo -} - -// AddComments adds the "comments" edges to the Comment entity. -func (auo *ArticleUpdateOne) AddComments(c ...*Comment) *ArticleUpdateOne { - ids := make([]int64, len(c)) - for i := range c { - ids[i] = c[i].ID - } - return auo.AddCommentIDs(ids...) -} - -// AddTagIDs adds the "tags" edge to the Tag entity by IDs. -func (auo *ArticleUpdateOne) AddTagIDs(ids ...int64) *ArticleUpdateOne { - auo.mutation.AddTagIDs(ids...) - return auo -} - -// AddTags adds the "tags" edges to the Tag entity. -func (auo *ArticleUpdateOne) AddTags(t ...*Tag) *ArticleUpdateOne { - ids := make([]int64, len(t)) - for i := range t { - ids[i] = t[i].ID - } - return auo.AddTagIDs(ids...) -} - -// Mutation returns the ArticleMutation object of the builder. -func (auo *ArticleUpdateOne) Mutation() *ArticleMutation { - return auo.mutation -} - -// ClearComments clears all "comments" edges to the Comment entity. -func (auo *ArticleUpdateOne) ClearComments() *ArticleUpdateOne { - auo.mutation.ClearComments() - return auo -} - -// RemoveCommentIDs removes the "comments" edge to Comment entities by IDs. -func (auo *ArticleUpdateOne) RemoveCommentIDs(ids ...int64) *ArticleUpdateOne { - auo.mutation.RemoveCommentIDs(ids...) - return auo -} - -// RemoveComments removes "comments" edges to Comment entities. -func (auo *ArticleUpdateOne) RemoveComments(c ...*Comment) *ArticleUpdateOne { - ids := make([]int64, len(c)) - for i := range c { - ids[i] = c[i].ID - } - return auo.RemoveCommentIDs(ids...) -} - -// ClearTags clears all "tags" edges to the Tag entity. -func (auo *ArticleUpdateOne) ClearTags() *ArticleUpdateOne { - auo.mutation.ClearTags() - return auo -} - -// RemoveTagIDs removes the "tags" edge to Tag entities by IDs. -func (auo *ArticleUpdateOne) RemoveTagIDs(ids ...int64) *ArticleUpdateOne { - auo.mutation.RemoveTagIDs(ids...) - return auo -} - -// RemoveTags removes "tags" edges to Tag entities. -func (auo *ArticleUpdateOne) RemoveTags(t ...*Tag) *ArticleUpdateOne { - ids := make([]int64, len(t)) - for i := range t { - ids[i] = t[i].ID - } - return auo.RemoveTagIDs(ids...) -} - -// Save executes the query and returns the updated Article entity. -func (auo *ArticleUpdateOne) Save(ctx context.Context) (*Article, error) { - var ( - err error - node *Article - ) - if len(auo.hooks) == 0 { - node, err = auo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ArticleMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - auo.mutation = mutation - node, err = auo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(auo.hooks) - 1; i >= 0; i-- { - mut = auo.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, auo.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX is like Save, but panics if an error occurs. -func (auo *ArticleUpdateOne) SaveX(ctx context.Context) *Article { - node, err := auo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (auo *ArticleUpdateOne) Exec(ctx context.Context) error { - _, err := auo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (auo *ArticleUpdateOne) ExecX(ctx context.Context) { - if err := auo.Exec(ctx); err != nil { - panic(err) - } -} - -func (auo *ArticleUpdateOne) sqlSave(ctx context.Context) (_node *Article, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: article.Table, - Columns: article.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - id, ok := auo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Article.ID for update")} - } - _spec.Node.ID.Value = id - if ps := auo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := auo.mutation.Title(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: article.FieldTitle, - }) - } - if value, ok := auo.mutation.Content(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: article.FieldContent, - }) - } - if value, ok := auo.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: article.FieldCreatedAt, - }) - } - if value, ok := auo.mutation.UpdatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: article.FieldUpdatedAt, - }) - } - if auo.mutation.CommentsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: article.CommentsTable, - Columns: []string{article.CommentsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := auo.mutation.RemovedCommentsIDs(); len(nodes) > 0 && !auo.mutation.CommentsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: article.CommentsTable, - Columns: []string{article.CommentsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := auo.mutation.CommentsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: article.CommentsTable, - Columns: []string{article.CommentsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if auo.mutation.TagsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: article.TagsTable, - Columns: article.TagsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := auo.mutation.RemovedTagsIDs(); len(nodes) > 0 && !auo.mutation.TagsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: article.TagsTable, - Columns: article.TagsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := auo.mutation.TagsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: article.TagsTable, - Columns: article.TagsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - _node = &Article{config: auo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{article.Label} - } else if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - return nil, err - } - return _node, nil -} diff --git a/examples/blog/internal/data/ent/client.go b/examples/blog/internal/data/ent/client.go deleted file mode 100644 index 1c639c0ff..000000000 --- a/examples/blog/internal/data/ent/client.go +++ /dev/null @@ -1,465 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "log" - - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/migrate" - - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" -) - -// Client is the client that holds all ent builders. -type Client struct { - config - // Schema is the client for creating, migrating and dropping schema. - Schema *migrate.Schema - // Article is the client for interacting with the Article builders. - Article *ArticleClient - // Comment is the client for interacting with the Comment builders. - Comment *CommentClient - // Tag is the client for interacting with the Tag builders. - Tag *TagClient -} - -// NewClient creates a new client configured with the given options. -func NewClient(opts ...Option) *Client { - cfg := config{log: log.Println, hooks: &hooks{}} - cfg.options(opts...) - client := &Client{config: cfg} - client.init() - return client -} - -func (c *Client) init() { - c.Schema = migrate.NewSchema(c.driver) - c.Article = NewArticleClient(c.config) - c.Comment = NewCommentClient(c.config) - c.Tag = NewTagClient(c.config) -} - -// Open opens a database/sql.DB specified by the driver name and -// the data source name, and returns a new client attached to it. -// Optional parameters can be added for configuring the client. -func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { - switch driverName { - case dialect.MySQL, dialect.Postgres, dialect.SQLite: - drv, err := sql.Open(driverName, dataSourceName) - if err != nil { - return nil, err - } - return NewClient(append(options, Driver(drv))...), nil - default: - return nil, fmt.Errorf("unsupported driver: %q", driverName) - } -} - -// Tx returns a new transactional client. The provided context -// is used until the transaction is committed or rolled back. -func (c *Client) Tx(ctx context.Context) (*Tx, error) { - if _, ok := c.driver.(*txDriver); ok { - return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") - } - tx, err := newTx(ctx, c.driver) - if err != nil { - return nil, fmt.Errorf("ent: starting a transaction: %v", err) - } - cfg := c.config - cfg.driver = tx - return &Tx{ - ctx: ctx, - config: cfg, - Article: NewArticleClient(cfg), - Comment: NewCommentClient(cfg), - Tag: NewTagClient(cfg), - }, nil -} - -// BeginTx returns a transactional client with specified options. -func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { - if _, ok := c.driver.(*txDriver); ok { - return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") - } - tx, err := c.driver.(interface { - BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) - }).BeginTx(ctx, opts) - if err != nil { - return nil, fmt.Errorf("ent: starting a transaction: %v", err) - } - cfg := c.config - cfg.driver = &txDriver{tx: tx, drv: c.driver} - return &Tx{ - config: cfg, - Article: NewArticleClient(cfg), - Comment: NewCommentClient(cfg), - Tag: NewTagClient(cfg), - }, nil -} - -// Debug returns a new debug-client. It's used to get verbose logging on specific operations. -// -// client.Debug(). -// Article. -// Query(). -// Count(ctx) -// -func (c *Client) Debug() *Client { - if c.debug { - return c - } - cfg := c.config - cfg.driver = dialect.Debug(c.driver, c.log) - client := &Client{config: cfg} - client.init() - return client -} - -// Close closes the database connection and prevents new queries from starting. -func (c *Client) Close() error { - return c.driver.Close() -} - -// Use adds the mutation hooks to all the entity clients. -// In order to add hooks to a specific client, call: `client.Node.Use(...)`. -func (c *Client) Use(hooks ...Hook) { - c.Article.Use(hooks...) - c.Comment.Use(hooks...) - c.Tag.Use(hooks...) -} - -// ArticleClient is a client for the Article schema. -type ArticleClient struct { - config -} - -// NewArticleClient returns a client for the Article from the given config. -func NewArticleClient(c config) *ArticleClient { - return &ArticleClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `article.Hooks(f(g(h())))`. -func (c *ArticleClient) Use(hooks ...Hook) { - c.hooks.Article = append(c.hooks.Article, hooks...) -} - -// Create returns a create builder for Article. -func (c *ArticleClient) Create() *ArticleCreate { - mutation := newArticleMutation(c.config, OpCreate) - return &ArticleCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of Article entities. -func (c *ArticleClient) CreateBulk(builders ...*ArticleCreate) *ArticleCreateBulk { - return &ArticleCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for Article. -func (c *ArticleClient) Update() *ArticleUpdate { - mutation := newArticleMutation(c.config, OpUpdate) - return &ArticleUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *ArticleClient) UpdateOne(a *Article) *ArticleUpdateOne { - mutation := newArticleMutation(c.config, OpUpdateOne, withArticle(a)) - return &ArticleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *ArticleClient) UpdateOneID(id int64) *ArticleUpdateOne { - mutation := newArticleMutation(c.config, OpUpdateOne, withArticleID(id)) - return &ArticleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for Article. -func (c *ArticleClient) Delete() *ArticleDelete { - mutation := newArticleMutation(c.config, OpDelete) - return &ArticleDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a delete builder for the given entity. -func (c *ArticleClient) DeleteOne(a *Article) *ArticleDeleteOne { - return c.DeleteOneID(a.ID) -} - -// DeleteOneID returns a delete builder for the given id. -func (c *ArticleClient) DeleteOneID(id int64) *ArticleDeleteOne { - builder := c.Delete().Where(article.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &ArticleDeleteOne{builder} -} - -// Query returns a query builder for Article. -func (c *ArticleClient) Query() *ArticleQuery { - return &ArticleQuery{config: c.config} -} - -// Get returns a Article entity by its id. -func (c *ArticleClient) Get(ctx context.Context, id int64) (*Article, error) { - return c.Query().Where(article.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *ArticleClient) GetX(ctx context.Context, id int64) *Article { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// QueryComments queries the comments edge of a Article. -func (c *ArticleClient) QueryComments(a *Article) *CommentQuery { - query := &CommentQuery{config: c.config} - query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { - id := a.ID - step := sqlgraph.NewStep( - sqlgraph.From(article.Table, article.FieldID, id), - sqlgraph.To(comment.Table, comment.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, article.CommentsTable, article.CommentsColumn), - ) - fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// QueryTags queries the tags edge of a Article. -func (c *ArticleClient) QueryTags(a *Article) *TagQuery { - query := &TagQuery{config: c.config} - query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { - id := a.ID - step := sqlgraph.NewStep( - sqlgraph.From(article.Table, article.FieldID, id), - sqlgraph.To(tag.Table, tag.FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, article.TagsTable, article.TagsPrimaryKey...), - ) - fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// Hooks returns the client hooks. -func (c *ArticleClient) Hooks() []Hook { - return c.hooks.Article -} - -// CommentClient is a client for the Comment schema. -type CommentClient struct { - config -} - -// NewCommentClient returns a client for the Comment from the given config. -func NewCommentClient(c config) *CommentClient { - return &CommentClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `comment.Hooks(f(g(h())))`. -func (c *CommentClient) Use(hooks ...Hook) { - c.hooks.Comment = append(c.hooks.Comment, hooks...) -} - -// Create returns a create builder for Comment. -func (c *CommentClient) Create() *CommentCreate { - mutation := newCommentMutation(c.config, OpCreate) - return &CommentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of Comment entities. -func (c *CommentClient) CreateBulk(builders ...*CommentCreate) *CommentCreateBulk { - return &CommentCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for Comment. -func (c *CommentClient) Update() *CommentUpdate { - mutation := newCommentMutation(c.config, OpUpdate) - return &CommentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *CommentClient) UpdateOne(co *Comment) *CommentUpdateOne { - mutation := newCommentMutation(c.config, OpUpdateOne, withComment(co)) - return &CommentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *CommentClient) UpdateOneID(id int64) *CommentUpdateOne { - mutation := newCommentMutation(c.config, OpUpdateOne, withCommentID(id)) - return &CommentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for Comment. -func (c *CommentClient) Delete() *CommentDelete { - mutation := newCommentMutation(c.config, OpDelete) - return &CommentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a delete builder for the given entity. -func (c *CommentClient) DeleteOne(co *Comment) *CommentDeleteOne { - return c.DeleteOneID(co.ID) -} - -// DeleteOneID returns a delete builder for the given id. -func (c *CommentClient) DeleteOneID(id int64) *CommentDeleteOne { - builder := c.Delete().Where(comment.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &CommentDeleteOne{builder} -} - -// Query returns a query builder for Comment. -func (c *CommentClient) Query() *CommentQuery { - return &CommentQuery{config: c.config} -} - -// Get returns a Comment entity by its id. -func (c *CommentClient) Get(ctx context.Context, id int64) (*Comment, error) { - return c.Query().Where(comment.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *CommentClient) GetX(ctx context.Context, id int64) *Comment { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// QueryPost queries the post edge of a Comment. -func (c *CommentClient) QueryPost(co *Comment) *ArticleQuery { - query := &ArticleQuery{config: c.config} - query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { - id := co.ID - step := sqlgraph.NewStep( - sqlgraph.From(comment.Table, comment.FieldID, id), - sqlgraph.To(article.Table, article.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, comment.PostTable, comment.PostColumn), - ) - fromV = sqlgraph.Neighbors(co.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// Hooks returns the client hooks. -func (c *CommentClient) Hooks() []Hook { - return c.hooks.Comment -} - -// TagClient is a client for the Tag schema. -type TagClient struct { - config -} - -// NewTagClient returns a client for the Tag from the given config. -func NewTagClient(c config) *TagClient { - return &TagClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `tag.Hooks(f(g(h())))`. -func (c *TagClient) Use(hooks ...Hook) { - c.hooks.Tag = append(c.hooks.Tag, hooks...) -} - -// Create returns a create builder for Tag. -func (c *TagClient) Create() *TagCreate { - mutation := newTagMutation(c.config, OpCreate) - return &TagCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of Tag entities. -func (c *TagClient) CreateBulk(builders ...*TagCreate) *TagCreateBulk { - return &TagCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for Tag. -func (c *TagClient) Update() *TagUpdate { - mutation := newTagMutation(c.config, OpUpdate) - return &TagUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *TagClient) UpdateOne(t *Tag) *TagUpdateOne { - mutation := newTagMutation(c.config, OpUpdateOne, withTag(t)) - return &TagUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *TagClient) UpdateOneID(id int64) *TagUpdateOne { - mutation := newTagMutation(c.config, OpUpdateOne, withTagID(id)) - return &TagUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for Tag. -func (c *TagClient) Delete() *TagDelete { - mutation := newTagMutation(c.config, OpDelete) - return &TagDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a delete builder for the given entity. -func (c *TagClient) DeleteOne(t *Tag) *TagDeleteOne { - return c.DeleteOneID(t.ID) -} - -// DeleteOneID returns a delete builder for the given id. -func (c *TagClient) DeleteOneID(id int64) *TagDeleteOne { - builder := c.Delete().Where(tag.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &TagDeleteOne{builder} -} - -// Query returns a query builder for Tag. -func (c *TagClient) Query() *TagQuery { - return &TagQuery{config: c.config} -} - -// Get returns a Tag entity by its id. -func (c *TagClient) Get(ctx context.Context, id int64) (*Tag, error) { - return c.Query().Where(tag.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *TagClient) GetX(ctx context.Context, id int64) *Tag { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// QueryPosts queries the posts edge of a Tag. -func (c *TagClient) QueryPosts(t *Tag) *ArticleQuery { - query := &ArticleQuery{config: c.config} - query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { - id := t.ID - step := sqlgraph.NewStep( - sqlgraph.From(tag.Table, tag.FieldID, id), - sqlgraph.To(article.Table, article.FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, tag.PostsTable, tag.PostsPrimaryKey...), - ) - fromV = sqlgraph.Neighbors(t.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// Hooks returns the client hooks. -func (c *TagClient) Hooks() []Hook { - return c.hooks.Tag -} diff --git a/examples/blog/internal/data/ent/comment.go b/examples/blog/internal/data/ent/comment.go deleted file mode 100644 index cc4867675..000000000 --- a/examples/blog/internal/data/ent/comment.go +++ /dev/null @@ -1,174 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent/dialect/sql" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" -) - -// Comment is the model entity for the Comment schema. -type Comment struct { - config `json:"-"` - // ID of the ent. - ID int64 `json:"id,omitempty"` - // Name holds the value of the "name" field. - Name string `json:"name,omitempty"` - // Content holds the value of the "content" field. - Content string `json:"content,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // UpdatedAt holds the value of the "updated_at" field. - UpdatedAt time.Time `json:"updated_at,omitempty"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the CommentQuery when eager-loading is set. - Edges CommentEdges `json:"edges"` - article_comments *int64 -} - -// CommentEdges holds the relations/edges for other nodes in the graph. -type CommentEdges struct { - // Post holds the value of the post edge. - Post *Article `json:"post,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [1]bool -} - -// PostOrErr returns the Post value or an error if the edge -// was not loaded in eager-loading, or loaded but was not found. -func (e CommentEdges) PostOrErr() (*Article, error) { - if e.loadedTypes[0] { - if e.Post == nil { - // The edge post was loaded in eager-loading, - // but was not found. - return nil, &NotFoundError{label: article.Label} - } - return e.Post, nil - } - return nil, &NotLoadedError{edge: "post"} -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*Comment) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) - for i := range columns { - switch columns[i] { - case comment.FieldID: - values[i] = &sql.NullInt64{} - case comment.FieldName, comment.FieldContent: - values[i] = &sql.NullString{} - case comment.FieldCreatedAt, comment.FieldUpdatedAt: - values[i] = &sql.NullTime{} - case comment.ForeignKeys[0]: // article_comments - values[i] = &sql.NullInt64{} - default: - return nil, fmt.Errorf("unexpected column %q for type Comment", columns[i]) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Comment fields. -func (c *Comment) assignValues(columns []string, values []interface{}) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case comment.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - c.ID = int64(value.Int64) - case comment.FieldName: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field name", values[i]) - } else if value.Valid { - c.Name = value.String - } - case comment.FieldContent: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field content", values[i]) - } else if value.Valid { - c.Content = value.String - } - case comment.FieldCreatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[i]) - } else if value.Valid { - c.CreatedAt = value.Time - } - case comment.FieldUpdatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[i]) - } else if value.Valid { - c.UpdatedAt = value.Time - } - case comment.ForeignKeys[0]: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for edge-field article_comments", value) - } else if value.Valid { - c.article_comments = new(int64) - *c.article_comments = int64(value.Int64) - } - } - } - return nil -} - -// QueryPost queries the "post" edge of the Comment entity. -func (c *Comment) QueryPost() *ArticleQuery { - return (&CommentClient{config: c.config}).QueryPost(c) -} - -// Update returns a builder for updating this Comment. -// Note that you need to call Comment.Unwrap() before calling this method if this Comment -// was returned from a transaction, and the transaction was committed or rolled back. -func (c *Comment) Update() *CommentUpdateOne { - return (&CommentClient{config: c.config}).UpdateOne(c) -} - -// Unwrap unwraps the Comment entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (c *Comment) Unwrap() *Comment { - tx, ok := c.config.driver.(*txDriver) - if !ok { - panic("ent: Comment is not a transactional entity") - } - c.config.driver = tx.drv - return c -} - -// String implements the fmt.Stringer. -func (c *Comment) String() string { - var builder strings.Builder - builder.WriteString("Comment(") - builder.WriteString(fmt.Sprintf("id=%v", c.ID)) - builder.WriteString(", name=") - builder.WriteString(c.Name) - builder.WriteString(", content=") - builder.WriteString(c.Content) - builder.WriteString(", created_at=") - builder.WriteString(c.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", updated_at=") - builder.WriteString(c.UpdatedAt.Format(time.ANSIC)) - builder.WriteByte(')') - return builder.String() -} - -// Comments is a parsable slice of Comment. -type Comments []*Comment - -func (c Comments) config(cfg config) { - for _i := range c { - c[_i].config = cfg - } -} diff --git a/examples/blog/internal/data/ent/comment/comment.go b/examples/blog/internal/data/ent/comment/comment.go deleted file mode 100644 index 928871dab..000000000 --- a/examples/blog/internal/data/ent/comment/comment.go +++ /dev/null @@ -1,71 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package comment - -import ( - "time" -) - -const ( - // Label holds the string label denoting the comment type in the database. - Label = "comment" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldName holds the string denoting the name field in the database. - FieldName = "name" - // FieldContent holds the string denoting the content field in the database. - FieldContent = "content" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldUpdatedAt holds the string denoting the updated_at field in the database. - FieldUpdatedAt = "updated_at" - - // EdgePost holds the string denoting the post edge name in mutations. - EdgePost = "post" - - // Table holds the table name of the comment in the database. - Table = "comments" - // PostTable is the table the holds the post relation/edge. - PostTable = "comments" - // PostInverseTable is the table name for the Article entity. - // It exists in this package in order to avoid circular dependency with the "article" package. - PostInverseTable = "articles" - // PostColumn is the table column denoting the post relation/edge. - PostColumn = "article_comments" -) - -// Columns holds all SQL columns for comment fields. -var Columns = []string{ - FieldID, - FieldName, - FieldContent, - FieldCreatedAt, - FieldUpdatedAt, -} - -// ForeignKeys holds the SQL foreign-keys that are owned by the Comment type. -var ForeignKeys = []string{ - "article_comments", -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - for i := range ForeignKeys { - if column == ForeignKeys[i] { - return true - } - } - return false -} - -var ( - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. - DefaultUpdatedAt func() time.Time -) diff --git a/examples/blog/internal/data/ent/comment/where.go b/examples/blog/internal/data/ent/comment/where.go deleted file mode 100644 index 24410d12e..000000000 --- a/examples/blog/internal/data/ent/comment/where.go +++ /dev/null @@ -1,556 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package comment - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int64) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int64) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int64) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int64) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int64) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int64) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int64) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int64) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int64) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) -} - -// Name applies equality check predicate on the "name" field. It's identical to NameEQ. -func Name(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) -} - -// Content applies equality check predicate on the "content" field. It's identical to ContentEQ. -func Content(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldContent), v)) - }) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) -} - -// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. -func UpdatedAt(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) -} - -// NameEQ applies the EQ predicate on the "name" field. -func NameEQ(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) -} - -// NameNEQ applies the NEQ predicate on the "name" field. -func NameNEQ(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) -} - -// NameIn applies the In predicate on the "name" field. -func NameIn(vs ...string) predicate.Comment { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Comment(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldName), v...)) - }) -} - -// NameNotIn applies the NotIn predicate on the "name" field. -func NameNotIn(vs ...string) predicate.Comment { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Comment(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) -} - -// NameGT applies the GT predicate on the "name" field. -func NameGT(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) -} - -// NameGTE applies the GTE predicate on the "name" field. -func NameGTE(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) -} - -// NameLT applies the LT predicate on the "name" field. -func NameLT(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) -} - -// NameLTE applies the LTE predicate on the "name" field. -func NameLTE(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) -} - -// NameContains applies the Contains predicate on the "name" field. -func NameContains(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) -} - -// NameHasPrefix applies the HasPrefix predicate on the "name" field. -func NameHasPrefix(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) -} - -// NameHasSuffix applies the HasSuffix predicate on the "name" field. -func NameHasSuffix(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) -} - -// NameEqualFold applies the EqualFold predicate on the "name" field. -func NameEqualFold(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) -} - -// NameContainsFold applies the ContainsFold predicate on the "name" field. -func NameContainsFold(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) -} - -// ContentEQ applies the EQ predicate on the "content" field. -func ContentEQ(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldContent), v)) - }) -} - -// ContentNEQ applies the NEQ predicate on the "content" field. -func ContentNEQ(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldContent), v)) - }) -} - -// ContentIn applies the In predicate on the "content" field. -func ContentIn(vs ...string) predicate.Comment { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Comment(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldContent), v...)) - }) -} - -// ContentNotIn applies the NotIn predicate on the "content" field. -func ContentNotIn(vs ...string) predicate.Comment { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Comment(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldContent), v...)) - }) -} - -// ContentGT applies the GT predicate on the "content" field. -func ContentGT(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldContent), v)) - }) -} - -// ContentGTE applies the GTE predicate on the "content" field. -func ContentGTE(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldContent), v)) - }) -} - -// ContentLT applies the LT predicate on the "content" field. -func ContentLT(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldContent), v)) - }) -} - -// ContentLTE applies the LTE predicate on the "content" field. -func ContentLTE(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldContent), v)) - }) -} - -// ContentContains applies the Contains predicate on the "content" field. -func ContentContains(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldContent), v)) - }) -} - -// ContentHasPrefix applies the HasPrefix predicate on the "content" field. -func ContentHasPrefix(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldContent), v)) - }) -} - -// ContentHasSuffix applies the HasSuffix predicate on the "content" field. -func ContentHasSuffix(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldContent), v)) - }) -} - -// ContentEqualFold applies the EqualFold predicate on the "content" field. -func ContentEqualFold(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldContent), v)) - }) -} - -// ContentContainsFold applies the ContainsFold predicate on the "content" field. -func ContentContainsFold(v string) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldContent), v)) - }) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.Comment { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Comment(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.Comment { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Comment(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) -} - -// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. -func UpdatedAtEQ(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. -func UpdatedAtNEQ(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtIn applies the In predicate on the "updated_at" field. -func UpdatedAtIn(vs ...time.Time) predicate.Comment { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Comment(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) -} - -// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. -func UpdatedAtNotIn(vs ...time.Time) predicate.Comment { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Comment(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) -} - -// UpdatedAtGT applies the GT predicate on the "updated_at" field. -func UpdatedAtGT(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. -func UpdatedAtGTE(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtLT applies the LT predicate on the "updated_at" field. -func UpdatedAtLT(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. -func UpdatedAtLTE(v time.Time) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) -} - -// HasPost applies the HasEdge predicate on the "post" edge. -func HasPost() predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(PostTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, PostTable, PostColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasPostWith applies the HasEdge predicate on the "post" edge with a given conditions (other predicates). -func HasPostWith(preds ...predicate.Article) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(PostInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, PostTable, PostColumn), - ) - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.Comment) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.Comment) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.Comment) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - p(s.Not()) - }) -} diff --git a/examples/blog/internal/data/ent/comment_create.go b/examples/blog/internal/data/ent/comment_create.go deleted file mode 100644 index a05a6498f..000000000 --- a/examples/blog/internal/data/ent/comment_create.go +++ /dev/null @@ -1,319 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" -) - -// CommentCreate is the builder for creating a Comment entity. -type CommentCreate struct { - config - mutation *CommentMutation - hooks []Hook -} - -// SetName sets the "name" field. -func (cc *CommentCreate) SetName(s string) *CommentCreate { - cc.mutation.SetName(s) - return cc -} - -// SetContent sets the "content" field. -func (cc *CommentCreate) SetContent(s string) *CommentCreate { - cc.mutation.SetContent(s) - return cc -} - -// SetCreatedAt sets the "created_at" field. -func (cc *CommentCreate) SetCreatedAt(t time.Time) *CommentCreate { - cc.mutation.SetCreatedAt(t) - return cc -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (cc *CommentCreate) SetNillableCreatedAt(t *time.Time) *CommentCreate { - if t != nil { - cc.SetCreatedAt(*t) - } - return cc -} - -// SetUpdatedAt sets the "updated_at" field. -func (cc *CommentCreate) SetUpdatedAt(t time.Time) *CommentCreate { - cc.mutation.SetUpdatedAt(t) - return cc -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (cc *CommentCreate) SetNillableUpdatedAt(t *time.Time) *CommentCreate { - if t != nil { - cc.SetUpdatedAt(*t) - } - return cc -} - -// SetID sets the "id" field. -func (cc *CommentCreate) SetID(i int64) *CommentCreate { - cc.mutation.SetID(i) - return cc -} - -// SetPostID sets the "post" edge to the Article entity by ID. -func (cc *CommentCreate) SetPostID(id int64) *CommentCreate { - cc.mutation.SetPostID(id) - return cc -} - -// SetNillablePostID sets the "post" edge to the Article entity by ID if the given value is not nil. -func (cc *CommentCreate) SetNillablePostID(id *int64) *CommentCreate { - if id != nil { - cc = cc.SetPostID(*id) - } - return cc -} - -// SetPost sets the "post" edge to the Article entity. -func (cc *CommentCreate) SetPost(a *Article) *CommentCreate { - return cc.SetPostID(a.ID) -} - -// Mutation returns the CommentMutation object of the builder. -func (cc *CommentCreate) Mutation() *CommentMutation { - return cc.mutation -} - -// Save creates the Comment in the database. -func (cc *CommentCreate) Save(ctx context.Context) (*Comment, error) { - var ( - err error - node *Comment - ) - cc.defaults() - if len(cc.hooks) == 0 { - if err = cc.check(); err != nil { - return nil, err - } - node, err = cc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CommentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = cc.check(); err != nil { - return nil, err - } - cc.mutation = mutation - node, err = cc.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(cc.hooks) - 1; i >= 0; i-- { - mut = cc.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cc.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX calls Save and panics if Save returns an error. -func (cc *CommentCreate) SaveX(ctx context.Context) *Comment { - v, err := cc.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// defaults sets the default values of the builder before save. -func (cc *CommentCreate) defaults() { - if _, ok := cc.mutation.CreatedAt(); !ok { - v := comment.DefaultCreatedAt() - cc.mutation.SetCreatedAt(v) - } - if _, ok := cc.mutation.UpdatedAt(); !ok { - v := comment.DefaultUpdatedAt() - cc.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (cc *CommentCreate) check() error { - if _, ok := cc.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New("ent: missing required field \"name\"")} - } - if _, ok := cc.mutation.Content(); !ok { - return &ValidationError{Name: "content", err: errors.New("ent: missing required field \"content\"")} - } - if _, ok := cc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New("ent: missing required field \"created_at\"")} - } - if _, ok := cc.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New("ent: missing required field \"updated_at\"")} - } - return nil -} - -func (cc *CommentCreate) sqlSave(ctx context.Context) (*Comment, error) { - _node, _spec := cc.createSpec() - if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil { - if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - return nil, err - } - if _node.ID == 0 { - id := _spec.ID.Value.(int64) - _node.ID = int64(id) - } - return _node, nil -} - -func (cc *CommentCreate) createSpec() (*Comment, *sqlgraph.CreateSpec) { - var ( - _node = &Comment{config: cc.config} - _spec = &sqlgraph.CreateSpec{ - Table: comment.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - } - ) - if id, ok := cc.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = id - } - if value, ok := cc.mutation.Name(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: comment.FieldName, - }) - _node.Name = value - } - if value, ok := cc.mutation.Content(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: comment.FieldContent, - }) - _node.Content = value - } - if value, ok := cc.mutation.CreatedAt(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: comment.FieldCreatedAt, - }) - _node.CreatedAt = value - } - if value, ok := cc.mutation.UpdatedAt(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: comment.FieldUpdatedAt, - }) - _node.UpdatedAt = value - } - if nodes := cc.mutation.PostIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: comment.PostTable, - Columns: []string{comment.PostColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - return _node, _spec -} - -// CommentCreateBulk is the builder for creating many Comment entities in bulk. -type CommentCreateBulk struct { - config - builders []*CommentCreate -} - -// Save creates the Comment entities in the database. -func (ccb *CommentCreateBulk) Save(ctx context.Context) ([]*Comment, error) { - specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) - nodes := make([]*Comment, len(ccb.builders)) - mutators := make([]Mutator, len(ccb.builders)) - for i := range ccb.builders { - func(i int, root context.Context) { - builder := ccb.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CommentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() - var err error - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation) - } else { - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, ccb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil { - if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - } - } - mutation.done = true - if err != nil { - return nil, err - } - if nodes[i].ID == 0 { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int64(id) - } - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, ccb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (ccb *CommentCreateBulk) SaveX(ctx context.Context) []*Comment { - v, err := ccb.Save(ctx) - if err != nil { - panic(err) - } - return v -} diff --git a/examples/blog/internal/data/ent/comment_delete.go b/examples/blog/internal/data/ent/comment_delete.go deleted file mode 100644 index 821ccc762..000000000 --- a/examples/blog/internal/data/ent/comment_delete.go +++ /dev/null @@ -1,108 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" -) - -// CommentDelete is the builder for deleting a Comment entity. -type CommentDelete struct { - config - hooks []Hook - mutation *CommentMutation -} - -// Where adds a new predicate to the CommentDelete builder. -func (cd *CommentDelete) Where(ps ...predicate.Comment) *CommentDelete { - cd.mutation.predicates = append(cd.mutation.predicates, ps...) - return cd -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (cd *CommentDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(cd.hooks) == 0 { - affected, err = cd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CommentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - cd.mutation = mutation - affected, err = cd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(cd.hooks) - 1; i >= 0; i-- { - mut = cd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cd.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// ExecX is like Exec, but panics if an error occurs. -func (cd *CommentDelete) ExecX(ctx context.Context) int { - n, err := cd.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (cd *CommentDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: comment.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - }, - } - if ps := cd.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return sqlgraph.DeleteNodes(ctx, cd.driver, _spec) -} - -// CommentDeleteOne is the builder for deleting a single Comment entity. -type CommentDeleteOne struct { - cd *CommentDelete -} - -// Exec executes the deletion query. -func (cdo *CommentDeleteOne) Exec(ctx context.Context) error { - n, err := cdo.cd.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{comment.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (cdo *CommentDeleteOne) ExecX(ctx context.Context) { - cdo.cd.ExecX(ctx) -} diff --git a/examples/blog/internal/data/ent/comment_query.go b/examples/blog/internal/data/ent/comment_query.go deleted file mode 100644 index 2a9202714..000000000 --- a/examples/blog/internal/data/ent/comment_query.go +++ /dev/null @@ -1,970 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "math" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" -) - -// CommentQuery is the builder for querying Comment entities. -type CommentQuery struct { - config - limit *int - offset *int - order []OrderFunc - fields []string - predicates []predicate.Comment - // eager-loading edges. - withPost *ArticleQuery - withFKs bool - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the CommentQuery builder. -func (cq *CommentQuery) Where(ps ...predicate.Comment) *CommentQuery { - cq.predicates = append(cq.predicates, ps...) - return cq -} - -// Limit adds a limit step to the query. -func (cq *CommentQuery) Limit(limit int) *CommentQuery { - cq.limit = &limit - return cq -} - -// Offset adds an offset step to the query. -func (cq *CommentQuery) Offset(offset int) *CommentQuery { - cq.offset = &offset - return cq -} - -// Order adds an order step to the query. -func (cq *CommentQuery) Order(o ...OrderFunc) *CommentQuery { - cq.order = append(cq.order, o...) - return cq -} - -// QueryPost chains the current query on the "post" edge. -func (cq *CommentQuery) QueryPost() *ArticleQuery { - query := &ArticleQuery{config: cq.config} - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := cq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := cq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(comment.Table, comment.FieldID, selector), - sqlgraph.To(article.Table, article.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, comment.PostTable, comment.PostColumn), - ) - fromU = sqlgraph.SetNeighbors(cq.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first Comment entity from the query. -// Returns a *NotFoundError when no Comment was found. -func (cq *CommentQuery) First(ctx context.Context) (*Comment, error) { - nodes, err := cq.Limit(1).All(ctx) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{comment.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (cq *CommentQuery) FirstX(ctx context.Context) *Comment { - node, err := cq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first Comment ID from the query. -// Returns a *NotFoundError when no Comment ID was found. -func (cq *CommentQuery) FirstID(ctx context.Context) (id int64, err error) { - var ids []int64 - if ids, err = cq.Limit(1).IDs(ctx); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{comment.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (cq *CommentQuery) FirstIDX(ctx context.Context) int64 { - id, err := cq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single Comment entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one Comment entity is not found. -// Returns a *NotFoundError when no Comment entities are found. -func (cq *CommentQuery) Only(ctx context.Context) (*Comment, error) { - nodes, err := cq.Limit(2).All(ctx) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{comment.Label} - default: - return nil, &NotSingularError{comment.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (cq *CommentQuery) OnlyX(ctx context.Context) *Comment { - node, err := cq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only Comment ID in the query. -// Returns a *NotSingularError when exactly one Comment ID is not found. -// Returns a *NotFoundError when no entities are found. -func (cq *CommentQuery) OnlyID(ctx context.Context) (id int64, err error) { - var ids []int64 - if ids, err = cq.Limit(2).IDs(ctx); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{comment.Label} - default: - err = &NotSingularError{comment.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (cq *CommentQuery) OnlyIDX(ctx context.Context) int64 { - id, err := cq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of Comments. -func (cq *CommentQuery) All(ctx context.Context) ([]*Comment, error) { - if err := cq.prepareQuery(ctx); err != nil { - return nil, err - } - return cq.sqlAll(ctx) -} - -// AllX is like All, but panics if an error occurs. -func (cq *CommentQuery) AllX(ctx context.Context) []*Comment { - nodes, err := cq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of Comment IDs. -func (cq *CommentQuery) IDs(ctx context.Context) ([]int64, error) { - var ids []int64 - if err := cq.Select(comment.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (cq *CommentQuery) IDsX(ctx context.Context) []int64 { - ids, err := cq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (cq *CommentQuery) Count(ctx context.Context) (int, error) { - if err := cq.prepareQuery(ctx); err != nil { - return 0, err - } - return cq.sqlCount(ctx) -} - -// CountX is like Count, but panics if an error occurs. -func (cq *CommentQuery) CountX(ctx context.Context) int { - count, err := cq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (cq *CommentQuery) Exist(ctx context.Context) (bool, error) { - if err := cq.prepareQuery(ctx); err != nil { - return false, err - } - return cq.sqlExist(ctx) -} - -// ExistX is like Exist, but panics if an error occurs. -func (cq *CommentQuery) ExistX(ctx context.Context) bool { - exist, err := cq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the CommentQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (cq *CommentQuery) Clone() *CommentQuery { - if cq == nil { - return nil - } - return &CommentQuery{ - config: cq.config, - limit: cq.limit, - offset: cq.offset, - order: append([]OrderFunc{}, cq.order...), - predicates: append([]predicate.Comment{}, cq.predicates...), - withPost: cq.withPost.Clone(), - // clone intermediate query. - sql: cq.sql.Clone(), - path: cq.path, - } -} - -// WithPost tells the query-builder to eager-load the nodes that are connected to -// the "post" edge. The optional arguments are used to configure the query builder of the edge. -func (cq *CommentQuery) WithPost(opts ...func(*ArticleQuery)) *CommentQuery { - query := &ArticleQuery{config: cq.config} - for _, opt := range opts { - opt(query) - } - cq.withPost = query - return cq -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// Name string `json:"name,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.Comment.Query(). -// GroupBy(comment.FieldName). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -// -func (cq *CommentQuery) GroupBy(field string, fields ...string) *CommentGroupBy { - group := &CommentGroupBy{config: cq.config} - group.fields = append([]string{field}, fields...) - group.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := cq.prepareQuery(ctx); err != nil { - return nil, err - } - return cq.sqlQuery(ctx), nil - } - return group -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// Name string `json:"name,omitempty"` -// } -// -// client.Comment.Query(). -// Select(comment.FieldName). -// Scan(ctx, &v) -// -func (cq *CommentQuery) Select(field string, fields ...string) *CommentSelect { - cq.fields = append([]string{field}, fields...) - return &CommentSelect{CommentQuery: cq} -} - -func (cq *CommentQuery) prepareQuery(ctx context.Context) error { - for _, f := range cq.fields { - if !comment.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if cq.path != nil { - prev, err := cq.path(ctx) - if err != nil { - return err - } - cq.sql = prev - } - return nil -} - -func (cq *CommentQuery) sqlAll(ctx context.Context) ([]*Comment, error) { - var ( - nodes = []*Comment{} - withFKs = cq.withFKs - _spec = cq.querySpec() - loadedTypes = [1]bool{ - cq.withPost != nil, - } - ) - if cq.withPost != nil { - withFKs = true - } - if withFKs { - _spec.Node.Columns = append(_spec.Node.Columns, comment.ForeignKeys...) - } - _spec.ScanValues = func(columns []string) ([]interface{}, error) { - node := &Comment{config: cq.config} - nodes = append(nodes, node) - return node.scanValues(columns) - } - _spec.Assign = func(columns []string, values []interface{}) error { - if len(nodes) == 0 { - return fmt.Errorf("ent: Assign called without calling ScanValues") - } - node := nodes[len(nodes)-1] - node.Edges.loadedTypes = loadedTypes - return node.assignValues(columns, values) - } - if err := sqlgraph.QueryNodes(ctx, cq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - - if query := cq.withPost; query != nil { - ids := make([]int64, 0, len(nodes)) - nodeids := make(map[int64][]*Comment) - for i := range nodes { - if fk := nodes[i].article_comments; fk != nil { - ids = append(ids, *fk) - nodeids[*fk] = append(nodeids[*fk], nodes[i]) - } - } - query.Where(article.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { - return nil, err - } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "article_comments" returned %v`, n.ID) - } - for i := range nodes { - nodes[i].Edges.Post = n - } - } - } - - return nodes, nil -} - -func (cq *CommentQuery) sqlCount(ctx context.Context) (int, error) { - _spec := cq.querySpec() - return sqlgraph.CountNodes(ctx, cq.driver, _spec) -} - -func (cq *CommentQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := cq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("ent: check existence: %v", err) - } - return n > 0, nil -} - -func (cq *CommentQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: comment.Table, - Columns: comment.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - }, - From: cq.sql, - Unique: true, - } - if fields := cq.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, comment.FieldID) - for i := range fields { - if fields[i] != comment.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := cq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := cq.limit; limit != nil { - _spec.Limit = *limit - } - if offset := cq.offset; offset != nil { - _spec.Offset = *offset - } - if ps := cq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector, comment.ValidColumn) - } - } - } - return _spec -} - -func (cq *CommentQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(cq.driver.Dialect()) - t1 := builder.Table(comment.Table) - selector := builder.Select(t1.Columns(comment.Columns...)...).From(t1) - if cq.sql != nil { - selector = cq.sql - selector.Select(selector.Columns(comment.Columns...)...) - } - for _, p := range cq.predicates { - p(selector) - } - for _, p := range cq.order { - p(selector, comment.ValidColumn) - } - if offset := cq.offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := cq.limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// CommentGroupBy is the group-by builder for Comment entities. -type CommentGroupBy struct { - config - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (cgb *CommentGroupBy) Aggregate(fns ...AggregateFunc) *CommentGroupBy { - cgb.fns = append(cgb.fns, fns...) - return cgb -} - -// Scan applies the group-by query and scans the result into the given value. -func (cgb *CommentGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := cgb.path(ctx) - if err != nil { - return err - } - cgb.sql = query - return cgb.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (cgb *CommentGroupBy) ScanX(ctx context.Context, v interface{}) { - if err := cgb.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CommentGroupBy) Strings(ctx context.Context) ([]string, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CommentGroupBy.Strings is not achievable when grouping more than 1 field") - } - var v []string - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (cgb *CommentGroupBy) StringsX(ctx context.Context) []string { - v, err := cgb.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CommentGroupBy) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = cgb.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{comment.Label} - default: - err = fmt.Errorf("ent: CommentGroupBy.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (cgb *CommentGroupBy) StringX(ctx context.Context) string { - v, err := cgb.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CommentGroupBy) Ints(ctx context.Context) ([]int, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CommentGroupBy.Ints is not achievable when grouping more than 1 field") - } - var v []int - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (cgb *CommentGroupBy) IntsX(ctx context.Context) []int { - v, err := cgb.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CommentGroupBy) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = cgb.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{comment.Label} - default: - err = fmt.Errorf("ent: CommentGroupBy.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (cgb *CommentGroupBy) IntX(ctx context.Context) int { - v, err := cgb.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CommentGroupBy) Float64s(ctx context.Context) ([]float64, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CommentGroupBy.Float64s is not achievable when grouping more than 1 field") - } - var v []float64 - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (cgb *CommentGroupBy) Float64sX(ctx context.Context) []float64 { - v, err := cgb.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CommentGroupBy) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = cgb.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{comment.Label} - default: - err = fmt.Errorf("ent: CommentGroupBy.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (cgb *CommentGroupBy) Float64X(ctx context.Context) float64 { - v, err := cgb.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CommentGroupBy) Bools(ctx context.Context) ([]bool, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CommentGroupBy.Bools is not achievable when grouping more than 1 field") - } - var v []bool - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (cgb *CommentGroupBy) BoolsX(ctx context.Context) []bool { - v, err := cgb.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CommentGroupBy) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = cgb.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{comment.Label} - default: - err = fmt.Errorf("ent: CommentGroupBy.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (cgb *CommentGroupBy) BoolX(ctx context.Context) bool { - v, err := cgb.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (cgb *CommentGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range cgb.fields { - if !comment.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := cgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := cgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (cgb *CommentGroupBy) sqlQuery() *sql.Selector { - selector := cgb.sql - columns := make([]string, 0, len(cgb.fields)+len(cgb.fns)) - columns = append(columns, cgb.fields...) - for _, fn := range cgb.fns { - columns = append(columns, fn(selector, comment.ValidColumn)) - } - return selector.Select(columns...).GroupBy(cgb.fields...) -} - -// CommentSelect is the builder for selecting fields of Comment entities. -type CommentSelect struct { - *CommentQuery - // intermediate query (i.e. traversal path). - sql *sql.Selector -} - -// Scan applies the selector query and scans the result into the given value. -func (cs *CommentSelect) Scan(ctx context.Context, v interface{}) error { - if err := cs.prepareQuery(ctx); err != nil { - return err - } - cs.sql = cs.CommentQuery.sqlQuery(ctx) - return cs.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (cs *CommentSelect) ScanX(ctx context.Context, v interface{}) { - if err := cs.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from a selector. It is only allowed when selecting one field. -func (cs *CommentSelect) Strings(ctx context.Context) ([]string, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CommentSelect.Strings is not achievable when selecting more than 1 field") - } - var v []string - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (cs *CommentSelect) StringsX(ctx context.Context) []string { - v, err := cs.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a selector. It is only allowed when selecting one field. -func (cs *CommentSelect) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = cs.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{comment.Label} - default: - err = fmt.Errorf("ent: CommentSelect.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (cs *CommentSelect) StringX(ctx context.Context) string { - v, err := cs.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from a selector. It is only allowed when selecting one field. -func (cs *CommentSelect) Ints(ctx context.Context) ([]int, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CommentSelect.Ints is not achievable when selecting more than 1 field") - } - var v []int - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (cs *CommentSelect) IntsX(ctx context.Context) []int { - v, err := cs.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a selector. It is only allowed when selecting one field. -func (cs *CommentSelect) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = cs.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{comment.Label} - default: - err = fmt.Errorf("ent: CommentSelect.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (cs *CommentSelect) IntX(ctx context.Context) int { - v, err := cs.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. -func (cs *CommentSelect) Float64s(ctx context.Context) ([]float64, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CommentSelect.Float64s is not achievable when selecting more than 1 field") - } - var v []float64 - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (cs *CommentSelect) Float64sX(ctx context.Context) []float64 { - v, err := cs.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. -func (cs *CommentSelect) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = cs.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{comment.Label} - default: - err = fmt.Errorf("ent: CommentSelect.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (cs *CommentSelect) Float64X(ctx context.Context) float64 { - v, err := cs.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from a selector. It is only allowed when selecting one field. -func (cs *CommentSelect) Bools(ctx context.Context) ([]bool, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CommentSelect.Bools is not achievable when selecting more than 1 field") - } - var v []bool - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (cs *CommentSelect) BoolsX(ctx context.Context) []bool { - v, err := cs.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a selector. It is only allowed when selecting one field. -func (cs *CommentSelect) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = cs.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{comment.Label} - default: - err = fmt.Errorf("ent: CommentSelect.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (cs *CommentSelect) BoolX(ctx context.Context) bool { - v, err := cs.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (cs *CommentSelect) sqlScan(ctx context.Context, v interface{}) error { - rows := &sql.Rows{} - query, args := cs.sqlQuery().Query() - if err := cs.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (cs *CommentSelect) sqlQuery() sql.Querier { - selector := cs.sql - selector.Select(selector.Columns(cs.fields...)...) - return selector -} diff --git a/examples/blog/internal/data/ent/comment_update.go b/examples/blog/internal/data/ent/comment_update.go deleted file mode 100644 index 968d7eb4b..000000000 --- a/examples/blog/internal/data/ent/comment_update.go +++ /dev/null @@ -1,470 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" -) - -// CommentUpdate is the builder for updating Comment entities. -type CommentUpdate struct { - config - hooks []Hook - mutation *CommentMutation -} - -// Where adds a new predicate for the CommentUpdate builder. -func (cu *CommentUpdate) Where(ps ...predicate.Comment) *CommentUpdate { - cu.mutation.predicates = append(cu.mutation.predicates, ps...) - return cu -} - -// SetName sets the "name" field. -func (cu *CommentUpdate) SetName(s string) *CommentUpdate { - cu.mutation.SetName(s) - return cu -} - -// SetContent sets the "content" field. -func (cu *CommentUpdate) SetContent(s string) *CommentUpdate { - cu.mutation.SetContent(s) - return cu -} - -// SetCreatedAt sets the "created_at" field. -func (cu *CommentUpdate) SetCreatedAt(t time.Time) *CommentUpdate { - cu.mutation.SetCreatedAt(t) - return cu -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (cu *CommentUpdate) SetNillableCreatedAt(t *time.Time) *CommentUpdate { - if t != nil { - cu.SetCreatedAt(*t) - } - return cu -} - -// SetUpdatedAt sets the "updated_at" field. -func (cu *CommentUpdate) SetUpdatedAt(t time.Time) *CommentUpdate { - cu.mutation.SetUpdatedAt(t) - return cu -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (cu *CommentUpdate) SetNillableUpdatedAt(t *time.Time) *CommentUpdate { - if t != nil { - cu.SetUpdatedAt(*t) - } - return cu -} - -// SetPostID sets the "post" edge to the Article entity by ID. -func (cu *CommentUpdate) SetPostID(id int64) *CommentUpdate { - cu.mutation.SetPostID(id) - return cu -} - -// SetNillablePostID sets the "post" edge to the Article entity by ID if the given value is not nil. -func (cu *CommentUpdate) SetNillablePostID(id *int64) *CommentUpdate { - if id != nil { - cu = cu.SetPostID(*id) - } - return cu -} - -// SetPost sets the "post" edge to the Article entity. -func (cu *CommentUpdate) SetPost(a *Article) *CommentUpdate { - return cu.SetPostID(a.ID) -} - -// Mutation returns the CommentMutation object of the builder. -func (cu *CommentUpdate) Mutation() *CommentMutation { - return cu.mutation -} - -// ClearPost clears the "post" edge to the Article entity. -func (cu *CommentUpdate) ClearPost() *CommentUpdate { - cu.mutation.ClearPost() - return cu -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (cu *CommentUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(cu.hooks) == 0 { - affected, err = cu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CommentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - cu.mutation = mutation - affected, err = cu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(cu.hooks) - 1; i >= 0; i-- { - mut = cu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cu.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// SaveX is like Save, but panics if an error occurs. -func (cu *CommentUpdate) SaveX(ctx context.Context) int { - affected, err := cu.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (cu *CommentUpdate) Exec(ctx context.Context) error { - _, err := cu.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (cu *CommentUpdate) ExecX(ctx context.Context) { - if err := cu.Exec(ctx); err != nil { - panic(err) - } -} - -func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: comment.Table, - Columns: comment.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - }, - } - if ps := cu.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := cu.mutation.Name(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: comment.FieldName, - }) - } - if value, ok := cu.mutation.Content(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: comment.FieldContent, - }) - } - if value, ok := cu.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: comment.FieldCreatedAt, - }) - } - if value, ok := cu.mutation.UpdatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: comment.FieldUpdatedAt, - }) - } - if cu.mutation.PostCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: comment.PostTable, - Columns: []string{comment.PostColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := cu.mutation.PostIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: comment.PostTable, - Columns: []string{comment.PostColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{comment.Label} - } else if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - return 0, err - } - return n, nil -} - -// CommentUpdateOne is the builder for updating a single Comment entity. -type CommentUpdateOne struct { - config - hooks []Hook - mutation *CommentMutation -} - -// SetName sets the "name" field. -func (cuo *CommentUpdateOne) SetName(s string) *CommentUpdateOne { - cuo.mutation.SetName(s) - return cuo -} - -// SetContent sets the "content" field. -func (cuo *CommentUpdateOne) SetContent(s string) *CommentUpdateOne { - cuo.mutation.SetContent(s) - return cuo -} - -// SetCreatedAt sets the "created_at" field. -func (cuo *CommentUpdateOne) SetCreatedAt(t time.Time) *CommentUpdateOne { - cuo.mutation.SetCreatedAt(t) - return cuo -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (cuo *CommentUpdateOne) SetNillableCreatedAt(t *time.Time) *CommentUpdateOne { - if t != nil { - cuo.SetCreatedAt(*t) - } - return cuo -} - -// SetUpdatedAt sets the "updated_at" field. -func (cuo *CommentUpdateOne) SetUpdatedAt(t time.Time) *CommentUpdateOne { - cuo.mutation.SetUpdatedAt(t) - return cuo -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (cuo *CommentUpdateOne) SetNillableUpdatedAt(t *time.Time) *CommentUpdateOne { - if t != nil { - cuo.SetUpdatedAt(*t) - } - return cuo -} - -// SetPostID sets the "post" edge to the Article entity by ID. -func (cuo *CommentUpdateOne) SetPostID(id int64) *CommentUpdateOne { - cuo.mutation.SetPostID(id) - return cuo -} - -// SetNillablePostID sets the "post" edge to the Article entity by ID if the given value is not nil. -func (cuo *CommentUpdateOne) SetNillablePostID(id *int64) *CommentUpdateOne { - if id != nil { - cuo = cuo.SetPostID(*id) - } - return cuo -} - -// SetPost sets the "post" edge to the Article entity. -func (cuo *CommentUpdateOne) SetPost(a *Article) *CommentUpdateOne { - return cuo.SetPostID(a.ID) -} - -// Mutation returns the CommentMutation object of the builder. -func (cuo *CommentUpdateOne) Mutation() *CommentMutation { - return cuo.mutation -} - -// ClearPost clears the "post" edge to the Article entity. -func (cuo *CommentUpdateOne) ClearPost() *CommentUpdateOne { - cuo.mutation.ClearPost() - return cuo -} - -// Save executes the query and returns the updated Comment entity. -func (cuo *CommentUpdateOne) Save(ctx context.Context) (*Comment, error) { - var ( - err error - node *Comment - ) - if len(cuo.hooks) == 0 { - node, err = cuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CommentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - cuo.mutation = mutation - node, err = cuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(cuo.hooks) - 1; i >= 0; i-- { - mut = cuo.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cuo.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX is like Save, but panics if an error occurs. -func (cuo *CommentUpdateOne) SaveX(ctx context.Context) *Comment { - node, err := cuo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (cuo *CommentUpdateOne) Exec(ctx context.Context) error { - _, err := cuo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (cuo *CommentUpdateOne) ExecX(ctx context.Context) { - if err := cuo.Exec(ctx); err != nil { - panic(err) - } -} - -func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: comment.Table, - Columns: comment.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: comment.FieldID, - }, - }, - } - id, ok := cuo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Comment.ID for update")} - } - _spec.Node.ID.Value = id - if ps := cuo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := cuo.mutation.Name(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: comment.FieldName, - }) - } - if value, ok := cuo.mutation.Content(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: comment.FieldContent, - }) - } - if value, ok := cuo.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: comment.FieldCreatedAt, - }) - } - if value, ok := cuo.mutation.UpdatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: comment.FieldUpdatedAt, - }) - } - if cuo.mutation.PostCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: comment.PostTable, - Columns: []string{comment.PostColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := cuo.mutation.PostIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: comment.PostTable, - Columns: []string{comment.PostColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - _node = &Comment{config: cuo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{comment.Label} - } else if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - return nil, err - } - return _node, nil -} diff --git a/examples/blog/internal/data/ent/config.go b/examples/blog/internal/data/ent/config.go deleted file mode 100644 index 5de3f7312..000000000 --- a/examples/blog/internal/data/ent/config.go +++ /dev/null @@ -1,61 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...interface{}) - // hooks to execute on mutations. - hooks *hooks -} - -// hooks per client, for fast access. -type hooks struct { - Article []ent.Hook - Comment []ent.Hook - Tag []ent.Hook -} - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...interface{})) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/blog/internal/data/ent/context.go b/examples/blog/internal/data/ent/context.go deleted file mode 100644 index 08407261b..000000000 --- a/examples/blog/internal/data/ent/context.go +++ /dev/null @@ -1,33 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" -) - -type clientCtxKey struct{} - -// FromContext returns a Client stored inside a context, or nil if there isn't one. -func FromContext(ctx context.Context) *Client { - c, _ := ctx.Value(clientCtxKey{}).(*Client) - return c -} - -// NewContext returns a new context with the given Client attached. -func NewContext(parent context.Context, c *Client) context.Context { - return context.WithValue(parent, clientCtxKey{}, c) -} - -type txCtxKey struct{} - -// TxFromContext returns a Tx stored inside a context, or nil if there isn't one. -func TxFromContext(ctx context.Context) *Tx { - tx, _ := ctx.Value(txCtxKey{}).(*Tx) - return tx -} - -// NewTxContext returns a new context with the given Tx attached. -func NewTxContext(parent context.Context, tx *Tx) context.Context { - return context.WithValue(parent, txCtxKey{}, tx) -} diff --git a/examples/blog/internal/data/ent/ent.go b/examples/blog/internal/data/ent/ent.go deleted file mode 100644 index e1f1aa0b4..000000000 --- a/examples/blog/internal/data/ent/ent.go +++ /dev/null @@ -1,270 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "errors" - "fmt" - "strings" - - "entgo.io/ent" - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" -) - -// ent aliases to avoid import conflicts in user's code. -type ( - Op = ent.Op - Hook = ent.Hook - Value = ent.Value - Query = ent.Query - Policy = ent.Policy - Mutator = ent.Mutator - Mutation = ent.Mutation - MutateFunc = ent.MutateFunc -) - -// OrderFunc applies an ordering on the sql selector. -type OrderFunc func(*sql.Selector, func(string) bool) - -// Asc applies the given fields in ASC order. -func Asc(fields ...string) OrderFunc { - return func(s *sql.Selector, check func(string) bool) { - for _, f := range fields { - if check(f) { - s.OrderBy(sql.Asc(f)) - } else { - s.AddError(&ValidationError{Name: f, err: fmt.Errorf("invalid field %q for ordering", f)}) - } - } - } -} - -// Desc applies the given fields in DESC order. -func Desc(fields ...string) OrderFunc { - return func(s *sql.Selector, check func(string) bool) { - for _, f := range fields { - if check(f) { - s.OrderBy(sql.Desc(f)) - } else { - s.AddError(&ValidationError{Name: f, err: fmt.Errorf("invalid field %q for ordering", f)}) - } - } - } -} - -// AggregateFunc applies an aggregation step on the group-by traversal/selector. -type AggregateFunc func(*sql.Selector, func(string) bool) string - -// As is a pseudo aggregation function for renaming another other functions with custom names. For example: -// -// GroupBy(field1, field2). -// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")). -// Scan(ctx, &v) -// -func As(fn AggregateFunc, end string) AggregateFunc { - return func(s *sql.Selector, check func(string) bool) string { - return sql.As(fn(s, check), end) - } -} - -// Count applies the "count" aggregation function on each group. -func Count() AggregateFunc { - return func(s *sql.Selector, _ func(string) bool) string { - return sql.Count("*") - } -} - -// Max applies the "max" aggregation function on the given field of each group. -func Max(field string) AggregateFunc { - return func(s *sql.Selector, check func(string) bool) string { - if !check(field) { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)}) - return "" - } - return sql.Max(s.C(field)) - } -} - -// Mean applies the "mean" aggregation function on the given field of each group. -func Mean(field string) AggregateFunc { - return func(s *sql.Selector, check func(string) bool) string { - if !check(field) { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)}) - return "" - } - return sql.Avg(s.C(field)) - } -} - -// Min applies the "min" aggregation function on the given field of each group. -func Min(field string) AggregateFunc { - return func(s *sql.Selector, check func(string) bool) string { - if !check(field) { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)}) - return "" - } - return sql.Min(s.C(field)) - } -} - -// Sum applies the "sum" aggregation function on the given field of each group. -func Sum(field string) AggregateFunc { - return func(s *sql.Selector, check func(string) bool) string { - if !check(field) { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)}) - return "" - } - return sql.Sum(s.C(field)) - } -} - -// ValidationError returns when validating a field fails. -type ValidationError struct { - Name string // Field or edge name. - err error -} - -// Error implements the error interface. -func (e *ValidationError) Error() string { - return e.err.Error() -} - -// Unwrap implements the errors.Wrapper interface. -func (e *ValidationError) Unwrap() error { - return e.err -} - -// IsValidationError returns a boolean indicating whether the error is a validaton error. -func IsValidationError(err error) bool { - if err == nil { - return false - } - var e *ValidationError - return errors.As(err, &e) -} - -// NotFoundError returns when trying to fetch a specific entity and it was not found in the database. -type NotFoundError struct { - label string -} - -// Error implements the error interface. -func (e *NotFoundError) Error() string { - return "ent: " + e.label + " not found" -} - -// IsNotFound returns a boolean indicating whether the error is a not found error. -func IsNotFound(err error) bool { - if err == nil { - return false - } - var e *NotFoundError - return errors.As(err, &e) -} - -// MaskNotFound masks not found error. -func MaskNotFound(err error) error { - if IsNotFound(err) { - return nil - } - return err -} - -// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database. -type NotSingularError struct { - label string -} - -// Error implements the error interface. -func (e *NotSingularError) Error() string { - return "ent: " + e.label + " not singular" -} - -// IsNotSingular returns a boolean indicating whether the error is a not singular error. -func IsNotSingular(err error) bool { - if err == nil { - return false - } - var e *NotSingularError - return errors.As(err, &e) -} - -// NotLoadedError returns when trying to get a node that was not loaded by the query. -type NotLoadedError struct { - edge string -} - -// Error implements the error interface. -func (e *NotLoadedError) Error() string { - return "ent: " + e.edge + " edge was not loaded" -} - -// IsNotLoaded returns a boolean indicating whether the error is a not loaded error. -func IsNotLoaded(err error) bool { - if err == nil { - return false - } - var e *NotLoadedError - return errors.As(err, &e) -} - -// ConstraintError returns when trying to create/update one or more entities and -// one or more of their constraints failed. For example, violation of edge or -// field uniqueness. -type ConstraintError struct { - msg string - wrap error -} - -// Error implements the error interface. -func (e ConstraintError) Error() string { - return "ent: constraint failed: " + e.msg -} - -// Unwrap implements the errors.Wrapper interface. -func (e *ConstraintError) Unwrap() error { - return e.wrap -} - -// IsConstraintError returns a boolean indicating whether the error is a constraint failure. -func IsConstraintError(err error) bool { - if err == nil { - return false - } - var e *ConstraintError - return errors.As(err, &e) -} - -func isSQLConstraintError(err error) (*ConstraintError, bool) { - var ( - msg = err.Error() - // error format per dialect. - errors = [...]string{ - "Error 1062", // MySQL 1062 error (ER_DUP_ENTRY). - "UNIQUE constraint failed", // SQLite. - "duplicate key value violates unique constraint", // PostgreSQL. - } - ) - if _, ok := err.(*sqlgraph.ConstraintError); ok { - return &ConstraintError{msg, err}, true - } - for i := range errors { - if strings.Contains(msg, errors[i]) { - return &ConstraintError{msg, err}, true - } - } - return nil, false -} - -// rollback calls tx.Rollback and wraps the given error with the rollback error if present. -func rollback(tx dialect.Tx, err error) error { - if rerr := tx.Rollback(); rerr != nil { - err = fmt.Errorf("%s: %v", err.Error(), rerr) - } - if err, ok := isSQLConstraintError(err); ok { - return err - } - return err -} diff --git a/examples/blog/internal/data/ent/enttest/enttest.go b/examples/blog/internal/data/ent/enttest/enttest.go deleted file mode 100644 index aeb991cb4..000000000 --- a/examples/blog/internal/data/ent/enttest/enttest.go +++ /dev/null @@ -1,78 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package enttest - -import ( - "context" - - "github.com/go-kratos/kratos/examples/blog/internal/data/ent" - // required by schema hooks. - _ "github.com/go-kratos/kratos/examples/blog/internal/data/ent/runtime" - - "entgo.io/ent/dialect/sql/schema" -) - -type ( - // TestingT is the interface that is shared between - // testing.T and testing.B and used by enttest. - TestingT interface { - FailNow() - Error(...interface{}) - } - - // Option configures client creation. - Option func(*options) - - options struct { - opts []ent.Option - migrateOpts []schema.MigrateOption - } -) - -// WithOptions forwards options to client creation. -func WithOptions(opts ...ent.Option) Option { - return func(o *options) { - o.opts = append(o.opts, opts...) - } -} - -// WithMigrateOptions forwards options to auto migration. -func WithMigrateOptions(opts ...schema.MigrateOption) Option { - return func(o *options) { - o.migrateOpts = append(o.migrateOpts, opts...) - } -} - -func newOptions(opts []Option) *options { - o := &options{} - for _, opt := range opts { - opt(o) - } - return o -} - -// Open calls ent.Open and auto-run migration. -func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client { - o := newOptions(opts) - c, err := ent.Open(driverName, dataSourceName, o.opts...) - if err != nil { - t.Error(err) - t.FailNow() - } - if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { - t.Error(err) - t.FailNow() - } - return c -} - -// NewClient calls ent.NewClient and auto-run migration. -func NewClient(t TestingT, opts ...Option) *ent.Client { - o := newOptions(opts) - c := ent.NewClient(o.opts...) - if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { - t.Error(err) - t.FailNow() - } - return c -} diff --git a/examples/blog/internal/data/ent/hook/hook.go b/examples/blog/internal/data/ent/hook/hook.go deleted file mode 100644 index 91272a4a1..000000000 --- a/examples/blog/internal/data/ent/hook/hook.go +++ /dev/null @@ -1,230 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package hook - -import ( - "context" - "fmt" - - "github.com/go-kratos/kratos/examples/blog/internal/data/ent" -) - -// The ArticleFunc type is an adapter to allow the use of ordinary -// function as Article mutator. -type ArticleFunc func(context.Context, *ent.ArticleMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f ArticleFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.ArticleMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ArticleMutation", m) - } - return f(ctx, mv) -} - -// The CommentFunc type is an adapter to allow the use of ordinary -// function as Comment mutator. -type CommentFunc func(context.Context, *ent.CommentMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f CommentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.CommentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CommentMutation", m) - } - return f(ctx, mv) -} - -// The TagFunc type is an adapter to allow the use of ordinary -// function as Tag mutator. -type TagFunc func(context.Context, *ent.TagMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f TagFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.TagMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TagMutation", m) - } - return f(ctx, mv) -} - -// Condition is a hook condition function. -type Condition func(context.Context, ent.Mutation) bool - -// And groups conditions with the AND operator. -func And(first, second Condition, rest ...Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - if !first(ctx, m) || !second(ctx, m) { - return false - } - for _, cond := range rest { - if !cond(ctx, m) { - return false - } - } - return true - } -} - -// Or groups conditions with the OR operator. -func Or(first, second Condition, rest ...Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - if first(ctx, m) || second(ctx, m) { - return true - } - for _, cond := range rest { - if cond(ctx, m) { - return true - } - } - return false - } -} - -// Not negates a given condition. -func Not(cond Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - return !cond(ctx, m) - } -} - -// HasOp is a condition testing mutation operation. -func HasOp(op ent.Op) Condition { - return func(_ context.Context, m ent.Mutation) bool { - return m.Op().Is(op) - } -} - -// HasAddedFields is a condition validating `.AddedField` on fields. -func HasAddedFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if _, exists := m.AddedField(field); !exists { - return false - } - for _, field := range fields { - if _, exists := m.AddedField(field); !exists { - return false - } - } - return true - } -} - -// HasClearedFields is a condition validating `.FieldCleared` on fields. -func HasClearedFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if exists := m.FieldCleared(field); !exists { - return false - } - for _, field := range fields { - if exists := m.FieldCleared(field); !exists { - return false - } - } - return true - } -} - -// HasFields is a condition validating `.Field` on fields. -func HasFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if _, exists := m.Field(field); !exists { - return false - } - for _, field := range fields { - if _, exists := m.Field(field); !exists { - return false - } - } - return true - } -} - -// If executes the given hook under condition. -// -// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...))) -// -func If(hk ent.Hook, cond Condition) ent.Hook { - return func(next ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if cond(ctx, m) { - return hk(next).Mutate(ctx, m) - } - return next.Mutate(ctx, m) - }) - } -} - -// On executes the given hook only for the given operation. -// -// hook.On(Log, ent.Delete|ent.Create) -// -func On(hk ent.Hook, op ent.Op) ent.Hook { - return If(hk, HasOp(op)) -} - -// Unless skips the given hook only for the given operation. -// -// hook.Unless(Log, ent.Update|ent.UpdateOne) -// -func Unless(hk ent.Hook, op ent.Op) ent.Hook { - return If(hk, Not(HasOp(op))) -} - -// FixedError is a hook returning a fixed error. -func FixedError(err error) ent.Hook { - return func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { - return nil, err - }) - } -} - -// Reject returns a hook that rejects all operations that match op. -// -// func (T) Hooks() []ent.Hook { -// return []ent.Hook{ -// Reject(ent.Delete|ent.Update), -// } -// } -// -func Reject(op ent.Op) ent.Hook { - hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) - return On(hk, op) -} - -// Chain acts as a list of hooks and is effectively immutable. -// Once created, it will always hold the same set of hooks in the same order. -type Chain struct { - hooks []ent.Hook -} - -// NewChain creates a new chain of hooks. -func NewChain(hooks ...ent.Hook) Chain { - return Chain{append([]ent.Hook(nil), hooks...)} -} - -// Hook chains the list of hooks and returns the final hook. -func (c Chain) Hook() ent.Hook { - return func(mutator ent.Mutator) ent.Mutator { - for i := len(c.hooks) - 1; i >= 0; i-- { - mutator = c.hooks[i](mutator) - } - return mutator - } -} - -// Append extends a chain, adding the specified hook -// as the last ones in the mutation flow. -func (c Chain) Append(hooks ...ent.Hook) Chain { - newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks)) - newHooks = append(newHooks, c.hooks...) - newHooks = append(newHooks, hooks...) - return Chain{newHooks} -} - -// Extend extends a chain, adding the specified chain -// as the last ones in the mutation flow. -func (c Chain) Extend(chain Chain) Chain { - return c.Append(chain.hooks...) -} diff --git a/examples/blog/internal/data/ent/migrate/migrate.go b/examples/blog/internal/data/ent/migrate/migrate.go deleted file mode 100644 index 0ce6a6e9a..000000000 --- a/examples/blog/internal/data/ent/migrate/migrate.go +++ /dev/null @@ -1,72 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package migrate - -import ( - "context" - "fmt" - "io" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql/schema" -) - -var ( - // WithGlobalUniqueID sets the universal ids options to the migration. - // If this option is enabled, ent migration will allocate a 1<<32 range - // for the ids of each entity (table). - // Note that this option cannot be applied on tables that already exist. - WithGlobalUniqueID = schema.WithGlobalUniqueID - // WithDropColumn sets the drop column option to the migration. - // If this option is enabled, ent migration will drop old columns - // that were used for both fields and edges. This defaults to false. - WithDropColumn = schema.WithDropColumn - // WithDropIndex sets the drop index option to the migration. - // If this option is enabled, ent migration will drop old indexes - // that were defined in the schema. This defaults to false. - // Note that unique constraints are defined using `UNIQUE INDEX`, - // and therefore, it's recommended to enable this option to get more - // flexibility in the schema changes. - WithDropIndex = schema.WithDropIndex - // WithFixture sets the foreign-key renaming option to the migration when upgrading - // ent from v0.1.0 (issue-#285). Defaults to false. - WithFixture = schema.WithFixture - // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. - WithForeignKeys = schema.WithForeignKeys -) - -// Schema is the API for creating, migrating and dropping a schema. -type Schema struct { - drv dialect.Driver - universalID bool -} - -// NewSchema creates a new schema client. -func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } - -// Create creates all schema resources. -func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { - migrate, err := schema.NewMigrate(s.drv, opts...) - if err != nil { - return fmt.Errorf("ent/migrate: %v", err) - } - return migrate.Create(ctx, Tables...) -} - -// WriteTo writes the schema changes to w instead of running them against the database. -// -// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil { -// log.Fatal(err) -// } -// -func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { - drv := &schema.WriteDriver{ - Writer: w, - Driver: s.drv, - } - migrate, err := schema.NewMigrate(drv, opts...) - if err != nil { - return fmt.Errorf("ent/migrate: %v", err) - } - return migrate.Create(ctx, Tables...) -} diff --git a/examples/blog/internal/data/ent/migrate/schema.go b/examples/blog/internal/data/ent/migrate/schema.go deleted file mode 100644 index ad644f6d5..000000000 --- a/examples/blog/internal/data/ent/migrate/schema.go +++ /dev/null @@ -1,105 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package migrate - -import ( - "entgo.io/ent/dialect/sql/schema" - "entgo.io/ent/schema/field" -) - -var ( - // ArticlesColumns holds the columns for the "articles" table. - ArticlesColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt64, Increment: true}, - {Name: "title", Type: field.TypeString}, - {Name: "content", Type: field.TypeString}, - {Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, - {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, - } - // ArticlesTable holds the schema information for the "articles" table. - ArticlesTable = &schema.Table{ - Name: "articles", - Columns: ArticlesColumns, - PrimaryKey: []*schema.Column{ArticlesColumns[0]}, - ForeignKeys: []*schema.ForeignKey{}, - } - // CommentsColumns holds the columns for the "comments" table. - CommentsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt64, Increment: true}, - {Name: "name", Type: field.TypeString}, - {Name: "content", Type: field.TypeString}, - {Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, - {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, - {Name: "article_comments", Type: field.TypeInt64, Nullable: true}, - } - // CommentsTable holds the schema information for the "comments" table. - CommentsTable = &schema.Table{ - Name: "comments", - Columns: CommentsColumns, - PrimaryKey: []*schema.Column{CommentsColumns[0]}, - ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "comments_articles_comments", - Columns: []*schema.Column{CommentsColumns[5]}, - - RefColumns: []*schema.Column{ArticlesColumns[0]}, - OnDelete: schema.SetNull, - }, - }, - } - // TagsColumns holds the columns for the "tags" table. - TagsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt64, Increment: true}, - {Name: "slug", Type: field.TypeString}, - {Name: "name", Type: field.TypeString}, - {Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, - {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, - } - // TagsTable holds the schema information for the "tags" table. - TagsTable = &schema.Table{ - Name: "tags", - Columns: TagsColumns, - PrimaryKey: []*schema.Column{TagsColumns[0]}, - ForeignKeys: []*schema.ForeignKey{}, - } - // TagPostsColumns holds the columns for the "tag_posts" table. - TagPostsColumns = []*schema.Column{ - {Name: "tag_id", Type: field.TypeInt64}, - {Name: "article_id", Type: field.TypeInt64}, - } - // TagPostsTable holds the schema information for the "tag_posts" table. - TagPostsTable = &schema.Table{ - Name: "tag_posts", - Columns: TagPostsColumns, - PrimaryKey: []*schema.Column{TagPostsColumns[0], TagPostsColumns[1]}, - ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "tag_posts_tag_id", - Columns: []*schema.Column{TagPostsColumns[0]}, - - RefColumns: []*schema.Column{TagsColumns[0]}, - OnDelete: schema.Cascade, - }, - { - Symbol: "tag_posts_article_id", - Columns: []*schema.Column{TagPostsColumns[1]}, - - RefColumns: []*schema.Column{ArticlesColumns[0]}, - OnDelete: schema.Cascade, - }, - }, - } - // Tables holds all the tables in the schema. - Tables = []*schema.Table{ - ArticlesTable, - CommentsTable, - TagsTable, - TagPostsTable, - } -) - -func init() { - CommentsTable.ForeignKeys[0].RefTable = ArticlesTable - TagPostsTable.ForeignKeys[0].RefTable = TagsTable - TagPostsTable.ForeignKeys[1].RefTable = ArticlesTable -} diff --git a/examples/blog/internal/data/ent/mutation.go b/examples/blog/internal/data/ent/mutation.go deleted file mode 100644 index a9ead49db..000000000 --- a/examples/blog/internal/data/ent/mutation.go +++ /dev/null @@ -1,1731 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "sync" - "time" - - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" - - "entgo.io/ent" -) - -const ( - // Operation types. - OpCreate = ent.OpCreate - OpDelete = ent.OpDelete - OpDeleteOne = ent.OpDeleteOne - OpUpdate = ent.OpUpdate - OpUpdateOne = ent.OpUpdateOne - - // Node types. - TypeArticle = "Article" - TypeComment = "Comment" - TypeTag = "Tag" -) - -// ArticleMutation represents an operation that mutates the Article nodes in the graph. -type ArticleMutation struct { - config - op Op - typ string - id *int64 - title *string - content *string - created_at *time.Time - updated_at *time.Time - clearedFields map[string]struct{} - comments map[int64]struct{} - removedcomments map[int64]struct{} - clearedcomments bool - tags map[int64]struct{} - removedtags map[int64]struct{} - clearedtags bool - done bool - oldValue func(context.Context) (*Article, error) - predicates []predicate.Article -} - -var _ ent.Mutation = (*ArticleMutation)(nil) - -// articleOption allows management of the mutation configuration using functional options. -type articleOption func(*ArticleMutation) - -// newArticleMutation creates new mutation for the Article entity. -func newArticleMutation(c config, op Op, opts ...articleOption) *ArticleMutation { - m := &ArticleMutation{ - config: c, - op: op, - typ: TypeArticle, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withArticleID sets the ID field of the mutation. -func withArticleID(id int64) articleOption { - return func(m *ArticleMutation) { - var ( - err error - once sync.Once - value *Article - ) - m.oldValue = func(ctx context.Context) (*Article, error) { - once.Do(func() { - if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") - } else { - value, err = m.Client().Article.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withArticle sets the old Article of the mutation. -func withArticle(node *Article) articleOption { - return func(m *ArticleMutation) { - m.oldValue = func(context.Context) (*Article, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m ArticleMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m ArticleMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of Article entities. -func (m *ArticleMutation) SetID(id int64) { - m.id = &id -} - -// ID returns the ID value in the mutation. Note that the ID -// is only available if it was provided to the builder. -func (m *ArticleMutation) ID() (id int64, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// SetTitle sets the "title" field. -func (m *ArticleMutation) SetTitle(s string) { - m.title = &s -} - -// Title returns the value of the "title" field in the mutation. -func (m *ArticleMutation) Title() (r string, exists bool) { - v := m.title - if v == nil { - return - } - return *v, true -} - -// OldTitle returns the old "title" field's value of the Article entity. -// If the Article object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *ArticleMutation) OldTitle(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldTitle is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldTitle requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTitle: %w", err) - } - return oldValue.Title, nil -} - -// ResetTitle resets all changes to the "title" field. -func (m *ArticleMutation) ResetTitle() { - m.title = nil -} - -// SetContent sets the "content" field. -func (m *ArticleMutation) SetContent(s string) { - m.content = &s -} - -// Content returns the value of the "content" field in the mutation. -func (m *ArticleMutation) Content() (r string, exists bool) { - v := m.content - if v == nil { - return - } - return *v, true -} - -// OldContent returns the old "content" field's value of the Article entity. -// If the Article object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *ArticleMutation) OldContent(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldContent is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldContent requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldContent: %w", err) - } - return oldValue.Content, nil -} - -// ResetContent resets all changes to the "content" field. -func (m *ArticleMutation) ResetContent() { - m.content = nil -} - -// SetCreatedAt sets the "created_at" field. -func (m *ArticleMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ArticleMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the Article entity. -// If the Article object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *ArticleMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *ArticleMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *ArticleMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ArticleMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return - } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the Article entity. -// If the Article object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *ArticleMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) - } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ArticleMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// AddCommentIDs adds the "comments" edge to the Comment entity by ids. -func (m *ArticleMutation) AddCommentIDs(ids ...int64) { - if m.comments == nil { - m.comments = make(map[int64]struct{}) - } - for i := range ids { - m.comments[ids[i]] = struct{}{} - } -} - -// ClearComments clears the "comments" edge to the Comment entity. -func (m *ArticleMutation) ClearComments() { - m.clearedcomments = true -} - -// CommentsCleared returns if the "comments" edge to the Comment entity was cleared. -func (m *ArticleMutation) CommentsCleared() bool { - return m.clearedcomments -} - -// RemoveCommentIDs removes the "comments" edge to the Comment entity by IDs. -func (m *ArticleMutation) RemoveCommentIDs(ids ...int64) { - if m.removedcomments == nil { - m.removedcomments = make(map[int64]struct{}) - } - for i := range ids { - m.removedcomments[ids[i]] = struct{}{} - } -} - -// RemovedComments returns the removed IDs of the "comments" edge to the Comment entity. -func (m *ArticleMutation) RemovedCommentsIDs() (ids []int64) { - for id := range m.removedcomments { - ids = append(ids, id) - } - return -} - -// CommentsIDs returns the "comments" edge IDs in the mutation. -func (m *ArticleMutation) CommentsIDs() (ids []int64) { - for id := range m.comments { - ids = append(ids, id) - } - return -} - -// ResetComments resets all changes to the "comments" edge. -func (m *ArticleMutation) ResetComments() { - m.comments = nil - m.clearedcomments = false - m.removedcomments = nil -} - -// AddTagIDs adds the "tags" edge to the Tag entity by ids. -func (m *ArticleMutation) AddTagIDs(ids ...int64) { - if m.tags == nil { - m.tags = make(map[int64]struct{}) - } - for i := range ids { - m.tags[ids[i]] = struct{}{} - } -} - -// ClearTags clears the "tags" edge to the Tag entity. -func (m *ArticleMutation) ClearTags() { - m.clearedtags = true -} - -// TagsCleared returns if the "tags" edge to the Tag entity was cleared. -func (m *ArticleMutation) TagsCleared() bool { - return m.clearedtags -} - -// RemoveTagIDs removes the "tags" edge to the Tag entity by IDs. -func (m *ArticleMutation) RemoveTagIDs(ids ...int64) { - if m.removedtags == nil { - m.removedtags = make(map[int64]struct{}) - } - for i := range ids { - m.removedtags[ids[i]] = struct{}{} - } -} - -// RemovedTags returns the removed IDs of the "tags" edge to the Tag entity. -func (m *ArticleMutation) RemovedTagsIDs() (ids []int64) { - for id := range m.removedtags { - ids = append(ids, id) - } - return -} - -// TagsIDs returns the "tags" edge IDs in the mutation. -func (m *ArticleMutation) TagsIDs() (ids []int64) { - for id := range m.tags { - ids = append(ids, id) - } - return -} - -// ResetTags resets all changes to the "tags" edge. -func (m *ArticleMutation) ResetTags() { - m.tags = nil - m.clearedtags = false - m.removedtags = nil -} - -// Op returns the operation name. -func (m *ArticleMutation) Op() Op { - return m.op -} - -// Type returns the node type of this mutation (Article). -func (m *ArticleMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *ArticleMutation) Fields() []string { - fields := make([]string, 0, 4) - if m.title != nil { - fields = append(fields, article.FieldTitle) - } - if m.content != nil { - fields = append(fields, article.FieldContent) - } - if m.created_at != nil { - fields = append(fields, article.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, article.FieldUpdatedAt) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *ArticleMutation) Field(name string) (ent.Value, bool) { - switch name { - case article.FieldTitle: - return m.Title() - case article.FieldContent: - return m.Content() - case article.FieldCreatedAt: - return m.CreatedAt() - case article.FieldUpdatedAt: - return m.UpdatedAt() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *ArticleMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case article.FieldTitle: - return m.OldTitle(ctx) - case article.FieldContent: - return m.OldContent(ctx) - case article.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case article.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - } - return nil, fmt.Errorf("unknown Article field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *ArticleMutation) SetField(name string, value ent.Value) error { - switch name { - case article.FieldTitle: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTitle(v) - return nil - case article.FieldContent: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetContent(v) - return nil - case article.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case article.FieldUpdatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUpdatedAt(v) - return nil - } - return fmt.Errorf("unknown Article field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *ArticleMutation) AddedFields() []string { - return nil -} - -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *ArticleMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *ArticleMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown Article numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *ArticleMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *ArticleMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *ArticleMutation) ClearField(name string) error { - return fmt.Errorf("unknown Article nullable field %s", name) -} - -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *ArticleMutation) ResetField(name string) error { - switch name { - case article.FieldTitle: - m.ResetTitle() - return nil - case article.FieldContent: - m.ResetContent() - return nil - case article.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case article.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - } - return fmt.Errorf("unknown Article field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *ArticleMutation) AddedEdges() []string { - edges := make([]string, 0, 2) - if m.comments != nil { - edges = append(edges, article.EdgeComments) - } - if m.tags != nil { - edges = append(edges, article.EdgeTags) - } - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *ArticleMutation) AddedIDs(name string) []ent.Value { - switch name { - case article.EdgeComments: - ids := make([]ent.Value, 0, len(m.comments)) - for id := range m.comments { - ids = append(ids, id) - } - return ids - case article.EdgeTags: - ids := make([]ent.Value, 0, len(m.tags)) - for id := range m.tags { - ids = append(ids, id) - } - return ids - } - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *ArticleMutation) RemovedEdges() []string { - edges := make([]string, 0, 2) - if m.removedcomments != nil { - edges = append(edges, article.EdgeComments) - } - if m.removedtags != nil { - edges = append(edges, article.EdgeTags) - } - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *ArticleMutation) RemovedIDs(name string) []ent.Value { - switch name { - case article.EdgeComments: - ids := make([]ent.Value, 0, len(m.removedcomments)) - for id := range m.removedcomments { - ids = append(ids, id) - } - return ids - case article.EdgeTags: - ids := make([]ent.Value, 0, len(m.removedtags)) - for id := range m.removedtags { - ids = append(ids, id) - } - return ids - } - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ArticleMutation) ClearedEdges() []string { - edges := make([]string, 0, 2) - if m.clearedcomments { - edges = append(edges, article.EdgeComments) - } - if m.clearedtags { - edges = append(edges, article.EdgeTags) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *ArticleMutation) EdgeCleared(name string) bool { - switch name { - case article.EdgeComments: - return m.clearedcomments - case article.EdgeTags: - return m.clearedtags - } - return false -} - -// ClearEdge clears the value of the edge with the given name. It returns an error -// if that edge is not defined in the schema. -func (m *ArticleMutation) ClearEdge(name string) error { - switch name { - } - return fmt.Errorf("unknown Article unique edge %s", name) -} - -// ResetEdge resets all changes to the edge with the given name in this mutation. -// It returns an error if the edge is not defined in the schema. -func (m *ArticleMutation) ResetEdge(name string) error { - switch name { - case article.EdgeComments: - m.ResetComments() - return nil - case article.EdgeTags: - m.ResetTags() - return nil - } - return fmt.Errorf("unknown Article edge %s", name) -} - -// CommentMutation represents an operation that mutates the Comment nodes in the graph. -type CommentMutation struct { - config - op Op - typ string - id *int64 - name *string - content *string - created_at *time.Time - updated_at *time.Time - clearedFields map[string]struct{} - post *int64 - clearedpost bool - done bool - oldValue func(context.Context) (*Comment, error) - predicates []predicate.Comment -} - -var _ ent.Mutation = (*CommentMutation)(nil) - -// commentOption allows management of the mutation configuration using functional options. -type commentOption func(*CommentMutation) - -// newCommentMutation creates new mutation for the Comment entity. -func newCommentMutation(c config, op Op, opts ...commentOption) *CommentMutation { - m := &CommentMutation{ - config: c, - op: op, - typ: TypeComment, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withCommentID sets the ID field of the mutation. -func withCommentID(id int64) commentOption { - return func(m *CommentMutation) { - var ( - err error - once sync.Once - value *Comment - ) - m.oldValue = func(ctx context.Context) (*Comment, error) { - once.Do(func() { - if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") - } else { - value, err = m.Client().Comment.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withComment sets the old Comment of the mutation. -func withComment(node *Comment) commentOption { - return func(m *CommentMutation) { - m.oldValue = func(context.Context) (*Comment, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m CommentMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m CommentMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of Comment entities. -func (m *CommentMutation) SetID(id int64) { - m.id = &id -} - -// ID returns the ID value in the mutation. Note that the ID -// is only available if it was provided to the builder. -func (m *CommentMutation) ID() (id int64, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// SetName sets the "name" field. -func (m *CommentMutation) SetName(s string) { - m.name = &s -} - -// Name returns the value of the "name" field in the mutation. -func (m *CommentMutation) Name() (r string, exists bool) { - v := m.name - if v == nil { - return - } - return *v, true -} - -// OldName returns the old "name" field's value of the Comment entity. -// If the Comment object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *CommentMutation) OldName(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldName is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldName requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldName: %w", err) - } - return oldValue.Name, nil -} - -// ResetName resets all changes to the "name" field. -func (m *CommentMutation) ResetName() { - m.name = nil -} - -// SetContent sets the "content" field. -func (m *CommentMutation) SetContent(s string) { - m.content = &s -} - -// Content returns the value of the "content" field in the mutation. -func (m *CommentMutation) Content() (r string, exists bool) { - v := m.content - if v == nil { - return - } - return *v, true -} - -// OldContent returns the old "content" field's value of the Comment entity. -// If the Comment object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *CommentMutation) OldContent(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldContent is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldContent requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldContent: %w", err) - } - return oldValue.Content, nil -} - -// ResetContent resets all changes to the "content" field. -func (m *CommentMutation) ResetContent() { - m.content = nil -} - -// SetCreatedAt sets the "created_at" field. -func (m *CommentMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *CommentMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the Comment entity. -// If the Comment object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *CommentMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *CommentMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *CommentMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *CommentMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return - } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the Comment entity. -// If the Comment object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *CommentMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) - } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *CommentMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetPostID sets the "post" edge to the Article entity by id. -func (m *CommentMutation) SetPostID(id int64) { - m.post = &id -} - -// ClearPost clears the "post" edge to the Article entity. -func (m *CommentMutation) ClearPost() { - m.clearedpost = true -} - -// PostCleared returns if the "post" edge to the Article entity was cleared. -func (m *CommentMutation) PostCleared() bool { - return m.clearedpost -} - -// PostID returns the "post" edge ID in the mutation. -func (m *CommentMutation) PostID() (id int64, exists bool) { - if m.post != nil { - return *m.post, true - } - return -} - -// PostIDs returns the "post" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// PostID instead. It exists only for internal usage by the builders. -func (m *CommentMutation) PostIDs() (ids []int64) { - if id := m.post; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetPost resets all changes to the "post" edge. -func (m *CommentMutation) ResetPost() { - m.post = nil - m.clearedpost = false -} - -// Op returns the operation name. -func (m *CommentMutation) Op() Op { - return m.op -} - -// Type returns the node type of this mutation (Comment). -func (m *CommentMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *CommentMutation) Fields() []string { - fields := make([]string, 0, 4) - if m.name != nil { - fields = append(fields, comment.FieldName) - } - if m.content != nil { - fields = append(fields, comment.FieldContent) - } - if m.created_at != nil { - fields = append(fields, comment.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, comment.FieldUpdatedAt) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *CommentMutation) Field(name string) (ent.Value, bool) { - switch name { - case comment.FieldName: - return m.Name() - case comment.FieldContent: - return m.Content() - case comment.FieldCreatedAt: - return m.CreatedAt() - case comment.FieldUpdatedAt: - return m.UpdatedAt() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *CommentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case comment.FieldName: - return m.OldName(ctx) - case comment.FieldContent: - return m.OldContent(ctx) - case comment.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case comment.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - } - return nil, fmt.Errorf("unknown Comment field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *CommentMutation) SetField(name string, value ent.Value) error { - switch name { - case comment.FieldName: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetName(v) - return nil - case comment.FieldContent: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetContent(v) - return nil - case comment.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case comment.FieldUpdatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUpdatedAt(v) - return nil - } - return fmt.Errorf("unknown Comment field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *CommentMutation) AddedFields() []string { - return nil -} - -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *CommentMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *CommentMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown Comment numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *CommentMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *CommentMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *CommentMutation) ClearField(name string) error { - return fmt.Errorf("unknown Comment nullable field %s", name) -} - -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *CommentMutation) ResetField(name string) error { - switch name { - case comment.FieldName: - m.ResetName() - return nil - case comment.FieldContent: - m.ResetContent() - return nil - case comment.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case comment.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - } - return fmt.Errorf("unknown Comment field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *CommentMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.post != nil { - edges = append(edges, comment.EdgePost) - } - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *CommentMutation) AddedIDs(name string) []ent.Value { - switch name { - case comment.EdgePost: - if id := m.post; id != nil { - return []ent.Value{*id} - } - } - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *CommentMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *CommentMutation) RemovedIDs(name string) []ent.Value { - switch name { - } - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *CommentMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.clearedpost { - edges = append(edges, comment.EdgePost) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *CommentMutation) EdgeCleared(name string) bool { - switch name { - case comment.EdgePost: - return m.clearedpost - } - return false -} - -// ClearEdge clears the value of the edge with the given name. It returns an error -// if that edge is not defined in the schema. -func (m *CommentMutation) ClearEdge(name string) error { - switch name { - case comment.EdgePost: - m.ClearPost() - return nil - } - return fmt.Errorf("unknown Comment unique edge %s", name) -} - -// ResetEdge resets all changes to the edge with the given name in this mutation. -// It returns an error if the edge is not defined in the schema. -func (m *CommentMutation) ResetEdge(name string) error { - switch name { - case comment.EdgePost: - m.ResetPost() - return nil - } - return fmt.Errorf("unknown Comment edge %s", name) -} - -// TagMutation represents an operation that mutates the Tag nodes in the graph. -type TagMutation struct { - config - op Op - typ string - id *int64 - slug *string - name *string - created_at *time.Time - updated_at *time.Time - clearedFields map[string]struct{} - posts map[int64]struct{} - removedposts map[int64]struct{} - clearedposts bool - done bool - oldValue func(context.Context) (*Tag, error) - predicates []predicate.Tag -} - -var _ ent.Mutation = (*TagMutation)(nil) - -// tagOption allows management of the mutation configuration using functional options. -type tagOption func(*TagMutation) - -// newTagMutation creates new mutation for the Tag entity. -func newTagMutation(c config, op Op, opts ...tagOption) *TagMutation { - m := &TagMutation{ - config: c, - op: op, - typ: TypeTag, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withTagID sets the ID field of the mutation. -func withTagID(id int64) tagOption { - return func(m *TagMutation) { - var ( - err error - once sync.Once - value *Tag - ) - m.oldValue = func(ctx context.Context) (*Tag, error) { - once.Do(func() { - if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") - } else { - value, err = m.Client().Tag.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withTag sets the old Tag of the mutation. -func withTag(node *Tag) tagOption { - return func(m *TagMutation) { - m.oldValue = func(context.Context) (*Tag, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m TagMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m TagMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of Tag entities. -func (m *TagMutation) SetID(id int64) { - m.id = &id -} - -// ID returns the ID value in the mutation. Note that the ID -// is only available if it was provided to the builder. -func (m *TagMutation) ID() (id int64, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// SetSlug sets the "slug" field. -func (m *TagMutation) SetSlug(s string) { - m.slug = &s -} - -// Slug returns the value of the "slug" field in the mutation. -func (m *TagMutation) Slug() (r string, exists bool) { - v := m.slug - if v == nil { - return - } - return *v, true -} - -// OldSlug returns the old "slug" field's value of the Tag entity. -// If the Tag object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *TagMutation) OldSlug(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSlug is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldSlug requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldSlug: %w", err) - } - return oldValue.Slug, nil -} - -// ResetSlug resets all changes to the "slug" field. -func (m *TagMutation) ResetSlug() { - m.slug = nil -} - -// SetName sets the "name" field. -func (m *TagMutation) SetName(s string) { - m.name = &s -} - -// Name returns the value of the "name" field in the mutation. -func (m *TagMutation) Name() (r string, exists bool) { - v := m.name - if v == nil { - return - } - return *v, true -} - -// OldName returns the old "name" field's value of the Tag entity. -// If the Tag object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *TagMutation) OldName(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldName is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldName requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldName: %w", err) - } - return oldValue.Name, nil -} - -// ResetName resets all changes to the "name" field. -func (m *TagMutation) ResetName() { - m.name = nil -} - -// SetCreatedAt sets the "created_at" field. -func (m *TagMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *TagMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the Tag entity. -// If the Tag object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *TagMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *TagMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *TagMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *TagMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return - } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the Tag entity. -// If the Tag object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *TagMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) - } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *TagMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// AddPostIDs adds the "posts" edge to the Article entity by ids. -func (m *TagMutation) AddPostIDs(ids ...int64) { - if m.posts == nil { - m.posts = make(map[int64]struct{}) - } - for i := range ids { - m.posts[ids[i]] = struct{}{} - } -} - -// ClearPosts clears the "posts" edge to the Article entity. -func (m *TagMutation) ClearPosts() { - m.clearedposts = true -} - -// PostsCleared returns if the "posts" edge to the Article entity was cleared. -func (m *TagMutation) PostsCleared() bool { - return m.clearedposts -} - -// RemovePostIDs removes the "posts" edge to the Article entity by IDs. -func (m *TagMutation) RemovePostIDs(ids ...int64) { - if m.removedposts == nil { - m.removedposts = make(map[int64]struct{}) - } - for i := range ids { - m.removedposts[ids[i]] = struct{}{} - } -} - -// RemovedPosts returns the removed IDs of the "posts" edge to the Article entity. -func (m *TagMutation) RemovedPostsIDs() (ids []int64) { - for id := range m.removedposts { - ids = append(ids, id) - } - return -} - -// PostsIDs returns the "posts" edge IDs in the mutation. -func (m *TagMutation) PostsIDs() (ids []int64) { - for id := range m.posts { - ids = append(ids, id) - } - return -} - -// ResetPosts resets all changes to the "posts" edge. -func (m *TagMutation) ResetPosts() { - m.posts = nil - m.clearedposts = false - m.removedposts = nil -} - -// Op returns the operation name. -func (m *TagMutation) Op() Op { - return m.op -} - -// Type returns the node type of this mutation (Tag). -func (m *TagMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *TagMutation) Fields() []string { - fields := make([]string, 0, 4) - if m.slug != nil { - fields = append(fields, tag.FieldSlug) - } - if m.name != nil { - fields = append(fields, tag.FieldName) - } - if m.created_at != nil { - fields = append(fields, tag.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, tag.FieldUpdatedAt) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *TagMutation) Field(name string) (ent.Value, bool) { - switch name { - case tag.FieldSlug: - return m.Slug() - case tag.FieldName: - return m.Name() - case tag.FieldCreatedAt: - return m.CreatedAt() - case tag.FieldUpdatedAt: - return m.UpdatedAt() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *TagMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case tag.FieldSlug: - return m.OldSlug(ctx) - case tag.FieldName: - return m.OldName(ctx) - case tag.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case tag.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - } - return nil, fmt.Errorf("unknown Tag field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *TagMutation) SetField(name string, value ent.Value) error { - switch name { - case tag.FieldSlug: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSlug(v) - return nil - case tag.FieldName: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetName(v) - return nil - case tag.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case tag.FieldUpdatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUpdatedAt(v) - return nil - } - return fmt.Errorf("unknown Tag field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *TagMutation) AddedFields() []string { - return nil -} - -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *TagMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *TagMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown Tag numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *TagMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *TagMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *TagMutation) ClearField(name string) error { - return fmt.Errorf("unknown Tag nullable field %s", name) -} - -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *TagMutation) ResetField(name string) error { - switch name { - case tag.FieldSlug: - m.ResetSlug() - return nil - case tag.FieldName: - m.ResetName() - return nil - case tag.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case tag.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - } - return fmt.Errorf("unknown Tag field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *TagMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.posts != nil { - edges = append(edges, tag.EdgePosts) - } - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *TagMutation) AddedIDs(name string) []ent.Value { - switch name { - case tag.EdgePosts: - ids := make([]ent.Value, 0, len(m.posts)) - for id := range m.posts { - ids = append(ids, id) - } - return ids - } - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *TagMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) - if m.removedposts != nil { - edges = append(edges, tag.EdgePosts) - } - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *TagMutation) RemovedIDs(name string) []ent.Value { - switch name { - case tag.EdgePosts: - ids := make([]ent.Value, 0, len(m.removedposts)) - for id := range m.removedposts { - ids = append(ids, id) - } - return ids - } - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *TagMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.clearedposts { - edges = append(edges, tag.EdgePosts) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *TagMutation) EdgeCleared(name string) bool { - switch name { - case tag.EdgePosts: - return m.clearedposts - } - return false -} - -// ClearEdge clears the value of the edge with the given name. It returns an error -// if that edge is not defined in the schema. -func (m *TagMutation) ClearEdge(name string) error { - switch name { - } - return fmt.Errorf("unknown Tag unique edge %s", name) -} - -// ResetEdge resets all changes to the edge with the given name in this mutation. -// It returns an error if the edge is not defined in the schema. -func (m *TagMutation) ResetEdge(name string) error { - switch name { - case tag.EdgePosts: - m.ResetPosts() - return nil - } - return fmt.Errorf("unknown Tag edge %s", name) -} diff --git a/examples/blog/internal/data/ent/predicate/predicate.go b/examples/blog/internal/data/ent/predicate/predicate.go deleted file mode 100644 index 4bc3b94a0..000000000 --- a/examples/blog/internal/data/ent/predicate/predicate.go +++ /dev/null @@ -1,16 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package predicate - -import ( - "entgo.io/ent/dialect/sql" -) - -// Article is the predicate function for article builders. -type Article func(*sql.Selector) - -// Comment is the predicate function for comment builders. -type Comment func(*sql.Selector) - -// Tag is the predicate function for tag builders. -type Tag func(*sql.Selector) diff --git a/examples/blog/internal/data/ent/runtime.go b/examples/blog/internal/data/ent/runtime.go deleted file mode 100644 index 65c772f32..000000000 --- a/examples/blog/internal/data/ent/runtime.go +++ /dev/null @@ -1,48 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "time" - - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/schema" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" -) - -// The init function reads all schema descriptors with runtime code -// (default values, validators, hooks and policies) and stitches it -// to their package variables. -func init() { - articleFields := schema.Article{}.Fields() - _ = articleFields - // articleDescCreatedAt is the schema descriptor for created_at field. - articleDescCreatedAt := articleFields[3].Descriptor() - // article.DefaultCreatedAt holds the default value on creation for the created_at field. - article.DefaultCreatedAt = articleDescCreatedAt.Default.(func() time.Time) - // articleDescUpdatedAt is the schema descriptor for updated_at field. - articleDescUpdatedAt := articleFields[4].Descriptor() - // article.DefaultUpdatedAt holds the default value on creation for the updated_at field. - article.DefaultUpdatedAt = articleDescUpdatedAt.Default.(func() time.Time) - commentFields := schema.Comment{}.Fields() - _ = commentFields - // commentDescCreatedAt is the schema descriptor for created_at field. - commentDescCreatedAt := commentFields[3].Descriptor() - // comment.DefaultCreatedAt holds the default value on creation for the created_at field. - comment.DefaultCreatedAt = commentDescCreatedAt.Default.(func() time.Time) - // commentDescUpdatedAt is the schema descriptor for updated_at field. - commentDescUpdatedAt := commentFields[4].Descriptor() - // comment.DefaultUpdatedAt holds the default value on creation for the updated_at field. - comment.DefaultUpdatedAt = commentDescUpdatedAt.Default.(func() time.Time) - tagFields := schema.Tag{}.Fields() - _ = tagFields - // tagDescCreatedAt is the schema descriptor for created_at field. - tagDescCreatedAt := tagFields[3].Descriptor() - // tag.DefaultCreatedAt holds the default value on creation for the created_at field. - tag.DefaultCreatedAt = tagDescCreatedAt.Default.(func() time.Time) - // tagDescUpdatedAt is the schema descriptor for updated_at field. - tagDescUpdatedAt := tagFields[4].Descriptor() - // tag.DefaultUpdatedAt holds the default value on creation for the updated_at field. - tag.DefaultUpdatedAt = tagDescUpdatedAt.Default.(func() time.Time) -} diff --git a/examples/blog/internal/data/ent/runtime/runtime.go b/examples/blog/internal/data/ent/runtime/runtime.go deleted file mode 100644 index 6fc96fef4..000000000 --- a/examples/blog/internal/data/ent/runtime/runtime.go +++ /dev/null @@ -1,10 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package runtime - -// The schema-stitching logic is generated in github.com/go-kratos/kratos/examples/blog/internal/data/ent/runtime.go - -const ( - Version = "v0.6.0" // Version of ent codegen. - Sum = "h1:oo/a8sXPQKzHYFlVwmwOnyzBy+u8FWQsoLLqFCrOBt0=" // Sum of ent codegen. -) diff --git a/examples/blog/internal/data/ent/schema/article.go b/examples/blog/internal/data/ent/schema/article.go deleted file mode 100644 index 795785265..000000000 --- a/examples/blog/internal/data/ent/schema/article.go +++ /dev/null @@ -1,41 +0,0 @@ -package schema - -import ( - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect" - "entgo.io/ent/schema/edge" - "entgo.io/ent/schema/field" -) - -// Article holds the schema definition for the Article entity. -type Article struct { - ent.Schema -} - -// Fields of the Post. -func (Article) Fields() []ent.Field { - return []ent.Field{ - field.Int64("id"), - field.String("title"), - field.String("content"), - field.Time("created_at"). - Default(time.Now).SchemaType(map[string]string{ - dialect.MySQL: "datetime", - }), - field.Time("updated_at"). - Default(time.Now).SchemaType(map[string]string{ - dialect.MySQL: "datetime", - }), - } -} - -// Edges of the Post. -func (Article) Edges() []ent.Edge { - return []ent.Edge{ - edge.To("comments", Comment.Type), - edge.From("tags", Tag.Type). - Ref("posts"), - } -} diff --git a/examples/blog/internal/data/ent/schema/comment.go b/examples/blog/internal/data/ent/schema/comment.go deleted file mode 100644 index 37eafb7bc..000000000 --- a/examples/blog/internal/data/ent/schema/comment.go +++ /dev/null @@ -1,41 +0,0 @@ -package schema - -import ( - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect" - "entgo.io/ent/schema/edge" - "entgo.io/ent/schema/field" -) - -// Comment holds the schema definition for the Comment entity. -type Comment struct { - ent.Schema -} - -// Fields of the Comment. -func (Comment) Fields() []ent.Field { - return []ent.Field{ - field.Int64("id"), - field.String("name"), - field.String("content"), - field.Time("created_at"). - Default(time.Now).SchemaType(map[string]string{ - dialect.MySQL: "datetime", - }), - field.Time("updated_at"). - Default(time.Now).SchemaType(map[string]string{ - dialect.MySQL: "datetime", - }), - } -} - -// Edges of the Comment. -func (Comment) Edges() []ent.Edge { - return []ent.Edge{ - edge.From("post", Article.Type). - Ref("comments"). - Unique(), - } -} diff --git a/examples/blog/internal/data/ent/schema/tag.go b/examples/blog/internal/data/ent/schema/tag.go deleted file mode 100644 index 3db2cb6bc..000000000 --- a/examples/blog/internal/data/ent/schema/tag.go +++ /dev/null @@ -1,39 +0,0 @@ -package schema - -import ( - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect" - "entgo.io/ent/schema/edge" - "entgo.io/ent/schema/field" -) - -// Tag holds the schema definition for the Tag entity. -type Tag struct { - ent.Schema -} - -// Fields of the Tag. -func (Tag) Fields() []ent.Field { - return []ent.Field{ - field.Int64("id"), - field.String("slug"), - field.String("name"), - field.Time("created_at"). - Default(time.Now).SchemaType(map[string]string{ - dialect.MySQL: "datetime", - }), - field.Time("updated_at"). - Default(time.Now).SchemaType(map[string]string{ - dialect.MySQL: "datetime", - }), - } -} - -// Edges of the Tag. -func (Tag) Edges() []ent.Edge { - return []ent.Edge{ - edge.To("posts", Article.Type), - } -} diff --git a/examples/blog/internal/data/ent/tag.go b/examples/blog/internal/data/ent/tag.go deleted file mode 100644 index 09aacd082..000000000 --- a/examples/blog/internal/data/ent/tag.go +++ /dev/null @@ -1,158 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent/dialect/sql" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" -) - -// Tag is the model entity for the Tag schema. -type Tag struct { - config `json:"-"` - // ID of the ent. - ID int64 `json:"id,omitempty"` - // Slug holds the value of the "slug" field. - Slug string `json:"slug,omitempty"` - // Name holds the value of the "name" field. - Name string `json:"name,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // UpdatedAt holds the value of the "updated_at" field. - UpdatedAt time.Time `json:"updated_at,omitempty"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the TagQuery when eager-loading is set. - Edges TagEdges `json:"edges"` -} - -// TagEdges holds the relations/edges for other nodes in the graph. -type TagEdges struct { - // Posts holds the value of the posts edge. - Posts []*Article `json:"posts,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [1]bool -} - -// PostsOrErr returns the Posts value or an error if the edge -// was not loaded in eager-loading. -func (e TagEdges) PostsOrErr() ([]*Article, error) { - if e.loadedTypes[0] { - return e.Posts, nil - } - return nil, &NotLoadedError{edge: "posts"} -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*Tag) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) - for i := range columns { - switch columns[i] { - case tag.FieldID: - values[i] = &sql.NullInt64{} - case tag.FieldSlug, tag.FieldName: - values[i] = &sql.NullString{} - case tag.FieldCreatedAt, tag.FieldUpdatedAt: - values[i] = &sql.NullTime{} - default: - return nil, fmt.Errorf("unexpected column %q for type Tag", columns[i]) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Tag fields. -func (t *Tag) assignValues(columns []string, values []interface{}) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case tag.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - t.ID = int64(value.Int64) - case tag.FieldSlug: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field slug", values[i]) - } else if value.Valid { - t.Slug = value.String - } - case tag.FieldName: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field name", values[i]) - } else if value.Valid { - t.Name = value.String - } - case tag.FieldCreatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[i]) - } else if value.Valid { - t.CreatedAt = value.Time - } - case tag.FieldUpdatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[i]) - } else if value.Valid { - t.UpdatedAt = value.Time - } - } - } - return nil -} - -// QueryPosts queries the "posts" edge of the Tag entity. -func (t *Tag) QueryPosts() *ArticleQuery { - return (&TagClient{config: t.config}).QueryPosts(t) -} - -// Update returns a builder for updating this Tag. -// Note that you need to call Tag.Unwrap() before calling this method if this Tag -// was returned from a transaction, and the transaction was committed or rolled back. -func (t *Tag) Update() *TagUpdateOne { - return (&TagClient{config: t.config}).UpdateOne(t) -} - -// Unwrap unwraps the Tag entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (t *Tag) Unwrap() *Tag { - tx, ok := t.config.driver.(*txDriver) - if !ok { - panic("ent: Tag is not a transactional entity") - } - t.config.driver = tx.drv - return t -} - -// String implements the fmt.Stringer. -func (t *Tag) String() string { - var builder strings.Builder - builder.WriteString("Tag(") - builder.WriteString(fmt.Sprintf("id=%v", t.ID)) - builder.WriteString(", slug=") - builder.WriteString(t.Slug) - builder.WriteString(", name=") - builder.WriteString(t.Name) - builder.WriteString(", created_at=") - builder.WriteString(t.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", updated_at=") - builder.WriteString(t.UpdatedAt.Format(time.ANSIC)) - builder.WriteByte(')') - return builder.String() -} - -// Tags is a parsable slice of Tag. -type Tags []*Tag - -func (t Tags) config(cfg config) { - for _i := range t { - t[_i].config = cfg - } -} diff --git a/examples/blog/internal/data/ent/tag/tag.go b/examples/blog/internal/data/ent/tag/tag.go deleted file mode 100644 index 2820a76e4..000000000 --- a/examples/blog/internal/data/ent/tag/tag.go +++ /dev/null @@ -1,65 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package tag - -import ( - "time" -) - -const ( - // Label holds the string label denoting the tag type in the database. - Label = "tag" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldSlug holds the string denoting the slug field in the database. - FieldSlug = "slug" - // FieldName holds the string denoting the name field in the database. - FieldName = "name" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldUpdatedAt holds the string denoting the updated_at field in the database. - FieldUpdatedAt = "updated_at" - - // EdgePosts holds the string denoting the posts edge name in mutations. - EdgePosts = "posts" - - // Table holds the table name of the tag in the database. - Table = "tags" - // PostsTable is the table the holds the posts relation/edge. The primary key declared below. - PostsTable = "tag_posts" - // PostsInverseTable is the table name for the Article entity. - // It exists in this package in order to avoid circular dependency with the "article" package. - PostsInverseTable = "articles" -) - -// Columns holds all SQL columns for tag fields. -var Columns = []string{ - FieldID, - FieldSlug, - FieldName, - FieldCreatedAt, - FieldUpdatedAt, -} - -var ( - // PostsPrimaryKey and PostsColumn2 are the table columns denoting the - // primary key for the posts relation (M2M). - PostsPrimaryKey = []string{"tag_id", "article_id"} -) - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. - DefaultUpdatedAt func() time.Time -) diff --git a/examples/blog/internal/data/ent/tag/where.go b/examples/blog/internal/data/ent/tag/where.go deleted file mode 100644 index 90b89bf89..000000000 --- a/examples/blog/internal/data/ent/tag/where.go +++ /dev/null @@ -1,556 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package tag - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int64) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int64) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int64) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int64) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int64) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int64) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int64) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int64) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int64) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) -} - -// Slug applies equality check predicate on the "slug" field. It's identical to SlugEQ. -func Slug(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSlug), v)) - }) -} - -// Name applies equality check predicate on the "name" field. It's identical to NameEQ. -func Name(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) -} - -// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. -func UpdatedAt(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) -} - -// SlugEQ applies the EQ predicate on the "slug" field. -func SlugEQ(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSlug), v)) - }) -} - -// SlugNEQ applies the NEQ predicate on the "slug" field. -func SlugNEQ(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldSlug), v)) - }) -} - -// SlugIn applies the In predicate on the "slug" field. -func SlugIn(vs ...string) predicate.Tag { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldSlug), v...)) - }) -} - -// SlugNotIn applies the NotIn predicate on the "slug" field. -func SlugNotIn(vs ...string) predicate.Tag { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldSlug), v...)) - }) -} - -// SlugGT applies the GT predicate on the "slug" field. -func SlugGT(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldSlug), v)) - }) -} - -// SlugGTE applies the GTE predicate on the "slug" field. -func SlugGTE(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldSlug), v)) - }) -} - -// SlugLT applies the LT predicate on the "slug" field. -func SlugLT(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldSlug), v)) - }) -} - -// SlugLTE applies the LTE predicate on the "slug" field. -func SlugLTE(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldSlug), v)) - }) -} - -// SlugContains applies the Contains predicate on the "slug" field. -func SlugContains(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldSlug), v)) - }) -} - -// SlugHasPrefix applies the HasPrefix predicate on the "slug" field. -func SlugHasPrefix(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldSlug), v)) - }) -} - -// SlugHasSuffix applies the HasSuffix predicate on the "slug" field. -func SlugHasSuffix(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldSlug), v)) - }) -} - -// SlugEqualFold applies the EqualFold predicate on the "slug" field. -func SlugEqualFold(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldSlug), v)) - }) -} - -// SlugContainsFold applies the ContainsFold predicate on the "slug" field. -func SlugContainsFold(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldSlug), v)) - }) -} - -// NameEQ applies the EQ predicate on the "name" field. -func NameEQ(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) -} - -// NameNEQ applies the NEQ predicate on the "name" field. -func NameNEQ(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) -} - -// NameIn applies the In predicate on the "name" field. -func NameIn(vs ...string) predicate.Tag { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldName), v...)) - }) -} - -// NameNotIn applies the NotIn predicate on the "name" field. -func NameNotIn(vs ...string) predicate.Tag { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) -} - -// NameGT applies the GT predicate on the "name" field. -func NameGT(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) -} - -// NameGTE applies the GTE predicate on the "name" field. -func NameGTE(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) -} - -// NameLT applies the LT predicate on the "name" field. -func NameLT(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) -} - -// NameLTE applies the LTE predicate on the "name" field. -func NameLTE(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) -} - -// NameContains applies the Contains predicate on the "name" field. -func NameContains(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) -} - -// NameHasPrefix applies the HasPrefix predicate on the "name" field. -func NameHasPrefix(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) -} - -// NameHasSuffix applies the HasSuffix predicate on the "name" field. -func NameHasSuffix(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) -} - -// NameEqualFold applies the EqualFold predicate on the "name" field. -func NameEqualFold(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) -} - -// NameContainsFold applies the ContainsFold predicate on the "name" field. -func NameContainsFold(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.Tag { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.Tag { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) -} - -// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. -func UpdatedAtEQ(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. -func UpdatedAtNEQ(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtIn applies the In predicate on the "updated_at" field. -func UpdatedAtIn(vs ...time.Time) predicate.Tag { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) -} - -// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. -func UpdatedAtNotIn(vs ...time.Time) predicate.Tag { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) -} - -// UpdatedAtGT applies the GT predicate on the "updated_at" field. -func UpdatedAtGT(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. -func UpdatedAtGTE(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtLT applies the LT predicate on the "updated_at" field. -func UpdatedAtLT(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. -func UpdatedAtLTE(v time.Time) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) -} - -// HasPosts applies the HasEdge predicate on the "posts" edge. -func HasPosts() predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(PostsTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, PostsTable, PostsPrimaryKey...), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasPostsWith applies the HasEdge predicate on the "posts" edge with a given conditions (other predicates). -func HasPostsWith(preds ...predicate.Article) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(PostsInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, PostsTable, PostsPrimaryKey...), - ) - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.Tag) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.Tag) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.Tag) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - p(s.Not()) - }) -} diff --git a/examples/blog/internal/data/ent/tag_create.go b/examples/blog/internal/data/ent/tag_create.go deleted file mode 100644 index eabb8ede0..000000000 --- a/examples/blog/internal/data/ent/tag_create.go +++ /dev/null @@ -1,315 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" -) - -// TagCreate is the builder for creating a Tag entity. -type TagCreate struct { - config - mutation *TagMutation - hooks []Hook -} - -// SetSlug sets the "slug" field. -func (tc *TagCreate) SetSlug(s string) *TagCreate { - tc.mutation.SetSlug(s) - return tc -} - -// SetName sets the "name" field. -func (tc *TagCreate) SetName(s string) *TagCreate { - tc.mutation.SetName(s) - return tc -} - -// SetCreatedAt sets the "created_at" field. -func (tc *TagCreate) SetCreatedAt(t time.Time) *TagCreate { - tc.mutation.SetCreatedAt(t) - return tc -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (tc *TagCreate) SetNillableCreatedAt(t *time.Time) *TagCreate { - if t != nil { - tc.SetCreatedAt(*t) - } - return tc -} - -// SetUpdatedAt sets the "updated_at" field. -func (tc *TagCreate) SetUpdatedAt(t time.Time) *TagCreate { - tc.mutation.SetUpdatedAt(t) - return tc -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (tc *TagCreate) SetNillableUpdatedAt(t *time.Time) *TagCreate { - if t != nil { - tc.SetUpdatedAt(*t) - } - return tc -} - -// SetID sets the "id" field. -func (tc *TagCreate) SetID(i int64) *TagCreate { - tc.mutation.SetID(i) - return tc -} - -// AddPostIDs adds the "posts" edge to the Article entity by IDs. -func (tc *TagCreate) AddPostIDs(ids ...int64) *TagCreate { - tc.mutation.AddPostIDs(ids...) - return tc -} - -// AddPosts adds the "posts" edges to the Article entity. -func (tc *TagCreate) AddPosts(a ...*Article) *TagCreate { - ids := make([]int64, len(a)) - for i := range a { - ids[i] = a[i].ID - } - return tc.AddPostIDs(ids...) -} - -// Mutation returns the TagMutation object of the builder. -func (tc *TagCreate) Mutation() *TagMutation { - return tc.mutation -} - -// Save creates the Tag in the database. -func (tc *TagCreate) Save(ctx context.Context) (*Tag, error) { - var ( - err error - node *Tag - ) - tc.defaults() - if len(tc.hooks) == 0 { - if err = tc.check(); err != nil { - return nil, err - } - node, err = tc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TagMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = tc.check(); err != nil { - return nil, err - } - tc.mutation = mutation - node, err = tc.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(tc.hooks) - 1; i >= 0; i-- { - mut = tc.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, tc.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX calls Save and panics if Save returns an error. -func (tc *TagCreate) SaveX(ctx context.Context) *Tag { - v, err := tc.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// defaults sets the default values of the builder before save. -func (tc *TagCreate) defaults() { - if _, ok := tc.mutation.CreatedAt(); !ok { - v := tag.DefaultCreatedAt() - tc.mutation.SetCreatedAt(v) - } - if _, ok := tc.mutation.UpdatedAt(); !ok { - v := tag.DefaultUpdatedAt() - tc.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (tc *TagCreate) check() error { - if _, ok := tc.mutation.Slug(); !ok { - return &ValidationError{Name: "slug", err: errors.New("ent: missing required field \"slug\"")} - } - if _, ok := tc.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New("ent: missing required field \"name\"")} - } - if _, ok := tc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New("ent: missing required field \"created_at\"")} - } - if _, ok := tc.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New("ent: missing required field \"updated_at\"")} - } - return nil -} - -func (tc *TagCreate) sqlSave(ctx context.Context) (*Tag, error) { - _node, _spec := tc.createSpec() - if err := sqlgraph.CreateNode(ctx, tc.driver, _spec); err != nil { - if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - return nil, err - } - if _node.ID == 0 { - id := _spec.ID.Value.(int64) - _node.ID = int64(id) - } - return _node, nil -} - -func (tc *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) { - var ( - _node = &Tag{config: tc.config} - _spec = &sqlgraph.CreateSpec{ - Table: tag.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - } - ) - if id, ok := tc.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = id - } - if value, ok := tc.mutation.Slug(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: tag.FieldSlug, - }) - _node.Slug = value - } - if value, ok := tc.mutation.Name(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: tag.FieldName, - }) - _node.Name = value - } - if value, ok := tc.mutation.CreatedAt(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: tag.FieldCreatedAt, - }) - _node.CreatedAt = value - } - if value, ok := tc.mutation.UpdatedAt(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: tag.FieldUpdatedAt, - }) - _node.UpdatedAt = value - } - if nodes := tc.mutation.PostsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: tag.PostsTable, - Columns: tag.PostsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - return _node, _spec -} - -// TagCreateBulk is the builder for creating many Tag entities in bulk. -type TagCreateBulk struct { - config - builders []*TagCreate -} - -// Save creates the Tag entities in the database. -func (tcb *TagCreateBulk) Save(ctx context.Context) ([]*Tag, error) { - specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) - nodes := make([]*Tag, len(tcb.builders)) - mutators := make([]Mutator, len(tcb.builders)) - for i := range tcb.builders { - func(i int, root context.Context) { - builder := tcb.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TagMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() - var err error - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, tcb.builders[i+1].mutation) - } else { - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, tcb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil { - if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - } - } - mutation.done = true - if err != nil { - return nil, err - } - if nodes[i].ID == 0 { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int64(id) - } - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, tcb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (tcb *TagCreateBulk) SaveX(ctx context.Context) []*Tag { - v, err := tcb.Save(ctx) - if err != nil { - panic(err) - } - return v -} diff --git a/examples/blog/internal/data/ent/tag_delete.go b/examples/blog/internal/data/ent/tag_delete.go deleted file mode 100644 index 03af918c6..000000000 --- a/examples/blog/internal/data/ent/tag_delete.go +++ /dev/null @@ -1,108 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" -) - -// TagDelete is the builder for deleting a Tag entity. -type TagDelete struct { - config - hooks []Hook - mutation *TagMutation -} - -// Where adds a new predicate to the TagDelete builder. -func (td *TagDelete) Where(ps ...predicate.Tag) *TagDelete { - td.mutation.predicates = append(td.mutation.predicates, ps...) - return td -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (td *TagDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(td.hooks) == 0 { - affected, err = td.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TagMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - td.mutation = mutation - affected, err = td.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(td.hooks) - 1; i >= 0; i-- { - mut = td.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, td.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// ExecX is like Exec, but panics if an error occurs. -func (td *TagDelete) ExecX(ctx context.Context) int { - n, err := td.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (td *TagDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: tag.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - }, - } - if ps := td.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return sqlgraph.DeleteNodes(ctx, td.driver, _spec) -} - -// TagDeleteOne is the builder for deleting a single Tag entity. -type TagDeleteOne struct { - td *TagDelete -} - -// Exec executes the deletion query. -func (tdo *TagDeleteOne) Exec(ctx context.Context) error { - n, err := tdo.td.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{tag.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (tdo *TagDeleteOne) ExecX(ctx context.Context) { - tdo.td.ExecX(ctx) -} diff --git a/examples/blog/internal/data/ent/tag_query.go b/examples/blog/internal/data/ent/tag_query.go deleted file mode 100644 index 5d721a690..000000000 --- a/examples/blog/internal/data/ent/tag_query.go +++ /dev/null @@ -1,1002 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "database/sql/driver" - "errors" - "fmt" - "math" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" -) - -// TagQuery is the builder for querying Tag entities. -type TagQuery struct { - config - limit *int - offset *int - order []OrderFunc - fields []string - predicates []predicate.Tag - // eager-loading edges. - withPosts *ArticleQuery - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the TagQuery builder. -func (tq *TagQuery) Where(ps ...predicate.Tag) *TagQuery { - tq.predicates = append(tq.predicates, ps...) - return tq -} - -// Limit adds a limit step to the query. -func (tq *TagQuery) Limit(limit int) *TagQuery { - tq.limit = &limit - return tq -} - -// Offset adds an offset step to the query. -func (tq *TagQuery) Offset(offset int) *TagQuery { - tq.offset = &offset - return tq -} - -// Order adds an order step to the query. -func (tq *TagQuery) Order(o ...OrderFunc) *TagQuery { - tq.order = append(tq.order, o...) - return tq -} - -// QueryPosts chains the current query on the "posts" edge. -func (tq *TagQuery) QueryPosts() *ArticleQuery { - query := &ArticleQuery{config: tq.config} - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := tq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := tq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(tag.Table, tag.FieldID, selector), - sqlgraph.To(article.Table, article.FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, tag.PostsTable, tag.PostsPrimaryKey...), - ) - fromU = sqlgraph.SetNeighbors(tq.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first Tag entity from the query. -// Returns a *NotFoundError when no Tag was found. -func (tq *TagQuery) First(ctx context.Context) (*Tag, error) { - nodes, err := tq.Limit(1).All(ctx) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{tag.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (tq *TagQuery) FirstX(ctx context.Context) *Tag { - node, err := tq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first Tag ID from the query. -// Returns a *NotFoundError when no Tag ID was found. -func (tq *TagQuery) FirstID(ctx context.Context) (id int64, err error) { - var ids []int64 - if ids, err = tq.Limit(1).IDs(ctx); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{tag.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (tq *TagQuery) FirstIDX(ctx context.Context) int64 { - id, err := tq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single Tag entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one Tag entity is not found. -// Returns a *NotFoundError when no Tag entities are found. -func (tq *TagQuery) Only(ctx context.Context) (*Tag, error) { - nodes, err := tq.Limit(2).All(ctx) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{tag.Label} - default: - return nil, &NotSingularError{tag.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (tq *TagQuery) OnlyX(ctx context.Context) *Tag { - node, err := tq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only Tag ID in the query. -// Returns a *NotSingularError when exactly one Tag ID is not found. -// Returns a *NotFoundError when no entities are found. -func (tq *TagQuery) OnlyID(ctx context.Context) (id int64, err error) { - var ids []int64 - if ids, err = tq.Limit(2).IDs(ctx); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{tag.Label} - default: - err = &NotSingularError{tag.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (tq *TagQuery) OnlyIDX(ctx context.Context) int64 { - id, err := tq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of Tags. -func (tq *TagQuery) All(ctx context.Context) ([]*Tag, error) { - if err := tq.prepareQuery(ctx); err != nil { - return nil, err - } - return tq.sqlAll(ctx) -} - -// AllX is like All, but panics if an error occurs. -func (tq *TagQuery) AllX(ctx context.Context) []*Tag { - nodes, err := tq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of Tag IDs. -func (tq *TagQuery) IDs(ctx context.Context) ([]int64, error) { - var ids []int64 - if err := tq.Select(tag.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (tq *TagQuery) IDsX(ctx context.Context) []int64 { - ids, err := tq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (tq *TagQuery) Count(ctx context.Context) (int, error) { - if err := tq.prepareQuery(ctx); err != nil { - return 0, err - } - return tq.sqlCount(ctx) -} - -// CountX is like Count, but panics if an error occurs. -func (tq *TagQuery) CountX(ctx context.Context) int { - count, err := tq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (tq *TagQuery) Exist(ctx context.Context) (bool, error) { - if err := tq.prepareQuery(ctx); err != nil { - return false, err - } - return tq.sqlExist(ctx) -} - -// ExistX is like Exist, but panics if an error occurs. -func (tq *TagQuery) ExistX(ctx context.Context) bool { - exist, err := tq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the TagQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (tq *TagQuery) Clone() *TagQuery { - if tq == nil { - return nil - } - return &TagQuery{ - config: tq.config, - limit: tq.limit, - offset: tq.offset, - order: append([]OrderFunc{}, tq.order...), - predicates: append([]predicate.Tag{}, tq.predicates...), - withPosts: tq.withPosts.Clone(), - // clone intermediate query. - sql: tq.sql.Clone(), - path: tq.path, - } -} - -// WithPosts tells the query-builder to eager-load the nodes that are connected to -// the "posts" edge. The optional arguments are used to configure the query builder of the edge. -func (tq *TagQuery) WithPosts(opts ...func(*ArticleQuery)) *TagQuery { - query := &ArticleQuery{config: tq.config} - for _, opt := range opts { - opt(query) - } - tq.withPosts = query - return tq -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// Slug string `json:"slug,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.Tag.Query(). -// GroupBy(tag.FieldSlug). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -// -func (tq *TagQuery) GroupBy(field string, fields ...string) *TagGroupBy { - group := &TagGroupBy{config: tq.config} - group.fields = append([]string{field}, fields...) - group.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := tq.prepareQuery(ctx); err != nil { - return nil, err - } - return tq.sqlQuery(ctx), nil - } - return group -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// Slug string `json:"slug,omitempty"` -// } -// -// client.Tag.Query(). -// Select(tag.FieldSlug). -// Scan(ctx, &v) -// -func (tq *TagQuery) Select(field string, fields ...string) *TagSelect { - tq.fields = append([]string{field}, fields...) - return &TagSelect{TagQuery: tq} -} - -func (tq *TagQuery) prepareQuery(ctx context.Context) error { - for _, f := range tq.fields { - if !tag.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if tq.path != nil { - prev, err := tq.path(ctx) - if err != nil { - return err - } - tq.sql = prev - } - return nil -} - -func (tq *TagQuery) sqlAll(ctx context.Context) ([]*Tag, error) { - var ( - nodes = []*Tag{} - _spec = tq.querySpec() - loadedTypes = [1]bool{ - tq.withPosts != nil, - } - ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { - node := &Tag{config: tq.config} - nodes = append(nodes, node) - return node.scanValues(columns) - } - _spec.Assign = func(columns []string, values []interface{}) error { - if len(nodes) == 0 { - return fmt.Errorf("ent: Assign called without calling ScanValues") - } - node := nodes[len(nodes)-1] - node.Edges.loadedTypes = loadedTypes - return node.assignValues(columns, values) - } - if err := sqlgraph.QueryNodes(ctx, tq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - - if query := tq.withPosts; query != nil { - fks := make([]driver.Value, 0, len(nodes)) - ids := make(map[int64]*Tag, len(nodes)) - for _, node := range nodes { - ids[node.ID] = node - fks = append(fks, node.ID) - node.Edges.Posts = []*Article{} - } - var ( - edgeids []int64 - edges = make(map[int64][]*Tag) - ) - _spec := &sqlgraph.EdgeQuerySpec{ - Edge: &sqlgraph.EdgeSpec{ - Inverse: false, - Table: tag.PostsTable, - Columns: tag.PostsPrimaryKey, - }, - Predicate: func(s *sql.Selector) { - s.Where(sql.InValues(tag.PostsPrimaryKey[0], fks...)) - }, - - ScanValues: func() [2]interface{} { - return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}} - }, - Assign: func(out, in interface{}) error { - eout, ok := out.(*sql.NullInt64) - if !ok || eout == nil { - return fmt.Errorf("unexpected id value for edge-out") - } - ein, ok := in.(*sql.NullInt64) - if !ok || ein == nil { - return fmt.Errorf("unexpected id value for edge-in") - } - outValue := eout.Int64 - inValue := ein.Int64 - node, ok := ids[outValue] - if !ok { - return fmt.Errorf("unexpected node id in edges: %v", outValue) - } - edgeids = append(edgeids, inValue) - edges[inValue] = append(edges[inValue], node) - return nil - }, - } - if err := sqlgraph.QueryEdges(ctx, tq.driver, _spec); err != nil { - return nil, fmt.Errorf(`query edges "posts": %v`, err) - } - query.Where(article.IDIn(edgeids...)) - neighbors, err := query.All(ctx) - if err != nil { - return nil, err - } - for _, n := range neighbors { - nodes, ok := edges[n.ID] - if !ok { - return nil, fmt.Errorf(`unexpected "posts" node returned %v`, n.ID) - } - for i := range nodes { - nodes[i].Edges.Posts = append(nodes[i].Edges.Posts, n) - } - } - } - - return nodes, nil -} - -func (tq *TagQuery) sqlCount(ctx context.Context) (int, error) { - _spec := tq.querySpec() - return sqlgraph.CountNodes(ctx, tq.driver, _spec) -} - -func (tq *TagQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := tq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("ent: check existence: %v", err) - } - return n > 0, nil -} - -func (tq *TagQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: tag.Table, - Columns: tag.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - }, - From: tq.sql, - Unique: true, - } - if fields := tq.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, tag.FieldID) - for i := range fields { - if fields[i] != tag.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := tq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := tq.limit; limit != nil { - _spec.Limit = *limit - } - if offset := tq.offset; offset != nil { - _spec.Offset = *offset - } - if ps := tq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector, tag.ValidColumn) - } - } - } - return _spec -} - -func (tq *TagQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(tq.driver.Dialect()) - t1 := builder.Table(tag.Table) - selector := builder.Select(t1.Columns(tag.Columns...)...).From(t1) - if tq.sql != nil { - selector = tq.sql - selector.Select(selector.Columns(tag.Columns...)...) - } - for _, p := range tq.predicates { - p(selector) - } - for _, p := range tq.order { - p(selector, tag.ValidColumn) - } - if offset := tq.offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := tq.limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// TagGroupBy is the group-by builder for Tag entities. -type TagGroupBy struct { - config - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (tgb *TagGroupBy) Aggregate(fns ...AggregateFunc) *TagGroupBy { - tgb.fns = append(tgb.fns, fns...) - return tgb -} - -// Scan applies the group-by query and scans the result into the given value. -func (tgb *TagGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := tgb.path(ctx) - if err != nil { - return err - } - tgb.sql = query - return tgb.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (tgb *TagGroupBy) ScanX(ctx context.Context, v interface{}) { - if err := tgb.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from group-by. -// It is only allowed when executing a group-by query with one field. -func (tgb *TagGroupBy) Strings(ctx context.Context) ([]string, error) { - if len(tgb.fields) > 1 { - return nil, errors.New("ent: TagGroupBy.Strings is not achievable when grouping more than 1 field") - } - var v []string - if err := tgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (tgb *TagGroupBy) StringsX(ctx context.Context) []string { - v, err := tgb.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (tgb *TagGroupBy) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = tgb.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{tag.Label} - default: - err = fmt.Errorf("ent: TagGroupBy.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (tgb *TagGroupBy) StringX(ctx context.Context) string { - v, err := tgb.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from group-by. -// It is only allowed when executing a group-by query with one field. -func (tgb *TagGroupBy) Ints(ctx context.Context) ([]int, error) { - if len(tgb.fields) > 1 { - return nil, errors.New("ent: TagGroupBy.Ints is not achievable when grouping more than 1 field") - } - var v []int - if err := tgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (tgb *TagGroupBy) IntsX(ctx context.Context) []int { - v, err := tgb.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (tgb *TagGroupBy) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = tgb.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{tag.Label} - default: - err = fmt.Errorf("ent: TagGroupBy.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (tgb *TagGroupBy) IntX(ctx context.Context) int { - v, err := tgb.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from group-by. -// It is only allowed when executing a group-by query with one field. -func (tgb *TagGroupBy) Float64s(ctx context.Context) ([]float64, error) { - if len(tgb.fields) > 1 { - return nil, errors.New("ent: TagGroupBy.Float64s is not achievable when grouping more than 1 field") - } - var v []float64 - if err := tgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (tgb *TagGroupBy) Float64sX(ctx context.Context) []float64 { - v, err := tgb.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (tgb *TagGroupBy) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = tgb.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{tag.Label} - default: - err = fmt.Errorf("ent: TagGroupBy.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (tgb *TagGroupBy) Float64X(ctx context.Context) float64 { - v, err := tgb.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from group-by. -// It is only allowed when executing a group-by query with one field. -func (tgb *TagGroupBy) Bools(ctx context.Context) ([]bool, error) { - if len(tgb.fields) > 1 { - return nil, errors.New("ent: TagGroupBy.Bools is not achievable when grouping more than 1 field") - } - var v []bool - if err := tgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (tgb *TagGroupBy) BoolsX(ctx context.Context) []bool { - v, err := tgb.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (tgb *TagGroupBy) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = tgb.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{tag.Label} - default: - err = fmt.Errorf("ent: TagGroupBy.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (tgb *TagGroupBy) BoolX(ctx context.Context) bool { - v, err := tgb.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (tgb *TagGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range tgb.fields { - if !tag.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := tgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := tgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (tgb *TagGroupBy) sqlQuery() *sql.Selector { - selector := tgb.sql - columns := make([]string, 0, len(tgb.fields)+len(tgb.fns)) - columns = append(columns, tgb.fields...) - for _, fn := range tgb.fns { - columns = append(columns, fn(selector, tag.ValidColumn)) - } - return selector.Select(columns...).GroupBy(tgb.fields...) -} - -// TagSelect is the builder for selecting fields of Tag entities. -type TagSelect struct { - *TagQuery - // intermediate query (i.e. traversal path). - sql *sql.Selector -} - -// Scan applies the selector query and scans the result into the given value. -func (ts *TagSelect) Scan(ctx context.Context, v interface{}) error { - if err := ts.prepareQuery(ctx); err != nil { - return err - } - ts.sql = ts.TagQuery.sqlQuery(ctx) - return ts.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (ts *TagSelect) ScanX(ctx context.Context, v interface{}) { - if err := ts.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from a selector. It is only allowed when selecting one field. -func (ts *TagSelect) Strings(ctx context.Context) ([]string, error) { - if len(ts.fields) > 1 { - return nil, errors.New("ent: TagSelect.Strings is not achievable when selecting more than 1 field") - } - var v []string - if err := ts.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (ts *TagSelect) StringsX(ctx context.Context) []string { - v, err := ts.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a selector. It is only allowed when selecting one field. -func (ts *TagSelect) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = ts.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{tag.Label} - default: - err = fmt.Errorf("ent: TagSelect.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (ts *TagSelect) StringX(ctx context.Context) string { - v, err := ts.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from a selector. It is only allowed when selecting one field. -func (ts *TagSelect) Ints(ctx context.Context) ([]int, error) { - if len(ts.fields) > 1 { - return nil, errors.New("ent: TagSelect.Ints is not achievable when selecting more than 1 field") - } - var v []int - if err := ts.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (ts *TagSelect) IntsX(ctx context.Context) []int { - v, err := ts.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a selector. It is only allowed when selecting one field. -func (ts *TagSelect) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = ts.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{tag.Label} - default: - err = fmt.Errorf("ent: TagSelect.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (ts *TagSelect) IntX(ctx context.Context) int { - v, err := ts.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. -func (ts *TagSelect) Float64s(ctx context.Context) ([]float64, error) { - if len(ts.fields) > 1 { - return nil, errors.New("ent: TagSelect.Float64s is not achievable when selecting more than 1 field") - } - var v []float64 - if err := ts.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (ts *TagSelect) Float64sX(ctx context.Context) []float64 { - v, err := ts.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. -func (ts *TagSelect) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = ts.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{tag.Label} - default: - err = fmt.Errorf("ent: TagSelect.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (ts *TagSelect) Float64X(ctx context.Context) float64 { - v, err := ts.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from a selector. It is only allowed when selecting one field. -func (ts *TagSelect) Bools(ctx context.Context) ([]bool, error) { - if len(ts.fields) > 1 { - return nil, errors.New("ent: TagSelect.Bools is not achievable when selecting more than 1 field") - } - var v []bool - if err := ts.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (ts *TagSelect) BoolsX(ctx context.Context) []bool { - v, err := ts.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a selector. It is only allowed when selecting one field. -func (ts *TagSelect) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = ts.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{tag.Label} - default: - err = fmt.Errorf("ent: TagSelect.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (ts *TagSelect) BoolX(ctx context.Context) bool { - v, err := ts.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (ts *TagSelect) sqlScan(ctx context.Context, v interface{}) error { - rows := &sql.Rows{} - query, args := ts.sqlQuery().Query() - if err := ts.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (ts *TagSelect) sqlQuery() sql.Querier { - selector := ts.sql - selector.Select(selector.Columns(ts.fields...)...) - return selector -} diff --git a/examples/blog/internal/data/ent/tag_update.go b/examples/blog/internal/data/ent/tag_update.go deleted file mode 100644 index 2edccab4a..000000000 --- a/examples/blog/internal/data/ent/tag_update.go +++ /dev/null @@ -1,530 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" - "github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" -) - -// TagUpdate is the builder for updating Tag entities. -type TagUpdate struct { - config - hooks []Hook - mutation *TagMutation -} - -// Where adds a new predicate for the TagUpdate builder. -func (tu *TagUpdate) Where(ps ...predicate.Tag) *TagUpdate { - tu.mutation.predicates = append(tu.mutation.predicates, ps...) - return tu -} - -// SetSlug sets the "slug" field. -func (tu *TagUpdate) SetSlug(s string) *TagUpdate { - tu.mutation.SetSlug(s) - return tu -} - -// SetName sets the "name" field. -func (tu *TagUpdate) SetName(s string) *TagUpdate { - tu.mutation.SetName(s) - return tu -} - -// SetCreatedAt sets the "created_at" field. -func (tu *TagUpdate) SetCreatedAt(t time.Time) *TagUpdate { - tu.mutation.SetCreatedAt(t) - return tu -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (tu *TagUpdate) SetNillableCreatedAt(t *time.Time) *TagUpdate { - if t != nil { - tu.SetCreatedAt(*t) - } - return tu -} - -// SetUpdatedAt sets the "updated_at" field. -func (tu *TagUpdate) SetUpdatedAt(t time.Time) *TagUpdate { - tu.mutation.SetUpdatedAt(t) - return tu -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (tu *TagUpdate) SetNillableUpdatedAt(t *time.Time) *TagUpdate { - if t != nil { - tu.SetUpdatedAt(*t) - } - return tu -} - -// AddPostIDs adds the "posts" edge to the Article entity by IDs. -func (tu *TagUpdate) AddPostIDs(ids ...int64) *TagUpdate { - tu.mutation.AddPostIDs(ids...) - return tu -} - -// AddPosts adds the "posts" edges to the Article entity. -func (tu *TagUpdate) AddPosts(a ...*Article) *TagUpdate { - ids := make([]int64, len(a)) - for i := range a { - ids[i] = a[i].ID - } - return tu.AddPostIDs(ids...) -} - -// Mutation returns the TagMutation object of the builder. -func (tu *TagUpdate) Mutation() *TagMutation { - return tu.mutation -} - -// ClearPosts clears all "posts" edges to the Article entity. -func (tu *TagUpdate) ClearPosts() *TagUpdate { - tu.mutation.ClearPosts() - return tu -} - -// RemovePostIDs removes the "posts" edge to Article entities by IDs. -func (tu *TagUpdate) RemovePostIDs(ids ...int64) *TagUpdate { - tu.mutation.RemovePostIDs(ids...) - return tu -} - -// RemovePosts removes "posts" edges to Article entities. -func (tu *TagUpdate) RemovePosts(a ...*Article) *TagUpdate { - ids := make([]int64, len(a)) - for i := range a { - ids[i] = a[i].ID - } - return tu.RemovePostIDs(ids...) -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (tu *TagUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(tu.hooks) == 0 { - affected, err = tu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TagMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - tu.mutation = mutation - affected, err = tu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(tu.hooks) - 1; i >= 0; i-- { - mut = tu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, tu.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// SaveX is like Save, but panics if an error occurs. -func (tu *TagUpdate) SaveX(ctx context.Context) int { - affected, err := tu.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (tu *TagUpdate) Exec(ctx context.Context) error { - _, err := tu.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (tu *TagUpdate) ExecX(ctx context.Context) { - if err := tu.Exec(ctx); err != nil { - panic(err) - } -} - -func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: tag.Table, - Columns: tag.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - }, - } - if ps := tu.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := tu.mutation.Slug(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: tag.FieldSlug, - }) - } - if value, ok := tu.mutation.Name(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: tag.FieldName, - }) - } - if value, ok := tu.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: tag.FieldCreatedAt, - }) - } - if value, ok := tu.mutation.UpdatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: tag.FieldUpdatedAt, - }) - } - if tu.mutation.PostsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: tag.PostsTable, - Columns: tag.PostsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := tu.mutation.RemovedPostsIDs(); len(nodes) > 0 && !tu.mutation.PostsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: tag.PostsTable, - Columns: tag.PostsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := tu.mutation.PostsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: tag.PostsTable, - Columns: tag.PostsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if n, err = sqlgraph.UpdateNodes(ctx, tu.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{tag.Label} - } else if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - return 0, err - } - return n, nil -} - -// TagUpdateOne is the builder for updating a single Tag entity. -type TagUpdateOne struct { - config - hooks []Hook - mutation *TagMutation -} - -// SetSlug sets the "slug" field. -func (tuo *TagUpdateOne) SetSlug(s string) *TagUpdateOne { - tuo.mutation.SetSlug(s) - return tuo -} - -// SetName sets the "name" field. -func (tuo *TagUpdateOne) SetName(s string) *TagUpdateOne { - tuo.mutation.SetName(s) - return tuo -} - -// SetCreatedAt sets the "created_at" field. -func (tuo *TagUpdateOne) SetCreatedAt(t time.Time) *TagUpdateOne { - tuo.mutation.SetCreatedAt(t) - return tuo -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (tuo *TagUpdateOne) SetNillableCreatedAt(t *time.Time) *TagUpdateOne { - if t != nil { - tuo.SetCreatedAt(*t) - } - return tuo -} - -// SetUpdatedAt sets the "updated_at" field. -func (tuo *TagUpdateOne) SetUpdatedAt(t time.Time) *TagUpdateOne { - tuo.mutation.SetUpdatedAt(t) - return tuo -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (tuo *TagUpdateOne) SetNillableUpdatedAt(t *time.Time) *TagUpdateOne { - if t != nil { - tuo.SetUpdatedAt(*t) - } - return tuo -} - -// AddPostIDs adds the "posts" edge to the Article entity by IDs. -func (tuo *TagUpdateOne) AddPostIDs(ids ...int64) *TagUpdateOne { - tuo.mutation.AddPostIDs(ids...) - return tuo -} - -// AddPosts adds the "posts" edges to the Article entity. -func (tuo *TagUpdateOne) AddPosts(a ...*Article) *TagUpdateOne { - ids := make([]int64, len(a)) - for i := range a { - ids[i] = a[i].ID - } - return tuo.AddPostIDs(ids...) -} - -// Mutation returns the TagMutation object of the builder. -func (tuo *TagUpdateOne) Mutation() *TagMutation { - return tuo.mutation -} - -// ClearPosts clears all "posts" edges to the Article entity. -func (tuo *TagUpdateOne) ClearPosts() *TagUpdateOne { - tuo.mutation.ClearPosts() - return tuo -} - -// RemovePostIDs removes the "posts" edge to Article entities by IDs. -func (tuo *TagUpdateOne) RemovePostIDs(ids ...int64) *TagUpdateOne { - tuo.mutation.RemovePostIDs(ids...) - return tuo -} - -// RemovePosts removes "posts" edges to Article entities. -func (tuo *TagUpdateOne) RemovePosts(a ...*Article) *TagUpdateOne { - ids := make([]int64, len(a)) - for i := range a { - ids[i] = a[i].ID - } - return tuo.RemovePostIDs(ids...) -} - -// Save executes the query and returns the updated Tag entity. -func (tuo *TagUpdateOne) Save(ctx context.Context) (*Tag, error) { - var ( - err error - node *Tag - ) - if len(tuo.hooks) == 0 { - node, err = tuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TagMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - tuo.mutation = mutation - node, err = tuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(tuo.hooks) - 1; i >= 0; i-- { - mut = tuo.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, tuo.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX is like Save, but panics if an error occurs. -func (tuo *TagUpdateOne) SaveX(ctx context.Context) *Tag { - node, err := tuo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (tuo *TagUpdateOne) Exec(ctx context.Context) error { - _, err := tuo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (tuo *TagUpdateOne) ExecX(ctx context.Context) { - if err := tuo.Exec(ctx); err != nil { - panic(err) - } -} - -func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: tag.Table, - Columns: tag.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: tag.FieldID, - }, - }, - } - id, ok := tuo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Tag.ID for update")} - } - _spec.Node.ID.Value = id - if ps := tuo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := tuo.mutation.Slug(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: tag.FieldSlug, - }) - } - if value, ok := tuo.mutation.Name(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: tag.FieldName, - }) - } - if value, ok := tuo.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: tag.FieldCreatedAt, - }) - } - if value, ok := tuo.mutation.UpdatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: tag.FieldUpdatedAt, - }) - } - if tuo.mutation.PostsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: tag.PostsTable, - Columns: tag.PostsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := tuo.mutation.RemovedPostsIDs(); len(nodes) > 0 && !tuo.mutation.PostsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: tag.PostsTable, - Columns: tag.PostsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := tuo.mutation.PostsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: tag.PostsTable, - Columns: tag.PostsPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: article.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - _node = &Tag{config: tuo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, tuo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{tag.Label} - } else if cerr, ok := isSQLConstraintError(err); ok { - err = cerr - } - return nil, err - } - return _node, nil -} diff --git a/examples/blog/internal/data/ent/tx.go b/examples/blog/internal/data/ent/tx.go deleted file mode 100644 index 5deb3c08a..000000000 --- a/examples/blog/internal/data/ent/tx.go +++ /dev/null @@ -1,216 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "sync" - - "entgo.io/ent/dialect" -) - -// Tx is a transactional client that is created by calling Client.Tx(). -type Tx struct { - config - // Article is the client for interacting with the Article builders. - Article *ArticleClient - // Comment is the client for interacting with the Comment builders. - Comment *CommentClient - // Tag is the client for interacting with the Tag builders. - Tag *TagClient - - // lazily loaded. - client *Client - clientOnce sync.Once - - // completion callbacks. - mu sync.Mutex - onCommit []CommitHook - onRollback []RollbackHook - - // ctx lives for the life of the transaction. It is - // the same context used by the underlying connection. - ctx context.Context -} - -type ( - // Committer is the interface that wraps the Committer method. - Committer interface { - Commit(context.Context, *Tx) error - } - - // The CommitFunc type is an adapter to allow the use of ordinary - // function as a Committer. If f is a function with the appropriate - // signature, CommitFunc(f) is a Committer that calls f. - CommitFunc func(context.Context, *Tx) error - - // CommitHook defines the "commit middleware". A function that gets a Committer - // and returns a Committer. For example: - // - // hook := func(next ent.Committer) ent.Committer { - // return ent.CommitFunc(func(context.Context, tx *ent.Tx) error { - // // Do some stuff before. - // if err := next.Commit(ctx, tx); err != nil { - // return err - // } - // // Do some stuff after. - // return nil - // }) - // } - // - CommitHook func(Committer) Committer -) - -// Commit calls f(ctx, m). -func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error { - return f(ctx, tx) -} - -// Commit commits the transaction. -func (tx *Tx) Commit() error { - txDriver := tx.config.driver.(*txDriver) - var fn Committer = CommitFunc(func(context.Context, *Tx) error { - return txDriver.tx.Commit() - }) - tx.mu.Lock() - hooks := append([]CommitHook(nil), tx.onCommit...) - tx.mu.Unlock() - for i := len(hooks) - 1; i >= 0; i-- { - fn = hooks[i](fn) - } - return fn.Commit(tx.ctx, tx) -} - -// OnCommit adds a hook to call on commit. -func (tx *Tx) OnCommit(f CommitHook) { - tx.mu.Lock() - defer tx.mu.Unlock() - tx.onCommit = append(tx.onCommit, f) -} - -type ( - // Rollbacker is the interface that wraps the Rollbacker method. - Rollbacker interface { - Rollback(context.Context, *Tx) error - } - - // The RollbackFunc type is an adapter to allow the use of ordinary - // function as a Rollbacker. If f is a function with the appropriate - // signature, RollbackFunc(f) is a Rollbacker that calls f. - RollbackFunc func(context.Context, *Tx) error - - // RollbackHook defines the "rollback middleware". A function that gets a Rollbacker - // and returns a Rollbacker. For example: - // - // hook := func(next ent.Rollbacker) ent.Rollbacker { - // return ent.RollbackFunc(func(context.Context, tx *ent.Tx) error { - // // Do some stuff before. - // if err := next.Rollback(ctx, tx); err != nil { - // return err - // } - // // Do some stuff after. - // return nil - // }) - // } - // - RollbackHook func(Rollbacker) Rollbacker -) - -// Rollback calls f(ctx, m). -func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error { - return f(ctx, tx) -} - -// Rollback rollbacks the transaction. -func (tx *Tx) Rollback() error { - txDriver := tx.config.driver.(*txDriver) - var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { - return txDriver.tx.Rollback() - }) - tx.mu.Lock() - hooks := append([]RollbackHook(nil), tx.onRollback...) - tx.mu.Unlock() - for i := len(hooks) - 1; i >= 0; i-- { - fn = hooks[i](fn) - } - return fn.Rollback(tx.ctx, tx) -} - -// OnRollback adds a hook to call on rollback. -func (tx *Tx) OnRollback(f RollbackHook) { - tx.mu.Lock() - defer tx.mu.Unlock() - tx.onRollback = append(tx.onRollback, f) -} - -// Client returns a Client that binds to current transaction. -func (tx *Tx) Client() *Client { - tx.clientOnce.Do(func() { - tx.client = &Client{config: tx.config} - tx.client.init() - }) - return tx.client -} - -func (tx *Tx) init() { - tx.Article = NewArticleClient(tx.config) - tx.Comment = NewCommentClient(tx.config) - tx.Tag = NewTagClient(tx.config) -} - -// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. -// The idea is to support transactions without adding any extra code to the builders. -// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. -// Commit and Rollback are nop for the internal builders and the user must call one -// of them in order to commit or rollback the transaction. -// -// If a closed transaction is embedded in one of the generated entities, and the entity -// applies a query, for example: Article.QueryXXX(), the query will be executed -// through the driver which created this transaction. -// -// Note that txDriver is not goroutine safe. -type txDriver struct { - // the driver we started the transaction from. - drv dialect.Driver - // tx is the underlying transaction. - tx dialect.Tx -} - -// newTx creates a new transactional driver. -func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { - tx, err := drv.Tx(ctx) - if err != nil { - return nil, err - } - return &txDriver{tx: tx, drv: drv}, nil -} - -// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls -// from the internal builders. Should be called only by the internal builders. -func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } - -// Dialect returns the dialect of the driver we started the transaction from. -func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } - -// Close is a nop close. -func (*txDriver) Close() error { return nil } - -// Commit is a nop commit for the internal builders. -// User must call `Tx.Commit` in order to commit the transaction. -func (*txDriver) Commit() error { return nil } - -// Rollback is a nop rollback for the internal builders. -// User must call `Tx.Rollback` in order to rollback the transaction. -func (*txDriver) Rollback() error { return nil } - -// Exec calls tx.Exec. -func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error { - return tx.tx.Exec(ctx, query, args, v) -} - -// Query calls tx.Query. -func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error { - return tx.tx.Query(ctx, query, args, v) -} - -var _ dialect.Driver = (*txDriver)(nil) diff --git a/examples/blog/internal/data/redis.go b/examples/blog/internal/data/redis.go deleted file mode 100644 index 3bbffa9a6..000000000 --- a/examples/blog/internal/data/redis.go +++ /dev/null @@ -1,26 +0,0 @@ -package data - -import ( - "context" - "fmt" - - "github.com/go-redis/redis/v8" -) - -func likeKey(id int64) string { - return fmt.Sprintf("like:%d", id) -} - -func (ar *articleRepo) GetArticleLike(ctx context.Context, id int64) (rv int64, err error) { - get := ar.data.rdb.Get(ctx, likeKey(id)) - rv, err = get.Int64() - if err == redis.Nil { - return 0, nil - } - return -} - -func (ar *articleRepo) IncArticleLike(ctx context.Context, id int64) error { - _, err := ar.data.rdb.Incr(ctx, likeKey(id)).Result() - return err -} diff --git a/examples/blog/internal/server/grpc.go b/examples/blog/internal/server/grpc.go deleted file mode 100644 index 4bf89fab7..000000000 --- a/examples/blog/internal/server/grpc.go +++ /dev/null @@ -1,37 +0,0 @@ -package server - -import ( - v1 "github.com/go-kratos/kratos/examples/blog/api/blog/v1" - "github.com/go-kratos/kratos/examples/blog/internal/conf" - "github.com/go-kratos/kratos/examples/blog/internal/service" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/middleware/tracing" - "github.com/go-kratos/kratos/v2/middleware/validate" - "github.com/go-kratos/kratos/v2/transport/grpc" -) - -// NewGRPCServer new a gRPC server. -func NewGRPCServer(c *conf.Server, logger log.Logger, blog *service.BlogService) *grpc.Server { - opts := []grpc.ServerOption{ - grpc.Middleware( - recovery.Recovery(), - tracing.Server(), - logging.Server(logger), - validate.Validator(), - ), - } - if c.Grpc.Network != "" { - opts = append(opts, grpc.Network(c.Grpc.Network)) - } - if c.Grpc.Addr != "" { - opts = append(opts, grpc.Address(c.Grpc.Addr)) - } - if c.Grpc.Timeout != nil { - opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) - } - srv := grpc.NewServer(opts...) - v1.RegisterBlogServiceServer(srv, blog) - return srv -} diff --git a/examples/blog/internal/server/http.go b/examples/blog/internal/server/http.go deleted file mode 100644 index f17a882ce..000000000 --- a/examples/blog/internal/server/http.go +++ /dev/null @@ -1,37 +0,0 @@ -package server - -import ( - v1 "github.com/go-kratos/kratos/examples/blog/api/blog/v1" - "github.com/go-kratos/kratos/examples/blog/internal/conf" - "github.com/go-kratos/kratos/examples/blog/internal/service" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/middleware/tracing" - "github.com/go-kratos/kratos/v2/middleware/validate" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// NewHTTPServer new a HTTP server. -func NewHTTPServer(c *conf.Server, logger log.Logger, blog *service.BlogService) *http.Server { - opts := []http.ServerOption{ - http.Middleware( - recovery.Recovery(), - tracing.Server(), - logging.Server(logger), - validate.Validator(), - ), - } - if c.Http.Network != "" { - opts = append(opts, http.Network(c.Http.Network)) - } - if c.Http.Addr != "" { - opts = append(opts, http.Address(c.Http.Addr)) - } - if c.Http.Timeout != nil { - opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration())) - } - srv := http.NewServer(opts...) - v1.RegisterBlogServiceHTTPServer(srv, blog) - return srv -} diff --git a/examples/blog/internal/server/server.go b/examples/blog/internal/server/server.go deleted file mode 100644 index 4d267a7a3..000000000 --- a/examples/blog/internal/server/server.go +++ /dev/null @@ -1,8 +0,0 @@ -package server - -import ( - "github.com/google/wire" -) - -// ProviderSet is server providers. -var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer) diff --git a/examples/blog/internal/service/README.md b/examples/blog/internal/service/README.md deleted file mode 100644 index 42321b7b1..000000000 --- a/examples/blog/internal/service/README.md +++ /dev/null @@ -1 +0,0 @@ -# Service diff --git a/examples/blog/internal/service/article.go b/examples/blog/internal/service/article.go deleted file mode 100644 index fd16fd070..000000000 --- a/examples/blog/internal/service/article.go +++ /dev/null @@ -1,67 +0,0 @@ -package service - -import ( - "context" - - "go.opentelemetry.io/otel" - - pb "github.com/go-kratos/kratos/examples/blog/api/blog/v1" - "github.com/go-kratos/kratos/examples/blog/internal/biz" - - "github.com/go-kratos/kratos/v2/log" -) - -func NewBlogService(article *biz.ArticleUsecase, logger log.Logger) *BlogService { - return &BlogService{ - article: article, - log: log.NewHelper(logger), - } -} - -func (s *BlogService) CreateArticle(ctx context.Context, req *pb.CreateArticleRequest) (*pb.CreateArticleReply, error) { - s.log.Infof("input data %v", req) - err := s.article.Create(ctx, &biz.Article{ - Title: req.Title, - Content: req.Content, - }) - return &pb.CreateArticleReply{}, err -} - -func (s *BlogService) UpdateArticle(ctx context.Context, req *pb.UpdateArticleRequest) (*pb.UpdateArticleReply, error) { - s.log.Infof("input data %v", req) - err := s.article.Update(ctx, req.Id, &biz.Article{ - Title: req.Title, - Content: req.Content, - }) - return &pb.UpdateArticleReply{}, err -} - -func (s *BlogService) DeleteArticle(ctx context.Context, req *pb.DeleteArticleRequest) (*pb.DeleteArticleReply, error) { - s.log.Infof("input data %v", req) - err := s.article.Delete(ctx, req.Id) - return &pb.DeleteArticleReply{}, err -} - -func (s *BlogService) GetArticle(ctx context.Context, req *pb.GetArticleRequest) (*pb.GetArticleReply, error) { - tr := otel.Tracer("api") - ctx, span := tr.Start(ctx, "GetArticle") - defer span.End() - p, err := s.article.Get(ctx, req.Id) - if err != nil { - return nil, err - } - return &pb.GetArticleReply{Article: &pb.Article{Id: p.ID, Title: p.Title, Content: p.Content, Like: p.Like}}, nil -} - -func (s *BlogService) ListArticle(ctx context.Context, req *pb.ListArticleRequest) (*pb.ListArticleReply, error) { - ps, err := s.article.List(ctx) - reply := &pb.ListArticleReply{} - for _, p := range ps { - reply.Results = append(reply.Results, &pb.Article{ - Id: p.ID, - Title: p.Title, - Content: p.Content, - }) - } - return reply, err -} diff --git a/examples/blog/internal/service/service.go b/examples/blog/internal/service/service.go deleted file mode 100644 index a66aea1ab..000000000 --- a/examples/blog/internal/service/service.go +++ /dev/null @@ -1,20 +0,0 @@ -package service - -import ( - pb "github.com/go-kratos/kratos/examples/blog/api/blog/v1" - "github.com/go-kratos/kratos/examples/blog/internal/biz" - - "github.com/go-kratos/kratos/v2/log" - "github.com/google/wire" -) - -// ProviderSet is service providers. -var ProviderSet = wire.NewSet(NewBlogService) - -type BlogService struct { - pb.UnimplementedBlogServiceServer - - log *log.Helper - - article *biz.ArticleUsecase -} diff --git a/examples/blog/openapi.yaml b/examples/blog/openapi.yaml deleted file mode 100644 index c4afd3ba2..000000000 --- a/examples/blog/openapi.yaml +++ /dev/null @@ -1,126 +0,0 @@ -# Generated with protoc-gen-openapi -# https://github.com/google/gnostic/tree/master/apps/protoc-gen-openapi - -openapi: 3.0.3 -info: - title: BlogService - version: 0.0.1 -paths: - /v1/article/: - get: - operationId: BlogService_ListArticle - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ListArticleReply' - post: - operationId: BlogService_CreateArticle - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CreateArticleRequest' - required: true - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateArticleReply' - /v1/article/{id}: - get: - operationId: BlogService_GetArticle - parameters: - - name: id - in: query - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/GetArticleReply' - put: - operationId: BlogService_UpdateArticle - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/UpdateArticleRequest' - required: true - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/UpdateArticleReply' - delete: - operationId: BlogService_DeleteArticle - parameters: - - name: id - in: query - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/DeleteArticleReply' -components: - schemas: - Article: - properties: - id: - type: integer - format: int64 - title: - type: string - content: - type: string - like: - type: integer - format: int64 - CreateArticleReply: - properties: - Article: - $ref: '#/components/schemas/Article' - CreateArticleRequest: - properties: - title: - type: string - content: - type: string - DeleteArticleReply: - properties: {} - GetArticleReply: - properties: - Article: - $ref: '#/components/schemas/Article' - ListArticleReply: - properties: - results: - type: array - items: - $ref: '#/components/schemas/Article' - UpdateArticleReply: - properties: - Article: - $ref: '#/components/schemas/Article' - UpdateArticleRequest: - properties: - id: - type: integer - format: int64 - title: - type: string - content: - type: string diff --git a/examples/config/apollo/README.md b/examples/config/apollo/README.md deleted file mode 100644 index e23004bb6..000000000 --- a/examples/config/apollo/README.md +++ /dev/null @@ -1,10 +0,0 @@ -### Profiles -examples/config/apollo is apollo config example. -You can deploy Apollo yourself or use docker compose in example to start Apollo, -then modify the configuration in the code to your actual Apollo configuration, -and run the program - -### Sample account - -Account: `apollo` -Password: `admin` \ No newline at end of file diff --git a/examples/config/apollo/docker-quick-start/docker-compose.yml b/examples/config/apollo/docker-quick-start/docker-compose.yml deleted file mode 100644 index a6c38d6e6..000000000 --- a/examples/config/apollo/docker-quick-start/docker-compose.yml +++ /dev/null @@ -1,50 +0,0 @@ -# -# Copyright 2021 Apollo Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -version: '2' - -services: - apollo-quick-start: - image: nobodyiam/apollo-quick-start - container_name: apollo-quick-start - depends_on: - - apollo-db - ports: - - "8080:8080" - - "8090:8090" - - "8070:8070" - links: - - apollo-db - - apollo-db: - image: mysql:5.7 - container_name: apollo-db - environment: - TZ: Asia/Shanghai - MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' - depends_on: - - apollo-dbdata - ports: - - "13306:3306" - volumes: - - ./sql:/docker-entrypoint-initdb.d - volumes_from: - - apollo-dbdata - - apollo-dbdata: - image: alpine:latest - container_name: apollo-dbdata - volumes: - - /var/lib/mysql \ No newline at end of file diff --git a/examples/config/apollo/docker-quick-start/sql/apolloconfigdb.sql b/examples/config/apollo/docker-quick-start/sql/apolloconfigdb.sql deleted file mode 100644 index eccac3c34..000000000 --- a/examples/config/apollo/docker-quick-start/sql/apolloconfigdb.sql +++ /dev/null @@ -1,448 +0,0 @@ --- --- Copyright 2021 Apollo Authors --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - -# Create Database -# ------------------------------------------------------------ -CREATE DATABASE IF NOT EXISTS ApolloConfigDB DEFAULT CHARACTER SET = utf8mb4; - -Use ApolloConfigDB; - -# Dump of table app -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `App`; - -CREATE TABLE `App` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', - `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', - `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', - `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', - `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', - `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', - `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `AppId` (`AppId`(191)), - KEY `DataChange_LastTime` (`DataChange_LastTime`), - KEY `IX_Name` (`Name`(191)) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用表'; - - - -# Dump of table appnamespace -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `AppNamespace`; - -CREATE TABLE `AppNamespace` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', - `Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', - `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'app id', - `Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', - `IsPublic` bit(1) NOT NULL DEFAULT b'0' COMMENT 'namespace是否为公共', - `Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_AppId` (`AppId`), - KEY `Name_AppId` (`Name`,`AppId`), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用namespace定义'; - - - -# Dump of table audit -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Audit`; - -CREATE TABLE `Audit` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', - `EntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', - `EntityId` int(10) unsigned DEFAULT NULL COMMENT '记录ID', - `OpName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', - `Comment` varchar(500) DEFAULT NULL COMMENT '备注', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='日志审计表'; - - - -# Dump of table cluster -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Cluster`; - -CREATE TABLE `Cluster` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', - `Name` varchar(32) NOT NULL DEFAULT '' COMMENT '集群名字', - `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'App id', - `ParentClusterId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父cluster', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_AppId_Name` (`AppId`,`Name`), - KEY `IX_ParentClusterId` (`ParentClusterId`), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='集群'; - - - -# Dump of table commit -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Commit`; - -CREATE TABLE `Commit` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', - `ChangeSets` longtext NOT NULL COMMENT '修改变更集', - `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', - `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', - `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', - `Comment` varchar(500) DEFAULT NULL COMMENT '备注', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `DataChange_LastTime` (`DataChange_LastTime`), - KEY `AppId` (`AppId`(191)), - KEY `ClusterName` (`ClusterName`(191)), - KEY `NamespaceName` (`NamespaceName`(191)) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='commit 历史表'; - -# Dump of table grayreleaserule -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `GrayReleaseRule`; - -CREATE TABLE `GrayReleaseRule` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', - `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', - `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', - `NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', - `BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'branch name', - `Rules` varchar(16000) DEFAULT '[]' COMMENT '灰度规则', - `ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '灰度对应的release', - `BranchStatus` tinyint(2) DEFAULT '1' COMMENT '灰度分支状态: 0:删除分支,1:正在使用的规则 2:全量发布', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `DataChange_LastTime` (`DataChange_LastTime`), - KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='灰度规则表'; - - -# Dump of table instance -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Instance`; - -CREATE TABLE `Instance` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', - `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', - `DataCenter` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Data Center Name', - `Ip` varchar(32) NOT NULL DEFAULT '' COMMENT 'instance ip', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - UNIQUE KEY `IX_UNIQUE_KEY` (`AppId`,`ClusterName`,`Ip`,`DataCenter`), - KEY `IX_IP` (`Ip`), - KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='使用配置的应用实例'; - - - -# Dump of table instanceconfig -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `InstanceConfig`; - -CREATE TABLE `InstanceConfig` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `InstanceId` int(11) unsigned DEFAULT NULL COMMENT 'Instance Id', - `ConfigAppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Config App Id', - `ConfigClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Cluster Name', - `ConfigNamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Namespace Name', - `ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', - `ReleaseDeliveryTime` timestamp NULL DEFAULT NULL COMMENT '配置获取时间', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - UNIQUE KEY `IX_UNIQUE_KEY` (`InstanceId`,`ConfigAppId`,`ConfigNamespaceName`), - KEY `IX_ReleaseKey` (`ReleaseKey`), - KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), - KEY `IX_Valid_Namespace` (`ConfigAppId`,`ConfigClusterName`,`ConfigNamespaceName`,`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用实例的配置信息'; - - - -# Dump of table item -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Item`; - -CREATE TABLE `Item` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', - `Key` varchar(128) NOT NULL DEFAULT 'default' COMMENT '配置项Key', - `Value` longtext NOT NULL COMMENT '配置项值', - `Comment` varchar(1024) DEFAULT '' COMMENT '注释', - `LineNum` int(10) unsigned DEFAULT '0' COMMENT '行号', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_GroupId` (`NamespaceId`), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置项目'; - - - -# Dump of table namespace -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Namespace`; - -CREATE TABLE `Namespace` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', - `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', - `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', - `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `AppId_ClusterName_NamespaceName` (`AppId`(191),`ClusterName`(191),`NamespaceName`(191)), - KEY `DataChange_LastTime` (`DataChange_LastTime`), - KEY `IX_NamespaceName` (`NamespaceName`(191)) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='命名空间'; - - - -# Dump of table namespacelock -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `NamespaceLock`; - -CREATE TABLE `NamespaceLock` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id', - `NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - `IsDeleted` bit(1) DEFAULT b'0' COMMENT '软删除', - PRIMARY KEY (`Id`), - UNIQUE KEY `IX_NamespaceId` (`NamespaceId`), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='namespace的编辑锁'; - - - -# Dump of table release -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Release`; - -CREATE TABLE `Release` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', - `ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', - `Name` varchar(64) NOT NULL DEFAULT 'default' COMMENT '发布名字', - `Comment` varchar(256) DEFAULT NULL COMMENT '发布说明', - `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', - `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', - `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', - `Configurations` longtext NOT NULL COMMENT '发布配置', - `IsAbandoned` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否废弃', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `AppId_ClusterName_GroupName` (`AppId`(191),`ClusterName`(191),`NamespaceName`(191)), - KEY `DataChange_LastTime` (`DataChange_LastTime`), - KEY `IX_ReleaseKey` (`ReleaseKey`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布'; - - -# Dump of table releasehistory -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `ReleaseHistory`; - -CREATE TABLE `ReleaseHistory` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', - `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', - `NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', - `BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT '发布分支名', - `ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关联的Release Id', - `PreviousReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '前一次发布的ReleaseId', - `Operation` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '发布类型,0: 普通发布,1: 回滚,2: 灰度发布,3: 灰度规则更新,4: 灰度合并回主分支发布,5: 主分支发布灰度自动发布,6: 主分支回滚灰度自动发布,7: 放弃灰度', - `OperationContext` longtext NOT NULL COMMENT '发布上下文信息', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`,`BranchName`), - KEY `IX_ReleaseId` (`ReleaseId`), - KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布历史'; - - -# Dump of table releasemessage -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `ReleaseMessage`; - -CREATE TABLE `ReleaseMessage` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', - `Message` varchar(1024) NOT NULL DEFAULT '' COMMENT '发布的消息内容', - `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `DataChange_LastTime` (`DataChange_LastTime`), - KEY `IX_Message` (`Message`(191)) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布消息'; - - - -# Dump of table serverconfig -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `ServerConfig`; - -CREATE TABLE `ServerConfig` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', - `Cluster` varchar(32) NOT NULL DEFAULT 'default' COMMENT '配置对应的集群,default为不针对特定的集群', - `Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', - `Comment` varchar(1024) DEFAULT '' COMMENT '注释', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_Key` (`Key`), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置服务自身配置'; - -# Dump of table accesskey -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `AccessKey`; - -CREATE TABLE `AccessKey` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', - `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', - `Secret` varchar(128) NOT NULL DEFAULT '' COMMENT 'Secret', - `IsEnabled` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: enabled, 0: disabled', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `AppId` (`AppId`(191)), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='访问密钥'; - -# Config -# ------------------------------------------------------------ -INSERT INTO `ServerConfig` (`Key`, `Cluster`, `Value`, `Comment`) -VALUES - ('eureka.service.url', 'default', 'http://localhost:8080/eureka/', 'Eureka服务Url,多个service以英文逗号分隔'), - ('namespace.lock.switch', 'default', 'false', '一次发布只能有一个人修改开关'), - ('item.value.length.limit', 'default', '20000', 'item value最大长度限制'), - ('config-service.cache.enabled', 'default', 'false', 'ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!'), - ('item.key.length.limit', 'default', '128', 'item key 最大长度限制'); - -# Sample Data -# ------------------------------------------------------------ -INSERT INTO `App` (`AppId`, `Name`, `OrgId`, `OrgName`, `OwnerName`, `OwnerEmail`) -VALUES - ('SampleApp', 'Sample App', 'TEST1', '样例部门1', 'apollo', 'apollo@acme.com'); - -INSERT INTO `AppNamespace` (`Name`, `AppId`, `Format`, `IsPublic`, `Comment`) -VALUES - ('application', 'SampleApp', 'properties', 0, 'default app namespace'); - -INSERT INTO `Cluster` (`Name`, `AppId`) -VALUES - ('default', 'SampleApp'); - -INSERT INTO `Namespace` (`Id`, `AppId`, `ClusterName`, `NamespaceName`) -VALUES - (1, 'SampleApp', 'default', 'application'); - - -INSERT INTO `Item` (`NamespaceId`, `Key`, `Value`, `Comment`, `LineNum`) -VALUES - (1, 'timeout', '100', 'sample timeout配置', 1); - -INSERT INTO `Release` (`ReleaseKey`, `Name`, `Comment`, `AppId`, `ClusterName`, `NamespaceName`, `Configurations`) -VALUES - ('20161009155425-d3a0749c6e20bc15', '20161009155424-release', 'Sample发布', 'SampleApp', 'default', 'application', '{\"timeout\":\"100\"}'); - -INSERT INTO `ReleaseHistory` (`AppId`, `ClusterName`, `NamespaceName`, `BranchName`, `ReleaseId`, `PreviousReleaseId`, `Operation`, `OperationContext`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`) -VALUES - ('SampleApp', 'default', 'application', 'default', 1, 0, 0, '{}', 'apollo', 'apollo'); - -INSERT INTO `ReleaseMessage` (`Message`) -VALUES - ('SampleApp+default+application'); - -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; \ No newline at end of file diff --git a/examples/config/apollo/docker-quick-start/sql/apolloportaldb.sql b/examples/config/apollo/docker-quick-start/sql/apolloportaldb.sql deleted file mode 100644 index bba52afe2..000000000 --- a/examples/config/apollo/docker-quick-start/sql/apolloportaldb.sql +++ /dev/null @@ -1,408 +0,0 @@ --- --- Copyright 2021 Apollo Authors --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - -# Create Database -# ------------------------------------------------------------ -CREATE DATABASE IF NOT EXISTS ApolloPortalDB DEFAULT CHARACTER SET = utf8mb4; - -Use ApolloPortalDB; - -# Dump of table app -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `App`; - -CREATE TABLE `App` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', - `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', - `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', - `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', - `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', - `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', - `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `AppId` (`AppId`(191)), - KEY `DataChange_LastTime` (`DataChange_LastTime`), - KEY `IX_Name` (`Name`(191)) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用表'; - - - -# Dump of table appnamespace -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `AppNamespace`; - -CREATE TABLE `AppNamespace` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', - `Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', - `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'app id', - `Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', - `IsPublic` bit(1) NOT NULL DEFAULT b'0' COMMENT 'namespace是否为公共', - `Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_AppId` (`AppId`), - KEY `Name_AppId` (`Name`,`AppId`), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用namespace定义'; - - - -# Dump of table consumer -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Consumer`; - -CREATE TABLE `Consumer` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', - `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', - `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', - `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', - `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', - `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `AppId` (`AppId`(191)), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='开放API消费者'; - - - -# Dump of table consumeraudit -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `ConsumerAudit`; - -CREATE TABLE `ConsumerAudit` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', - `Uri` varchar(1024) NOT NULL DEFAULT '' COMMENT '访问的Uri', - `Method` varchar(16) NOT NULL DEFAULT '' COMMENT '访问的Method', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), - KEY `IX_ConsumerId` (`ConsumerId`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer审计表'; - - - -# Dump of table consumerrole -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `ConsumerRole`; - -CREATE TABLE `ConsumerRole` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', - `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), - KEY `IX_RoleId` (`RoleId`), - KEY `IX_ConsumerId_RoleId` (`ConsumerId`,`RoleId`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer和role的绑定表'; - - - -# Dump of table consumertoken -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `ConsumerToken`; - -CREATE TABLE `ConsumerToken` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'ConsumerId', - `Token` varchar(128) NOT NULL DEFAULT '' COMMENT 'token', - `Expires` datetime NOT NULL DEFAULT '2099-01-01 00:00:00' COMMENT 'token失效时间', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - UNIQUE KEY `IX_Token` (`Token`), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer token表'; - -# Dump of table favorite -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Favorite`; - -CREATE TABLE `Favorite` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', - `UserId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '收藏的用户', - `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', - `Position` int(32) NOT NULL DEFAULT '10000' COMMENT '收藏顺序', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `AppId` (`AppId`(191)), - KEY `IX_UserId` (`UserId`), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COMMENT='应用收藏表'; - -# Dump of table permission -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Permission`; - -CREATE TABLE `Permission` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `PermissionType` varchar(32) NOT NULL DEFAULT '' COMMENT '权限类型', - `TargetId` varchar(256) NOT NULL DEFAULT '' COMMENT '权限对象类型', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_TargetId_PermissionType` (`TargetId`(191),`PermissionType`), - KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='permission表'; - - - -# Dump of table role -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Role`; - -CREATE TABLE `Role` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `RoleName` varchar(256) NOT NULL DEFAULT '' COMMENT 'Role name', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_RoleName` (`RoleName`(191)), - KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色表'; - - - -# Dump of table rolepermission -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `RolePermission`; - -CREATE TABLE `RolePermission` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', - `PermissionId` int(10) unsigned DEFAULT NULL COMMENT 'Permission Id', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), - KEY `IX_RoleId` (`RoleId`), - KEY `IX_PermissionId` (`PermissionId`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色和权限的绑定表'; - - - -# Dump of table serverconfig -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `ServerConfig`; - -CREATE TABLE `ServerConfig` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', - `Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', - `Comment` varchar(1024) DEFAULT '' COMMENT '注释', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_Key` (`Key`), - KEY `DataChange_LastTime` (`DataChange_LastTime`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置服务自身配置'; - - - -# Dump of table userrole -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `UserRole`; - -CREATE TABLE `UserRole` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `UserId` varchar(128) DEFAULT '' COMMENT '用户身份标识', - `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', - `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', - `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', - `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', - `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', - PRIMARY KEY (`Id`), - KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), - KEY `IX_RoleId` (`RoleId`), - KEY `IX_UserId_RoleId` (`UserId`,`RoleId`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户和role的绑定表'; - -# Dump of table Users -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Users`; - -CREATE TABLE `Users` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `Username` varchar(64) NOT NULL DEFAULT 'default' COMMENT '用户登录账户', - `Password` varchar(512) NOT NULL DEFAULT 'default' COMMENT '密码', - `UserDisplayName` varchar(512) NOT NULL DEFAULT 'default' COMMENT '用户名称', - `Email` varchar(64) NOT NULL DEFAULT 'default' COMMENT '邮箱地址', - `Enabled` tinyint(4) DEFAULT NULL COMMENT '是否有效', - PRIMARY KEY (`Id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; - - -# Dump of table Authorities -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Authorities`; - -CREATE TABLE `Authorities` ( - `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', - `Username` varchar(64) NOT NULL, - `Authority` varchar(50) NOT NULL, - PRIMARY KEY (`Id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - - -# Config -# ------------------------------------------------------------ -INSERT INTO `ServerConfig` (`Key`, `Value`, `Comment`) -VALUES - ('apollo.portal.envs', 'dev', '可支持的环境列表'), - ('organizations', '[{\"orgId\":\"TEST1\",\"orgName\":\"样例部门1\"},{\"orgId\":\"TEST2\",\"orgName\":\"样例部门2\"}]', '部门列表'), - ('superAdmin', 'apollo', 'Portal超级管理员'), - ('api.readTimeout', '10000', 'http接口read timeout'), - ('consumer.token.salt', 'someSalt', 'consumer token salt'), - ('admin.createPrivateNamespace.switch', 'true', '是否允许项目管理员创建私有namespace'), - ('configView.memberOnly.envs', 'dev', '只对项目成员显示配置信息的环境列表,多个env以英文逗号分隔'), - ('apollo.portal.meta.servers', '{}', '各环境Meta Service列表'); - -INSERT INTO `Users` (`Username`, `Password`, `UserDisplayName`, `Email`, `Enabled`) -VALUES - ('apollo', '$2a$10$7r20uS.BQ9uBpf3Baj3uQOZvMVvB1RN3PYoKE94gtz2.WAOuiiwXS', 'apollo', 'apollo@acme.com', 1); - -INSERT INTO `Authorities` (`Username`, `Authority`) VALUES ('apollo', 'ROLE_user'); - -# Sample Data -# ------------------------------------------------------------ -INSERT INTO `App` (`AppId`, `Name`, `OrgId`, `OrgName`, `OwnerName`, `OwnerEmail`) -VALUES - ('SampleApp', 'Sample App', 'TEST1', '样例部门1', 'apollo', 'apollo@acme.com'); - -INSERT INTO `AppNamespace` (`Name`, `AppId`, `Format`, `IsPublic`, `Comment`) -VALUES - ('application', 'SampleApp', 'properties', 0, 'default app namespace'); - -INSERT INTO `Permission` (`Id`, `PermissionType`, `TargetId`) -VALUES - (1, 'CreateCluster', 'SampleApp'), - (2, 'CreateNamespace', 'SampleApp'), - (3, 'AssignRole', 'SampleApp'), - (4, 'ModifyNamespace', 'SampleApp+application'), - (5, 'ReleaseNamespace', 'SampleApp+application'); - -INSERT INTO `Role` (`Id`, `RoleName`) -VALUES - (1, 'Master+SampleApp'), - (2, 'ModifyNamespace+SampleApp+application'), - (3, 'ReleaseNamespace+SampleApp+application'); - -INSERT INTO `RolePermission` (`RoleId`, `PermissionId`) -VALUES - (1, 1), - (1, 2), - (1, 3), - (2, 4), - (3, 5); - -INSERT INTO `UserRole` (`UserId`, `RoleId`) -VALUES - ('apollo', 1), - ('apollo', 2), - ('apollo', 3); - --- spring session (https://github.com/spring-projects/spring-session/blob/faee8f1bdb8822a5653a81eba838dddf224d92d6/spring-session-jdbc/src/main/resources/org/springframework/session/jdbc/schema-mysql.sql) -CREATE TABLE SPRING_SESSION ( - PRIMARY_ID CHAR(36) NOT NULL, - SESSION_ID CHAR(36) NOT NULL, - CREATION_TIME BIGINT NOT NULL, - LAST_ACCESS_TIME BIGINT NOT NULL, - MAX_INACTIVE_INTERVAL INT NOT NULL, - EXPIRY_TIME BIGINT NOT NULL, - PRINCIPAL_NAME VARCHAR(100), - CONSTRAINT SPRING_SESSION_PK PRIMARY KEY (PRIMARY_ID) -) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; - -CREATE UNIQUE INDEX SPRING_SESSION_IX1 ON SPRING_SESSION (SESSION_ID); -CREATE INDEX SPRING_SESSION_IX2 ON SPRING_SESSION (EXPIRY_TIME); -CREATE INDEX SPRING_SESSION_IX3 ON SPRING_SESSION (PRINCIPAL_NAME); - -CREATE TABLE SPRING_SESSION_ATTRIBUTES ( - SESSION_PRIMARY_ID CHAR(36) NOT NULL, - ATTRIBUTE_NAME VARCHAR(200) NOT NULL, - ATTRIBUTE_BYTES BLOB NOT NULL, - CONSTRAINT SPRING_SESSION_ATTRIBUTES_PK PRIMARY KEY (SESSION_PRIMARY_ID, ATTRIBUTE_NAME), - CONSTRAINT SPRING_SESSION_ATTRIBUTES_FK FOREIGN KEY (SESSION_PRIMARY_ID) REFERENCES SPRING_SESSION(PRIMARY_ID) ON DELETE CASCADE -) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; - -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; \ No newline at end of file diff --git a/examples/config/apollo/main.go b/examples/config/apollo/main.go deleted file mode 100644 index 90efd83a4..000000000 --- a/examples/config/apollo/main.go +++ /dev/null @@ -1,81 +0,0 @@ -package main - -import ( - "fmt" - "log" - - _ "github.com/go-kratos/kratos/v2/encoding/json" - _ "github.com/go-kratos/kratos/v2/encoding/yaml" - - "github.com/go-kratos/kratos/contrib/config/apollo/v2" - "github.com/go-kratos/kratos/v2/config" -) - -type bootstrap struct { - Application struct { - Name string `json:"name"` - Version string `json:"version"` - } `json:"application"` - - Event struct { - Key string `json:"key"` - Array []string `json:"array"` - } `json:"event"` - - Demo struct { - Deep struct { - Key string `json:"key"` - Value string `json:"value"` - } `json:"deep"` - } `json:"demo"` -} - -func main() { - c := config.New( - config.WithSource( - apollo.NewSource( - apollo.WithAppID("kratos"), - apollo.WithCluster("dev"), - apollo.WithEndpoint("http://localhost:8080"), - apollo.WithNamespace("application,event.yaml,demo.json"), - apollo.WithEnableBackup(), - apollo.WithSecret("ad75b33c77ae4b9c9626d969c44f41ee"), - ), - ), - ) - var bc bootstrap - if err := c.Load(); err != nil { - panic(err) - } - - scan(c, &bc) - - value(c, "application") - value(c, "application.name") - value(c, "event.array") - value(c, "demo.deep") - - watch(c, "application") - <-make(chan struct{}) -} - -func scan(c config.Config, bc *bootstrap) { - err := c.Scan(bc) - fmt.Printf("=========== scan result =============\n") - fmt.Printf("err: %v\n", err) - fmt.Printf("cfg: %+v\n\n", bc) -} - -func value(c config.Config, key string) { - fmt.Printf("=========== value result =============\n") - v := c.Value(key).Load() - fmt.Printf("key=%s, load: %+v\n\n", key, v) -} - -func watch(c config.Config, key string) { - if err := c.Watch(key, func(key string, value config.Value) { - log.Printf("config(key=%s) changed: %s\n", key, value.Load()) - }); err != nil { - panic(err) - } -} diff --git a/examples/config/config.yaml b/examples/config/config.yaml deleted file mode 100644 index 6c5f8d850..000000000 --- a/examples/config/config.yaml +++ /dev/null @@ -1,11 +0,0 @@ -service: - name: config - version: v1.0.0 -http: - server: - address: 0.0.0.0:8000 - timeout: 1s -grpc: - server: - address: 0.0.0.0:9000 - timeout: 1s diff --git a/examples/config/main.go b/examples/config/main.go deleted file mode 100644 index 4d69bd50f..000000000 --- a/examples/config/main.go +++ /dev/null @@ -1,57 +0,0 @@ -package main - -import ( - "flag" - "log" - - "github.com/go-kratos/kratos/v2/config" - "github.com/go-kratos/kratos/v2/config/file" -) - -var flagconf string - -func init() { - flag.StringVar(&flagconf, "conf", "config.yaml", "config path, eg: -conf config.yaml") -} - -func main() { - flag.Parse() - c := config.New( - config.WithSource( - file.NewSource(flagconf), - ), - ) - if err := c.Load(); err != nil { - panic(err) - } - - // Defines the config JSON Field - var v struct { - Service struct { - Name string `json:"name"` - Version string `json:"version"` - } `json:"service"` - } - - // Unmarshal the config to struct - if err := c.Scan(&v); err != nil { - panic(err) - } - log.Printf("config: %+v", v) - - // Get a value associated with the key - name, err := c.Value("service.name").String() - if err != nil { - panic(err) - } - log.Printf("service: %s", name) - - // watch key - if err := c.Watch("service.name", func(key string, value config.Value) { - log.Printf("config changed: %s = %v\n", key, value) - }); err != nil { - panic(err) - } - - <-make(chan struct{}) -} diff --git a/examples/config/t/a.yaml b/examples/config/t/a.yaml deleted file mode 100644 index 91a2ebf73..000000000 --- a/examples/config/t/a.yaml +++ /dev/null @@ -1,5 +0,0 @@ -foo: - baz: "2" - biu: "example" -hello: - a: b \ No newline at end of file diff --git a/examples/config/t/b.yaml b/examples/config/t/b.yaml deleted file mode 100644 index d51ff07a7..000000000 --- a/examples/config/t/b.yaml +++ /dev/null @@ -1,6 +0,0 @@ -foo: - bar: 3 - baz: aaaa -hey: - good: bad - qux: quux \ No newline at end of file diff --git a/examples/errors/api/error_reason.pb.go b/examples/errors/api/error_reason.pb.go deleted file mode 100644 index 1f850e471..000000000 --- a/examples/errors/api/error_reason.pb.go +++ /dev/null @@ -1,136 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.17.1 -// source: error_reason.proto - -package api - -import ( - _ "github.com/go-kratos/kratos/v2/errors" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type ErrorReason int32 - -const ( - ErrorReason_USER_NOT_FOUND ErrorReason = 0 - ErrorReason_CONTENT_MISSING ErrorReason = 1 -) - -// Enum value maps for ErrorReason. -var ( - ErrorReason_name = map[int32]string{ - 0: "USER_NOT_FOUND", - 1: "CONTENT_MISSING", - } - ErrorReason_value = map[string]int32{ - "USER_NOT_FOUND": 0, - "CONTENT_MISSING": 1, - } -) - -func (x ErrorReason) Enum() *ErrorReason { - p := new(ErrorReason) - *p = x - return p -} - -func (x ErrorReason) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (ErrorReason) Descriptor() protoreflect.EnumDescriptor { - return file_error_reason_proto_enumTypes[0].Descriptor() -} - -func (ErrorReason) Type() protoreflect.EnumType { - return &file_error_reason_proto_enumTypes[0] -} - -func (x ErrorReason) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use ErrorReason.Descriptor instead. -func (ErrorReason) EnumDescriptor() ([]byte, []int) { - return file_error_reason_proto_rawDescGZIP(), []int{0} -} - -var File_error_reason_proto protoreflect.FileDescriptor - -var file_error_reason_proto_rawDesc = []byte{ - 0x0a, 0x12, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x1a, 0x0c, 0x65, 0x72, - 0x72, 0x6f, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2a, 0x48, 0x0a, 0x0b, 0x45, 0x72, - 0x72, 0x6f, 0x72, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x0e, 0x55, 0x53, 0x45, - 0x52, 0x5f, 0x4e, 0x4f, 0x54, 0x5f, 0x46, 0x4f, 0x55, 0x4e, 0x44, 0x10, 0x00, 0x1a, 0x04, 0xa8, - 0x45, 0x94, 0x03, 0x12, 0x19, 0x0a, 0x0f, 0x43, 0x4f, 0x4e, 0x54, 0x45, 0x4e, 0x54, 0x5f, 0x4d, - 0x49, 0x53, 0x53, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x1a, 0x04, 0xa8, 0x45, 0x90, 0x03, 0x1a, 0x04, - 0xa0, 0x45, 0xf4, 0x03, 0x42, 0x57, 0x0a, 0x0e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x76, 0x31, 0x2e, - 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x50, 0x01, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x6b, - 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x62, - 0x6c, 0x6f, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0xa2, 0x02, 0x0d, - 0x41, 0x50, 0x49, 0x42, 0x6c, 0x6f, 0x67, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_error_reason_proto_rawDescOnce sync.Once - file_error_reason_proto_rawDescData = file_error_reason_proto_rawDesc -) - -func file_error_reason_proto_rawDescGZIP() []byte { - file_error_reason_proto_rawDescOnce.Do(func() { - file_error_reason_proto_rawDescData = protoimpl.X.CompressGZIP(file_error_reason_proto_rawDescData) - }) - return file_error_reason_proto_rawDescData -} - -var file_error_reason_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_error_reason_proto_goTypes = []interface{}{ - (ErrorReason)(0), // 0: errors.ErrorReason -} -var file_error_reason_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_error_reason_proto_init() } -func file_error_reason_proto_init() { - if File_error_reason_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_error_reason_proto_rawDesc, - NumEnums: 1, - NumMessages: 0, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_error_reason_proto_goTypes, - DependencyIndexes: file_error_reason_proto_depIdxs, - EnumInfos: file_error_reason_proto_enumTypes, - }.Build() - File_error_reason_proto = out.File - file_error_reason_proto_rawDesc = nil - file_error_reason_proto_goTypes = nil - file_error_reason_proto_depIdxs = nil -} diff --git a/examples/errors/api/error_reason.proto b/examples/errors/api/error_reason.proto deleted file mode 100644 index 37f322e19..000000000 --- a/examples/errors/api/error_reason.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; - -package errors; - -import "errors/errors.proto"; - -// 多语言特定包名,用于源代码引用 -option go_package = "github.com/go-kratos/kratos/examples/blog/api/v1;v1"; -option java_multiple_files = true; -option java_package = "blog.v1.errors"; -option objc_class_prefix = "APIBlogErrors"; - -enum ErrorReason { - option (errors.default_code) = 500; - - USER_NOT_FOUND = 0 [(errors.code) = 404]; - CONTENT_MISSING = 1 [(errors.code) = 400];; -} diff --git a/examples/errors/api/error_reason_errors.pb.go b/examples/errors/api/error_reason_errors.pb.go deleted file mode 100644 index 19190580a..000000000 --- a/examples/errors/api/error_reason_errors.pb.go +++ /dev/null @@ -1,30 +0,0 @@ -// Code generated by protoc-gen-go-errors. DO NOT EDIT. - -package api - -import ( - fmt "fmt" - errors "github.com/go-kratos/kratos/v2/errors" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the kratos package it is being compiled against. -const _ = errors.SupportPackageIsVersion1 - -func IsUserNotFound(err error) bool { - e := errors.FromError(err) - return e.Reason == ErrorReason_USER_NOT_FOUND.String() && e.Code == 404 -} - -func ErrorUserNotFound(format string, args ...interface{}) *errors.Error { - return errors.New(404, ErrorReason_USER_NOT_FOUND.String(), fmt.Sprintf(format, args...)) -} - -func IsContentMissing(err error) bool { - e := errors.FromError(err) - return e.Reason == ErrorReason_CONTENT_MISSING.String() && e.Code == 400 -} - -func ErrorContentMissing(format string, args ...interface{}) *errors.Error { - return errors.New(400, ErrorReason_CONTENT_MISSING.String(), fmt.Sprintf(format, args...)) -} diff --git a/examples/errors/client/main.go b/examples/errors/client/main.go deleted file mode 100644 index 54df1de6a..000000000 --- a/examples/errors/client/main.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - "context" - "log" - - stdhttp "net/http" - - "github.com/go-kratos/kratos/examples/errors/api" - pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/errors" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -func main() { - callHTTP() - callGRPC() -} - -func callHTTP() { - conn, err := http.NewClient( - context.Background(), - http.WithEndpoint("127.0.0.1:8000"), - ) - if err != nil { - panic(err) - } - client := pb.NewGreeterHTTPClient(conn) - reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "empty"}) - if err != nil { - if errors.Code(err) == stdhttp.StatusInternalServerError { - log.Println(err) - } - if api.IsUserNotFound(err) { - log.Println("[http] USER_NOT_FOUND_ERROR", err) - } - } else { - log.Printf("[http] SayHello %s\n", reply.Message) - } -} - -func callGRPC() { - conn, err := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("127.0.0.1:9000"), - ) - if err != nil { - panic(err) - } - client := pb.NewGreeterClient(conn) - reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "kratos"}) - if err != nil { - e := errors.FromError(err) - if e.Reason == "USER_NAME_EMPTY" && e.Code == 500 { - log.Println("[grpc] USER_NAME_EMPTY", err) - } - if api.IsUserNotFound(err) { - log.Println("[grpc] USER_NOT_FOUND_ERROR", err) - } - } else { - log.Printf("[grpc] SayHello %+v\n", reply) - } -} diff --git a/examples/errors/server/main.go b/examples/errors/server/main.go deleted file mode 100644 index 089af6c0d..000000000 --- a/examples/errors/server/main.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - - "github.com/go-kratos/kratos/examples/errors/api" - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/errors" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name = "errors" - // Version is the version of the compiled software. - // Version = "v1.0.0" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - fmt.Println(in.Name) - if in.Name == "empty" { - // Respond to errors through errors.New(). - return nil, errors.New(500, "USER_NAME_EMPTY", "user name is empty") - } - if in.Name == "kratos" { - // Respond to errors with proto generated code. - return nil, api.ErrorUserNotFound("user %s not found", "kratos") - } - return &helloworld.HelloReply{Message: fmt.Sprintf("Hello %+v", in.Name)}, nil -} - -func main() { - s := &server{} - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - ) - httpSrv := http.NewServer( - http.Address(":8000"), - ) - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - app := kratos.New( - kratos.Name(Name), - kratos.Server( - httpSrv, - grpcSrv, - ), - ) - - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/event/event/event.go b/examples/event/event/event.go deleted file mode 100644 index aed68e29e..000000000 --- a/examples/event/event/event.go +++ /dev/null @@ -1,20 +0,0 @@ -package event - -import "context" - -type Event interface { - Key() string - Value() []byte -} - -type Handler func(context.Context, Event) error - -type Sender interface { - Send(ctx context.Context, msg Event) error - Close() error -} - -type Receiver interface { - Receive(ctx context.Context, handler Handler) error - Close() error -} diff --git a/examples/event/kafka/kafka.go b/examples/event/kafka/kafka.go deleted file mode 100644 index dd4c05007..000000000 --- a/examples/event/kafka/kafka.go +++ /dev/null @@ -1,114 +0,0 @@ -package kafka - -import ( - "context" - "log" - - "github.com/go-kratos/kratos/examples/event/event" - "github.com/segmentio/kafka-go" -) - -var ( - _ event.Sender = (*kafkaSender)(nil) - _ event.Receiver = (*kafkaReceiver)(nil) - _ event.Event = (*Message)(nil) -) - -type Message struct { - key string - value []byte -} - -func (m *Message) Key() string { - return m.key -} - -func (m *Message) Value() []byte { - return m.value -} - -func NewMessage(key string, value []byte) event.Event { - return &Message{ - key: key, - value: value, - } -} - -type kafkaSender struct { - writer *kafka.Writer - topic string -} - -func (s *kafkaSender) Send(ctx context.Context, message event.Event) error { - err := s.writer.WriteMessages(ctx, kafka.Message{ - Key: []byte(message.Key()), - Value: message.Value(), - }) - if err != nil { - return err - } - return nil -} - -func (s *kafkaSender) Close() error { - err := s.writer.Close() - if err != nil { - return err - } - return nil -} - -func NewKafkaSender(address []string, topic string) (event.Sender, error) { - w := &kafka.Writer{ - Topic: topic, - Addr: kafka.TCP(address...), - Balancer: &kafka.LeastBytes{}, - } - return &kafkaSender{writer: w, topic: topic}, nil -} - -type kafkaReceiver struct { - reader *kafka.Reader - topic string -} - -func (k *kafkaReceiver) Receive(ctx context.Context, handler event.Handler) error { - go func() { - for { - m, err := k.reader.FetchMessage(context.Background()) - if err != nil { - break - } - err = handler(context.Background(), &Message{ - key: string(m.Key), - value: m.Value, - }) - if err != nil { - log.Fatal("message handling exception:", err) - } - if err := k.reader.CommitMessages(ctx, m); err != nil { - log.Fatal("failed to commit messages:", err) - } - } - }() - return nil -} - -func (k *kafkaReceiver) Close() error { - err := k.reader.Close() - if err != nil { - return err - } - return nil -} - -func NewKafkaReceiver(address []string, topic string) (event.Receiver, error) { - r := kafka.NewReader(kafka.ReaderConfig{ - Brokers: address, - GroupID: "group-a", - Topic: topic, - MinBytes: 10e3, // 10KB - MaxBytes: 10e6, // 10MB - }) - return &kafkaReceiver{reader: r, topic: topic}, nil -} diff --git a/examples/event/memory/memory.go b/examples/event/memory/memory.go deleted file mode 100644 index 67fe471a2..000000000 --- a/examples/event/memory/memory.go +++ /dev/null @@ -1,88 +0,0 @@ -package memory - -import ( - "context" - "log" - "sync" - - "github.com/go-kratos/kratos/examples/event/event" -) - -var ( - _ event.Sender = (*memorySender)(nil) - _ event.Receiver = (*memoryReceiver)(nil) - _ event.Event = (*Message)(nil) -) - -var ( - chanMap = struct { - sync.RWMutex - cm map[string]chan *Message - }{} - ChanSize = 256 -) - -func init() { - chanMap.cm = make(map[string]chan *Message) -} - -type Message struct { - key string - value []byte -} - -func (m *Message) Key() string { - return m.key -} - -func (m *Message) Value() []byte { - return m.value -} - -type memorySender struct { - topic string -} - -func (m *memorySender) Send(ctx context.Context, msg event.Event) error { - chanMap.cm[m.topic] <- &Message{ - key: msg.Key(), - value: msg.Value(), - } - return nil -} - -func (m *memorySender) Close() error { - return nil -} - -type memoryReceiver struct { - topic string -} - -func (m *memoryReceiver) Receive(ctx context.Context, handler event.Handler) error { - go func() { - for msg := range chanMap.cm[m.topic] { - err := handler(context.Background(), msg) - if err != nil { - log.Fatal("message handling exception:", err) - } - } - }() - return nil -} - -func (m *memoryReceiver) Close() error { - return nil -} - -func NewMemory(topic string) (event.Sender, event.Receiver) { - chanMap.RLock() - if _, ok := chanMap.cm[topic]; !ok { - // chanMap.Lock() - chanMap.cm[topic] = make(chan *Message, ChanSize) - // chanMap.Unlock() - } - defer chanMap.RUnlock() - - return &memorySender{topic: topic}, &memoryReceiver{topic: topic} -} diff --git a/examples/event/memory/memory_test.go b/examples/event/memory/memory_test.go deleted file mode 100644 index 813bcf86a..000000000 --- a/examples/event/memory/memory_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package memory - -import ( - "context" - "fmt" - "testing" - "time" - - "github.com/go-kratos/kratos/examples/event/event" -) - -func TestSendAndReceive(t *testing.T) { - send, receive := NewMemory("test") - err := receive.Receive(context.Background(), func(ctx context.Context, event event.Event) error { - t.Log(fmt.Sprintf("key:%s, value:%s\n", event.Key(), event.Value())) - return nil - }) - if err != nil { - t.Error(err) - } - - for i := 0; i < 5; i++ { - err := send.Send(context.Background(), &Message{ - key: "kratos", - value: []byte("hello world"), - }) - if err != nil { - t.Error(err) - } - } - - time.Sleep(5 * time.Second) -} diff --git a/examples/event/receiver/main.go b/examples/event/receiver/main.go deleted file mode 100644 index 0497a6269..000000000 --- a/examples/event/receiver/main.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "context" - "fmt" - "os" - "os/signal" - "syscall" - - "github.com/go-kratos/kratos/examples/event/event" - "github.com/go-kratos/kratos/examples/event/kafka" -) - -func main() { - sigs := make(chan os.Signal, 1) - signal.Notify(sigs, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - receiver, err := kafka.NewKafkaReceiver([]string{"localhost:9092"}, "kratos") - if err != nil { - panic(err) - } - receive(receiver) - - <-sigs - _ = receiver.Close() -} - -func receive(receiver event.Receiver) { - fmt.Println("start receiver") - err := receiver.Receive(context.Background(), func(ctx context.Context, msg event.Event) error { - fmt.Printf("key:%s, value:%s\n", msg.Key(), msg.Value()) - return nil - }) - if err != nil { - return - } -} diff --git a/examples/event/sender/main.go b/examples/event/sender/main.go deleted file mode 100644 index 3cd6ecfae..000000000 --- a/examples/event/sender/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "context" - "fmt" - - "github.com/go-kratos/kratos/examples/event/event" - "github.com/go-kratos/kratos/examples/event/kafka" -) - -func main() { - sender, err := kafka.NewKafkaSender([]string{"localhost:9092"}, "kratos") - if err != nil { - panic(err) - } - - for i := 0; i < 50; i++ { - send(sender) - } - - _ = sender.Close() -} - -func send(sender event.Sender) { - msg := kafka.NewMessage("kratos", []byte("hello world")) - err := sender.Send(context.Background(), msg) - if err != nil { - panic(err) - } - fmt.Printf("key:%s, value:%s\n", msg.Key(), msg.Value()) -} diff --git a/examples/go.mod b/examples/go.mod deleted file mode 100644 index ad1049b7a..000000000 --- a/examples/go.mod +++ /dev/null @@ -1,66 +0,0 @@ -module github.com/go-kratos/kratos/examples - -go 1.16 - -require ( - entgo.io/ent v0.9.0 - github.com/BurntSushi/toml v0.3.1 - github.com/envoyproxy/protoc-gen-validate v0.6.2 - github.com/gin-gonic/gin v1.7.7 - github.com/go-kratos/gin v0.1.0 - github.com/go-kratos/kratos/contrib/config/apollo/v2 v2.0.0-20210901080230-515b71ec9061 - github.com/go-kratos/kratos/contrib/metrics/prometheus/v2 v2.0.0-00010101000000-000000000000 - github.com/go-kratos/kratos/contrib/registry/consul/v2 v2.0.0-00010101000000-000000000000 - github.com/go-kratos/kratos/contrib/registry/discovery/v2 v2.0.0-00010101000000-000000000000 - github.com/go-kratos/kratos/contrib/registry/etcd/v2 v2.0.0-00010101000000-000000000000 - github.com/go-kratos/kratos/contrib/registry/nacos/v2 v2.0.0-00010101000000-000000000000 - github.com/go-kratos/kratos/contrib/registry/polaris/v2 v2.0.0 - github.com/go-kratos/kratos/contrib/registry/zookeeper/v2 v2.0.0-00010101000000-000000000000 - github.com/go-kratos/kratos/v2 v2.2.0 - github.com/go-kratos/swagger-api v1.0.0 - github.com/go-redis/redis/extra/redisotel v0.3.0 - github.com/go-redis/redis/v8 v8.11.2 - github.com/go-sql-driver/mysql v1.6.0 - github.com/golang-jwt/jwt/v4 v4.2.0 - github.com/google/wire v0.5.0 - github.com/gorilla/handlers v1.5.1 - github.com/gorilla/mux v1.8.0 - github.com/gorilla/websocket v1.4.2 - github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0 - github.com/hashicorp/consul/api v1.12.0 - github.com/labstack/echo/v4 v4.6.3 - github.com/nacos-group/nacos-sdk-go v1.0.9 - github.com/nicksnyder/go-i18n/v2 v2.1.2 - github.com/polarismesh/polaris-go v1.0.1 - github.com/prometheus/client_golang v1.12.0 - github.com/segmentio/kafka-go v0.4.27 - github.com/sirupsen/logrus v1.8.1 - github.com/soheilhy/cmux v0.1.4 - go.etcd.io/etcd/client/v3 v3.5.1 - go.opentelemetry.io/otel v1.3.0 - go.opentelemetry.io/otel/exporters/jaeger v1.3.0 - go.opentelemetry.io/otel/sdk v1.3.0 - go.opentelemetry.io/otel/trace v1.3.0 - go.uber.org/zap v1.19.1 - golang.org/x/text v0.3.7 - google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 - google.golang.org/grpc v1.44.0 - google.golang.org/grpc/examples v0.0.0-20220105183818-2fb1ac854b20 // indirect - google.golang.org/protobuf v1.27.1 - gorm.io/driver/mysql v1.3.2 - gorm.io/gorm v1.23.1 -) - -replace ( - github.com/buger/jsonparser => github.com/buger/jsonparser v1.1.1 - github.com/go-kratos/kratos/contrib/config/apollo/v2 => ../contrib/config/apollo - github.com/go-kratos/kratos/contrib/metrics/prometheus/v2 => ../contrib/metrics/prometheus - github.com/go-kratos/kratos/contrib/registry/consul/v2 => ../contrib/registry/consul - github.com/go-kratos/kratos/contrib/registry/discovery/v2 => ../contrib/registry/discovery - github.com/go-kratos/kratos/contrib/registry/etcd/v2 => ../contrib/registry/etcd - github.com/go-kratos/kratos/contrib/registry/nacos/v2 => ../contrib/registry/nacos - github.com/go-kratos/kratos/contrib/registry/polaris/v2 => ../contrib/registry/polaris - github.com/go-kratos/kratos/contrib/registry/zookeeper/v2 => ../contrib/registry/zookeeper - - github.com/go-kratos/kratos/v2 => ../ -) diff --git a/examples/go.sum b/examples/go.sum deleted file mode 100644 index 0449cc48c..000000000 --- a/examples/go.sum +++ /dev/null @@ -1,1340 +0,0 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= -cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= -cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= -cloud.google.com/go v0.44.3/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= -cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= -cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= -cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= -cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= -cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= -cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= -cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= -cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= -cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= -cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= -cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= -cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= -cloud.google.com/go v0.75.0/go.mod h1:VGuuCn7PG0dwsd5XPVm2Mm3wlh3EL55/79EKB6hlPTY= -cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECHg= -cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8= -cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0= -cloud.google.com/go v0.83.0/go.mod h1:Z7MJUsANfY0pYPdw0lbnivPx4/vhy/e2FEkSkF7vAVY= -cloud.google.com/go v0.84.0/go.mod h1:RazrYuxIK6Kb7YrzzhPoLmCVzl7Sup4NrbKPg8KHSUM= -cloud.google.com/go v0.87.0/go.mod h1:TpDYlFy7vuLzZMMZ+B6iRiELaY7z/gJPaqbMx6mlWcY= -cloud.google.com/go v0.90.0/go.mod h1:kRX0mNRHe0e2rC6oNakvwQqzyDmg57xJ+SZU1eT2aDQ= -cloud.google.com/go v0.93.3/go.mod h1:8utlLll2EF5XMAV15woO4lSbWQlk8rer9aLOfLh7+YI= -cloud.google.com/go v0.94.1/go.mod h1:qAlAugsXlC+JWO+Bke5vCtc9ONxjQT3drlTTnAplMW4= -cloud.google.com/go v0.97.0/go.mod h1:GF7l59pYBVlXQIBLx3a761cZ41F9bBH3JUlihCt2Udc= -cloud.google.com/go v0.99.0/go.mod h1:w0Xx2nLzqWJPuozYQX+hFfCSI8WioryfRDzkoI/Y2ZA= -cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= -cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= -cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= -cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= -cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= -cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= -cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= -cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= -cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= -cloud.google.com/go/firestore v1.6.1/go.mod h1:asNXNOzBdyVQmEU+ggO8UPodTkEVFW5Qx+rwHnAz+EY= -cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= -cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= -cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= -cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= -cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= -cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= -cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= -cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= -cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= -cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -entgo.io/ent v0.9.0 h1:2S1zfpMMW6p+wctj6kcYUprNPNjLWFW06T5MdyAfmWc= -entgo.io/ent v0.9.0/go.mod h1:6NUeTfUN5mp5YN+5tgoH1SlakSvYPTBOYotSOvaI4ak= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= -github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= -github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= -github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= -github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= -github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= -github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= -github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= -github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= -github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 h1:zOVTBdCKFd9JbCKz9/nt+FovbjPFmb7mUnp8nH9fQBA= -github.com/aliyun/alibaba-cloud-sdk-go v1.61.18/go.mod h1:v8ESoHo4SyHmuB4b1tJqDHxfTGEciD+yhvOU/5s1Rfk= -github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/apolloconfig/agollo/v4 v4.1.0 h1:aZmrnSr/l0/CD5+txdgF1bIiKP1I5m0EH0WkHqAVhHk= -github.com/apolloconfig/agollo/v4 v4.1.0/go.mod h1:SuvTjtg0p4UlSzSbik+ibLRr6oR1xRsfy65QzP3GEAs= -github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= -github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= -github.com/armon/go-metrics v0.3.10 h1:FR+drcQStOe+32sYyJYyZ7FIdgoGGBnwLl+flodp8Uo= -github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= -github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= -github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= -github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= -github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= -github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= -github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= -github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= -github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= -github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= -github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= -github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= -github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= -github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= -github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= -github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= -github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= -github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI= -github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= -github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= -github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8/yCZMuEPMUDHG0CW/brkkEp8mzqk2+ODEitlw= -github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= -github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= -github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= -github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= -github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= -github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= -github.com/envoyproxy/go-control-plane v0.10.1/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/envoyproxy/protoc-gen-validate v0.6.2 h1:JiO+kJTpmYGjEodY7O1Zk8oZcNz1+f30UtwtXoFUPzE= -github.com/envoyproxy/protoc-gen-validate v0.6.2/go.mod h1:2t7qjJNvHPx8IjnBOzl9E9/baC+qXE/TeeyBRzgJDws= -github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 h1:Ghm4eQYC0nEPnSJdVkTrXpu9KtoVCSo1hg7mtI7G9KU= -github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0yfBxPvZrHkprdPPTTS3N5rwmLE8T22KBXlw= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= -github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= -github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ= -github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= -github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= -github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY= -github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= -github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= -github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.7.2/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= -github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs= -github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U= -github.com/go-bindata/go-bindata v1.0.1-0.20190711162640-ee3c2418e368/go.mod h1:7xCgX1lzlrXPHkfvn3EhumqHkmSlzt8at9q7v0ax19c= -github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w= -github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o= -github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= -github.com/go-kratos/aegis v0.1.1/go.mod h1:jYeSQ3Gesba478zEnujOiG5QdsyF3Xk/8owFUeKcHxw= -github.com/go-kratos/gin v0.1.0 h1:yq5GfZnSNo8cOIqxqPE0FVNQ8fm++oKQBd3/rTTp4oI= -github.com/go-kratos/gin v0.1.0/go.mod h1:KzE88+mV1QJdmiT+sU2D560ucOXnWZx+4m0OnVcSyzQ= -github.com/go-kratos/grpc-gateway/v2 v2.0.0-20210804092615-bdc92eb5ce83 h1:YN1KsqX3mB8hkSrOLZv3xZaZh+lZ/L7QC00RATFLJSg= -github.com/go-kratos/grpc-gateway/v2 v2.0.0-20210804092615-bdc92eb5ce83/go.mod h1:qV5/s5A7wfY7GkNzptcUFRGAG4Y8H4mlXpSrOkDEIk0= -github.com/go-kratos/swagger-api v1.0.0 h1:R1JcAqLSvfDzqHoDnpK3Jt1MEJAXGNifV7AnBEhP3PE= -github.com/go-kratos/swagger-api v1.0.0/go.mod h1:BPeS1OUN4jtMitb99ptZAagAgyQ51S2F2vd9dT/J3eM= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.1 h1:DX7uPQ4WgAWfoh+NGGlbJQswnYIVvz0SRlLS3rPZQDA= -github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/stdr v1.2.0 h1:j4LrlVXgrbIWO83mmQUnK0Hi+YnbD+vzrE1z/EphbFE= -github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI= -github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= -github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= -github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/form/v4 v4.2.0 h1:N1wh+Goz61e6w66vo8vJkQt+uwZSoLz50kZPJWR8eic= -github.com/go-playground/form/v4 v4.2.0/go.mod h1:q1a2BY+AQUUzhl6xA/6hBetay6dEIhMHjgvJiGo6K7U= -github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= -github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= -github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= -github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= -github.com/go-redis/redis/extra/rediscmd v0.2.0 h1:A3bhCsCKsedClEH9/jYlcKqOuBoeeV+H0yDie5t+a6w= -github.com/go-redis/redis/extra/rediscmd v0.2.0/go.mod h1:Z5bP1EHl9PvWhx/DupfCdZwB0JgOO3aVxWc/PFux+BE= -github.com/go-redis/redis/extra/redisotel v0.3.0 h1:8rrizwFAUUeMgmelyiQi9KeFwmpQhay9E+/rE6qHsBM= -github.com/go-redis/redis/extra/redisotel v0.3.0/go.mod h1:sGV3dQnPMBUuqzowEP2nZPhLXCMeh83nY64yaju249c= -github.com/go-redis/redis/v8 v8.3.2/go.mod h1:jszGxBCez8QA1HWSmQxJO9Y82kNibbUmeYhKWrBejTU= -github.com/go-redis/redis/v8 v8.5.0/go.mod h1:YmEcgBDttjnkbMzDAhDtQxY9yVA7jMN6PCR5HeMvqFE= -github.com/go-redis/redis/v8 v8.11.2 h1:WqlSpAwz8mxDSMCvbyz1Mkiqe0LE5OY4j3lgkvu1Ts0= -github.com/go-redis/redis/v8 v8.11.2/go.mod h1:DLomh7y2e3ggQXQLd1YgmvIfecPJoFl7WU5SOQ/r06M= -github.com/go-resty/resty/v2 v2.6.0 h1:joIR5PNLM2EFqqESUjCMGXrWmXNHEU9CEiK813oKYS4= -github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q= -github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-sql-driver/mysql v1.5.1-0.20200311113236-681ffa848bae/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= -github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-zookeeper/zk v1.0.2 h1:4mx0EYENAdX/B/rbunjlt5+4RTA/a9SMHBRuSKdGxPM= -github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= -github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= -github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= -github.com/golang-jwt/jwt/v4 v4.2.0 h1:besgBTC8w8HjP6NzQdxwKH9Z5oQMZ24ThTrHp3cZ8eU= -github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v0.0.0-20210429001901-424d2337a529 h1:2voWjNECnrZRbfwXxHB1/j8wa6xdKn85B5NzgVL/pTU= -github.com/golang/glog v0.0.0-20210429001901-424d2337a529/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= -github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= -github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac/go.mod h1:P32wAyui1PQ58Oce/KYkOqQv8cVw1zAapXOl+dRFGbc= -github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82/go.mod h1:PxC8OnwL11+aosOB5+iEPoV3picfs8tUpkVd0pDo+Kg= -github.com/gonum/integrate v0.0.0-20181209220457-a422b5c0fdf2/go.mod h1:pDgmNM6seYpwvPos3q+zxlXMsbve6mOIPucUnUOrI7Y= -github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks= -github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A= -github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw= -github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b/go.mod h1:Z4GIJBJO3Wa4gD4vbwQxXXZ+WHmW6E9ixmNrwvs0iZs= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= -github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= -github.com/google/martian/v3 v3.2.1/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= -github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= -github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/wire v0.5.0 h1:I7ELFeVBr3yfPIcc8+MWvrjk+3VjbcSzoXm3JVa+jD8= -github.com/google/wire v0.5.0/go.mod h1:ngWDr9Qvq3yZA10YrxfyGELY/AFWGVpy9c1LTRi1EoU= -github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0= -github.com/googleapis/gax-go/v2 v2.1.1/go.mod h1:hddJymUZASv3XPyGkUpKj8pPO47Rmb0eJc8R6ouapiM= -github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= -github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= -github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= -github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= -github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= -github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0 h1:ajue7SzQMywqRjg2fK7dcpc0QhFGpTR2plWfV4EZWR4= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0/go.mod h1:r1hZAcvfFXuYmcKyCJI9wlyOPIZUJl6FCB8Cpca/NLE= -github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= -github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= -github.com/hashicorp/consul/api v1.9.1/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M= -github.com/hashicorp/consul/api v1.12.0 h1:k3y1FYv6nuKyNTqj6w9gXOx5r5CfLj/k/euUeBXj1OY= -github.com/hashicorp/consul/api v1.12.0/go.mod h1:6pVBMo0ebnYdt2S3H87XhekM/HHrUoTD2XXb/VrZVy0= -github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= -github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= -github.com/hashicorp/consul/sdk v0.8.0 h1:OJtKBtEjboEZvG6AOUdh4Z1Zbyu0WcxQ0qatRrZHTVU= -github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= -github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= -github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= -github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= -github.com/hashicorp/go-hclog v1.0.0 h1:bkKf0BeBXcSYa7f5Fyi9gMuQ8gNsxeiNpZjR6VxNZeo= -github.com/hashicorp/go-hclog v1.0.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= -github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= -github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-msgpack v0.5.3 h1:zKjpN5BK/P5lMYrLmBHdBULWbJ0XpYR+7NGzqkZzoD4= -github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= -github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= -github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= -github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= -github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= -github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc= -github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= -github.com/hashicorp/go-sockaddr v1.0.0 h1:GeH6tui99pF4NJgfnhp+L6+FfobzVW3Ah46sLo0ICXs= -github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= -github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= -github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= -github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= -github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= -github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= -github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY= -github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc= -github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= -github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= -github.com/hashicorp/memberlist v0.3.0 h1:8+567mCcFDnS5ADl7lrpxPMWiFCElyUEeW0gtj34fMA= -github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= -github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= -github.com/hashicorp/serf v0.9.6 h1:uuEX1kLR6aoda1TBttmJQKDLZE1Ob7KN0NPdE7EtCDc= -github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= -github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= -github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= -github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= -github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4= -github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag= -github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= -github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= -github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas= -github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= -github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= -github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= -github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= -github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= -github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.9.8 h1:VMAMUUOh+gaxKTMk+zqbjsSjsIcUcL/LF4o63i82QyA= -github.com/klauspost/compress v1.9.8/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/labstack/echo/v4 v4.6.3 h1:VhPuIZYxsbPmo4m9KAkMU/el2442eB7EBFFhNTTT9ac= -github.com/labstack/echo/v4 v4.6.3/go.mod h1:Hk5OiHj0kDqmFq7aHe7eDqI7CUhuCrfpupQtLGGLm7A= -github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o= -github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM= -github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= -github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570 h1:0iQektZGS248WXmGIYOwRXSQhD4qn3icjMpuxwO7qlo= -github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570/go.mod h1:BLt8L9ld7wVsvEWQbuLrUZnCMnUmLZ+CGDzKtclrTlE= -github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f h1:sgUSP4zdTUZYZgAGGtN5Lxk92rK+JUFOwf+FT99EEI4= -github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f/go.mod h1:UGmTpUd3rjbtfIpwAPrcfmGf/Z1HS95TATB+m57TPB8= -github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 h1:Bvq8AziQ5jFF4BHGAEDSqwPW1NJS3XshxbRCxtjFAZc= -github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042/go.mod h1:TPpsiPUEh0zFL1Snz4crhMlBe60PYxRHr5oFF3rRYg0= -github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= -github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= -github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w= -github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= -github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= -github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= -github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= -github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= -github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY= -github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= -github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= -github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= -github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0= -github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= -github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= -github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= -github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs= -github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/nacos-group/nacos-sdk-go v1.0.9 h1:sMvrp6tZj4LdhuHRsS4GCqASB81k3pjmT2ykDQQpwt0= -github.com/nacos-group/nacos-sdk-go v1.0.9/go.mod h1:hlAPn3UdzlxIlSILAyOXKxjFSvDJ9oLzTJ9hLAK1KzA= -github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= -github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= -github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= -github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= -github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -github.com/nicksnyder/go-i18n/v2 v2.1.2 h1:QHYxcUJnGHBaq7XbvgunmZ2Pn0focXFqTD61CkH146c= -github.com/nicksnyder/go-i18n/v2 v2.1.2/go.mod h1:d++QJC9ZVf7pa48qrsRWhMJ5pSHIPmS3OLqK1niyLxs= -github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= -github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= -github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= -github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= -github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4= -github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg= -github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= -github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ= -github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= -github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= -github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= -github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= -github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA= -github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= -github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= -github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= -github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= -github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= -github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= -github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= -github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= -github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM= -github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= -github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= -github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= -github.com/pierrec/lz4 v2.6.0+incompatible h1:Ix9yFKn1nSPBLFl/yZknTp8TU5G4Ps0JDmguYK6iH1A= -github.com/pierrec/lz4 v2.6.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= -github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= -github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/polaris-go v1.0.1 h1:Zqr8ZtxsJQsxt0MGyC/fFsF861ogoJCz16yWFJ/t54Q= -github.com/polarismesh/polaris-go v1.0.1/go.mod h1:3NOqn3QquPdEdY6YhPrsWGvBVCpKhPBGt0Hspq3yEqY= -github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= -github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= -github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= -github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.9.0/go.mod h1:FqZLKOZnGdFAhOK4nqGHa7D66IdsO+O441Eve7ptJDU= -github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= -github.com/prometheus/client_golang v1.12.0 h1:C+UIj/QWtmqY13Arb8kwMt5j34/0Z2iKamrJ+ryC0Gg= -github.com/prometheus/client_golang v1.12.0/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= -github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= -github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= -github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= -github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= -github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4= -github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= -github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= -github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= -github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ= -github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc= -github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= -github.com/sagikazarmark/crypt v0.4.0/go.mod h1:ALv2SRj7GxYV4HO9elxH9nS6M9gW+xDNxqmyJ6RfDFM= -github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= -github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/segmentio/kafka-go v0.4.27 h1:sIhEozeL/TLN2mZ5dkG462vcGEWYKS+u31sXPjKhAM4= -github.com/segmentio/kafka-go v0.4.27/go.mod h1:XzMcoMjSzDGHcIwpWUI7GB43iKZ2fTVmryPSGLf/MPg= -github.com/shirou/gopsutil/v3 v3.21.8/go.mod h1:YWp/H8Qs5fVmf17v7JNZzA0mPJ+mS2e9JdiUF9LlKzQ= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= -github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= -github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= -github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4= -github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= -github.com/spf13/afero v1.8.0 h1:5MmtuhAgYeU6qpa7w7bP0dv6MBYuup0vekhSpSkoq60= -github.com/spf13/afero v1.8.0/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo= -github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA= -github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= -github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= -github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= -github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= -github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= -github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk= -github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU= -github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= -github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= -github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= -github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/tebeka/strftime v0.1.3 h1:5HQXOqWKYRFfNyBMNVc9z5+QzuBtIXy03psIhtdJYto= -github.com/tebeka/strftime v0.1.3/go.mod h1:7wJm3dZlpr4l/oVK0t1HYIc4rMzQ2XJlOMIUJUJH6XQ= -github.com/tevid/gohamcrest v1.1.1 h1:ou+xSqlIw1xfGTg1uq1nif/htZ2S3EzRqLm2BP+tYU0= -github.com/tevid/gohamcrest v1.1.1/go.mod h1:3UvtWlqm8j5JbwYZh80D/PVBt0mJ1eJiYgZMibh0H/k= -github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs= -github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8= -github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3 h1:kF/7m/ZU+0D4Jj5eZ41Zm3IH/J8OElK1Qtd7tVKAwLk= -github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3/go.mod h1:QDlpd3qS71vYtakd2hmdpqhJ9nwv6mD6A30bQ1BPBFE= -github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= -github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= -github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= -github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= -github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4= -github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c h1:u40Z8hqBAAQyv+vATcGgV0YCnDjqSL7/q/JyPhhJSPk= -github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= -github.com/xdg/stringprep v1.0.0 h1:d9X0esnoa3dFsV0FG35rAT0RIhYFlPq7MiP+DW89La0= -github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738 h1:VcrIfasaLFkyjk6KNlXQSzO+B0fZcnECiDrKJsfxka0= -go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= -go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= -go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM= -go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= -go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= -go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnTH4E= -go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= -go.etcd.io/etcd/client/v2 v2.305.1/go.mod h1:pMEacxZW7o8pg4CrFE7pquyCJJzZvkvdD2RibOCCCGs= -go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0= -go.etcd.io/etcd/client/v3 v3.5.1 h1:oImGuV5LGKjCqXdjkMHCyWa5OO1gYKCnC/1sgdfj1Uk= -go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q= -go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= -go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= -go.opentelemetry.io/otel v0.13.0/go.mod h1:dlSNewoRYikTkotEnxdmuBHgzT+k/idJSfDv/FxEnOY= -go.opentelemetry.io/otel v0.16.0/go.mod h1:e4GKElweB8W2gWUqbghw0B8t5MCTccc9212eNHnOHwA= -go.opentelemetry.io/otel v0.17.0/go.mod h1:Oqtdxmf7UtEvL037ohlgnaYa1h7GtMh0NcSd9eqkC9s= -go.opentelemetry.io/otel v1.3.0 h1:APxLf0eiBwLl+SOXiJJCVYzA1OOJNyAoV8C5RNRyy7Y= -go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs= -go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0= -go.opentelemetry.io/otel/exporters/jaeger v1.3.0/go.mod h1:KoYHi1BtkUPncGSRtCe/eh1ijsnePhSkxwzz07vU0Fc= -go.opentelemetry.io/otel/metric v0.17.0/go.mod h1:hUz9lH1rNXyEwWAhIWCMFWKhYtpASgSnObJFnU26dJ0= -go.opentelemetry.io/otel/oteltest v0.17.0/go.mod h1:JT/LGFxPwpN+nlsTiinSYjdIx3hZIGqHCpChcIZmdoE= -go.opentelemetry.io/otel/sdk v1.3.0 h1:3278edCoH89MEJ0Ky8WQXVmDQv3FX4ZJ3Pp+9fJreAI= -go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs= -go.opentelemetry.io/otel/trace v0.17.0/go.mod h1:bIujpqg6ZL6xUTubIUgziI1jSaUPthmabA/ygf/6Cfg= -go.opentelemetry.io/otel/trace v1.3.0 h1:doy8Hzb1RJ+I3yFhtDmwNc7tIyw1tNMOIsyPzp1NOGY= -go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk= -go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= -go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4= -go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= -go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= -go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= -go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= -go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= -go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= -go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI= -go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa h1:idItI2DDfCokpg0N51B2VtiLdJ4vAuXC9fnCb2gACo4= -golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= -golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= -golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= -golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= -golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= -golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210913180222-943fd674d43e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210917221730-978cfadd31cf h1:R150MpwJIv1MpS0N/pc+NhTM8ajzvlmxlY5OYsrevXQ= -golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= -golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= -golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= -google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= -google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= -google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= -google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= -google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= -google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= -google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= -google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= -google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= -google.golang.org/api v0.51.0/go.mod h1:t4HdrdoNgyN5cbEfm7Lum0lcLDLiise1F8qDKX00sOU= -google.golang.org/api v0.54.0/go.mod h1:7C4bFFOvVDGXjfDTAsgGwDgAxRDeQ4X8NvUedIt6z3k= -google.golang.org/api v0.55.0/go.mod h1:38yMfeP1kfjsl8isn0tliTjIb1rJXcQi4UXlbqivdVE= -google.golang.org/api v0.56.0/go.mod h1:38yMfeP1kfjsl8isn0tliTjIb1rJXcQi4UXlbqivdVE= -google.golang.org/api v0.57.0/go.mod h1:dVPlbZyBo2/OjBpmvNdpn2GRm6rPy75jyU7bmhdrMgI= -google.golang.org/api v0.59.0/go.mod h1:sT2boj7M9YJxZzgeZqXogmhfmRWDtPzT31xkieUbuZU= -google.golang.org/api v0.61.0/go.mod h1:xQRti5UdCmoCEqFxcz93fTl338AVqDgyaDRuOZ3hg9I= -google.golang.org/api v0.63.0/go.mod h1:gs4ij2ffTRXwuzzgJl/56BdwJaA194ijkfn++9tDuPo= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= -google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= -google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= -google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200806141610-86f49bd18e98/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= -google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= -google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= -google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= -google.golang.org/genproto v0.0.0-20210701191553-46259e63a0a9/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= -google.golang.org/genproto v0.0.0-20210713002101-d411969a0d9a/go.mod h1:AxrInvYm1dci+enl5hChSFPOmmUF1+uAa/UsgNRWd7k= -google.golang.org/genproto v0.0.0-20210716133855-ce7ef5c701ea/go.mod h1:AxrInvYm1dci+enl5hChSFPOmmUF1+uAa/UsgNRWd7k= -google.golang.org/genproto v0.0.0-20210728212813-7823e685a01f/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= -google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= -google.golang.org/genproto v0.0.0-20210813162853-db860fec028c/go.mod h1:cFeNkxwySK631ADgubI+/XFU/xp8FD5KIVV4rj8UC5w= -google.golang.org/genproto v0.0.0-20210821163610-241b8fcbd6c8/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20210909211513-a8c4777a87af/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20210924002016-3dee208752a0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20211008145708-270636b82663/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20211028162531-8db9c33dc351/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 h1:YxHp5zqIcAShDEvRr5/0rVESVS+njYF68PSdazrNLJo= -google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= -google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= -google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= -google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.37.1/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= -google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= -google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= -google.golang.org/grpc v1.40.1/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= -google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= -google.golang.org/grpc v1.44.0 h1:weqSxi/TMs1SqFRMHCtBgXRs8k3X39QIDEZ0pRcttUg= -google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= -google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= -google.golang.org/grpc/examples v0.0.0-20220105183818-2fb1ac854b20 h1:E/V/xnVzrdcIgW1yYPuJONZnNKHb6OV2Jlj6lSTlGXQ= -google.golang.org/grpc/examples v0.0.0-20220105183818-2fb1ac854b20/go.mod h1:gID3PKrg7pWKntu9Ss6zTLJ0ttC0X9IHgREOCZwbCVU= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= -google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= -gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/ini.v1 v1.66.3 h1:jRskFVxYaMGAMUbN0UZ7niA9gzL9B49DOqE78vg0k3w= -gopkg.in/ini.v1 v1.66.3/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= -gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= -gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= -gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/mysql v1.3.2 h1:QJryWiqQ91EvZ0jZL48NOpdlPdMjdip1hQ8bTgo4H7I= -gorm.io/driver/mysql v1.3.2/go.mod h1:ChK6AHbHgDCFZyJp0F+BmVGb06PSIoh9uVYKAlRbb2U= -gorm.io/gorm v1.23.1 h1:aj5IlhDzEPsoIyOPtTRVI+SyaN1u6k613sbt4pwbxG0= -gorm.io/gorm v1.23.1/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= -honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= -rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= -sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= -sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= -sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/examples/header/client/main.go b/examples/header/client/main.go deleted file mode 100644 index cc7b34af4..000000000 --- a/examples/header/client/main.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "context" - "log" - stdhttp "net/http" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - - stdgrpc "google.golang.org/grpc" - grpcmd "google.golang.org/grpc/metadata" -) - -func main() { - callHTTP() - callGRPC() -} - -func callHTTP() { - conn, err := http.NewClient( - context.Background(), - http.WithEndpoint("127.0.0.1:8000"), - ) - if err != nil { - panic(err) - } - client := helloworld.NewGreeterHTTPClient(conn) - ctx := context.Background() - var header stdhttp.Header - reply, err := client.SayHello(ctx, &helloworld.HelloRequest{Name: "kratos"}, http.Header(&header)) - if err != nil { - log.Fatal(err) - } - log.Printf("[http] SayHello %s header: %v\n", reply.Message, header) -} - -func callGRPC() { - conn, err := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("127.0.0.1:9000"), - ) - if err != nil { - log.Fatal(err) - } - client := helloworld.NewGreeterClient(conn) - ctx := context.Background() - var md grpcmd.MD - reply, err := client.SayHello(ctx, &helloworld.HelloRequest{Name: "kratos"}, stdgrpc.Header(&md)) - if err != nil { - log.Fatal(err) - } - log.Printf("[grpc] SayHello %+v header: %v\n", reply, md) -} diff --git a/examples/header/server/main.go b/examples/header/server/main.go deleted file mode 100644 index e15c5857a..000000000 --- a/examples/header/server/main.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/transport" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name = "helloworld" - // Version is the version of the compiled software. - // Version = "v1.0.0" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - info, _ := kratos.FromContext(ctx) - if tr, ok := transport.FromServerContext(ctx); ok { - tr.ReplyHeader().Set("app_name", info.Name()) - } - return &helloworld.HelloReply{Message: fmt.Sprintf("Hello %s", in.Name)}, nil -} - -func main() { - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - ) - httpSrv := http.NewServer( - http.Address(":8000"), - ) - - s := &server{} - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - app := kratos.New( - kratos.Name(Name), - kratos.Server( - httpSrv, - grpcSrv, - ), - ) - - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/helloworld/README.md b/examples/helloworld/README.md deleted file mode 100644 index be39d4fee..000000000 --- a/examples/helloworld/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Run the example - -1、Compile and execute the server code: -```shell -$ go run server/main.go -``` -2、From a different terminal, compile and execute the client code: -```shell -$ go run client/main.go -``` \ No newline at end of file diff --git a/examples/helloworld/client/main.go b/examples/helloworld/client/main.go deleted file mode 100644 index a371acb31..000000000 --- a/examples/helloworld/client/main.go +++ /dev/null @@ -1,75 +0,0 @@ -package main - -import ( - "context" - "log" - - pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/errors" - "github.com/go-kratos/kratos/v2/middleware/recovery" - transgrpc "github.com/go-kratos/kratos/v2/transport/grpc" - transhttp "github.com/go-kratos/kratos/v2/transport/http" -) - -func main() { - callHTTP() - callGRPC() -} - -func callHTTP() { - conn, err := transhttp.NewClient( - context.Background(), - transhttp.WithMiddleware( - recovery.Recovery(), - ), - transhttp.WithEndpoint("127.0.0.1:8000"), - ) - if err != nil { - panic(err) - } - defer conn.Close() - client := pb.NewGreeterHTTPClient(conn) - reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[http] SayHello %s\n", reply.Message) - - // returns error - _, err = client.SayHello(context.Background(), &pb.HelloRequest{Name: "error"}) - if err != nil { - log.Printf("[http] SayHello error: %v\n", err) - } - if errors.IsBadRequest(err) { - log.Printf("[http] SayHello error is invalid argument: %v\n", err) - } -} - -func callGRPC() { - conn, err := transgrpc.DialInsecure( - context.Background(), - transgrpc.WithEndpoint("127.0.0.1:9000"), - transgrpc.WithMiddleware( - recovery.Recovery(), - ), - ) - if err != nil { - panic(err) - } - defer conn.Close() - client := pb.NewGreeterClient(conn) - reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[grpc] SayHello %+v\n", reply) - - // returns error - _, err = client.SayHello(context.Background(), &pb.HelloRequest{Name: "error"}) - if err != nil { - log.Printf("[grpc] SayHello error: %v\n", err) - } - if errors.IsBadRequest(err) { - log.Printf("[grpc] SayHello error is invalid argument: %v\n", err) - } -} diff --git a/examples/helloworld/helloworld/helloworld.pb.go b/examples/helloworld/helloworld/helloworld.pb.go deleted file mode 100644 index d3161911b..000000000 --- a/examples/helloworld/helloworld/helloworld.pb.go +++ /dev/null @@ -1,222 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.15.7 -// source: helloworld/helloworld/helloworld.proto - -package helloworld - -import ( - _ "google.golang.org/genproto/googleapis/api/annotations" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// The request message containing the user's name. -type HelloRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (x *HelloRequest) Reset() { - *x = HelloRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_helloworld_helloworld_helloworld_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *HelloRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*HelloRequest) ProtoMessage() {} - -func (x *HelloRequest) ProtoReflect() protoreflect.Message { - mi := &file_helloworld_helloworld_helloworld_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead. -func (*HelloRequest) Descriptor() ([]byte, []int) { - return file_helloworld_helloworld_helloworld_proto_rawDescGZIP(), []int{0} -} - -func (x *HelloRequest) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -// The response message containing the greetings -type HelloReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` -} - -func (x *HelloReply) Reset() { - *x = HelloReply{} - if protoimpl.UnsafeEnabled { - mi := &file_helloworld_helloworld_helloworld_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *HelloReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*HelloReply) ProtoMessage() {} - -func (x *HelloReply) ProtoReflect() protoreflect.Message { - mi := &file_helloworld_helloworld_helloworld_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use HelloReply.ProtoReflect.Descriptor instead. -func (*HelloReply) Descriptor() ([]byte, []int) { - return file_helloworld_helloworld_helloworld_proto_rawDescGZIP(), []int{1} -} - -func (x *HelloReply) GetMessage() string { - if x != nil { - return x.Message - } - return "" -} - -var File_helloworld_helloworld_helloworld_proto protoreflect.FileDescriptor - -var file_helloworld_helloworld_helloworld_proto_rawDesc = []byte{ - 0x0a, 0x26, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x68, 0x65, 0x6c, - 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, - 0x6c, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, - 0x6f, 0x72, 0x6c, 0x64, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, - 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0x22, 0x0a, 0x0c, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x26, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, - 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x63, - 0x0a, 0x07, 0x47, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x12, 0x58, 0x0a, 0x08, 0x53, 0x61, 0x79, - 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x18, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, - 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x16, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, - 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x1a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x12, - 0x12, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x7b, 0x6e, 0x61, - 0x6d, 0x65, 0x7d, 0x42, 0x3c, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, 0x74, - 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c, - 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, - 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_helloworld_helloworld_helloworld_proto_rawDescOnce sync.Once - file_helloworld_helloworld_helloworld_proto_rawDescData = file_helloworld_helloworld_helloworld_proto_rawDesc -) - -func file_helloworld_helloworld_helloworld_proto_rawDescGZIP() []byte { - file_helloworld_helloworld_helloworld_proto_rawDescOnce.Do(func() { - file_helloworld_helloworld_helloworld_proto_rawDescData = protoimpl.X.CompressGZIP(file_helloworld_helloworld_helloworld_proto_rawDescData) - }) - return file_helloworld_helloworld_helloworld_proto_rawDescData -} - -var file_helloworld_helloworld_helloworld_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_helloworld_helloworld_helloworld_proto_goTypes = []interface{}{ - (*HelloRequest)(nil), // 0: helloworld.HelloRequest - (*HelloReply)(nil), // 1: helloworld.HelloReply -} -var file_helloworld_helloworld_helloworld_proto_depIdxs = []int32{ - 0, // 0: helloworld.Greeter.SayHello:input_type -> helloworld.HelloRequest - 1, // 1: helloworld.Greeter.SayHello:output_type -> helloworld.HelloReply - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_helloworld_helloworld_helloworld_proto_init() } -func file_helloworld_helloworld_helloworld_proto_init() { - if File_helloworld_helloworld_helloworld_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_helloworld_helloworld_helloworld_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*HelloRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_helloworld_helloworld_helloworld_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*HelloReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_helloworld_helloworld_helloworld_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_helloworld_helloworld_helloworld_proto_goTypes, - DependencyIndexes: file_helloworld_helloworld_helloworld_proto_depIdxs, - MessageInfos: file_helloworld_helloworld_helloworld_proto_msgTypes, - }.Build() - File_helloworld_helloworld_helloworld_proto = out.File - file_helloworld_helloworld_helloworld_proto_rawDesc = nil - file_helloworld_helloworld_helloworld_proto_goTypes = nil - file_helloworld_helloworld_helloworld_proto_depIdxs = nil -} diff --git a/examples/helloworld/helloworld/helloworld.proto b/examples/helloworld/helloworld/helloworld.proto deleted file mode 100644 index dfde5df49..000000000 --- a/examples/helloworld/helloworld/helloworld.proto +++ /dev/null @@ -1,27 +0,0 @@ -syntax = "proto3"; - -package helloworld; - -import "google/api/annotations.proto"; - -option go_package = "github.com/go-kratos/kratos/examples/helloworld/helloworld"; - -// The greeting service definition. -service Greeter { - // Sends a greeting - rpc SayHello (HelloRequest) returns (HelloReply) { - option (google.api.http) = { - get: "/helloworld/{name}", - }; - } -} - -// The request message containing the user's name. -message HelloRequest { - string name = 1; -} - -// The response message containing the greetings -message HelloReply { - string message = 1; -} diff --git a/examples/helloworld/helloworld/helloworld_grpc.pb.go b/examples/helloworld/helloworld/helloworld_grpc.pb.go deleted file mode 100644 index 26ea9ebe6..000000000 --- a/examples/helloworld/helloworld/helloworld_grpc.pb.go +++ /dev/null @@ -1,103 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package helloworld - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// GreeterClient is the client API for Greeter service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type GreeterClient interface { - // Sends a greeting - SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) -} - -type greeterClient struct { - cc grpc.ClientConnInterface -} - -func NewGreeterClient(cc grpc.ClientConnInterface) GreeterClient { - return &greeterClient{cc} -} - -func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) { - out := new(HelloReply) - err := c.cc.Invoke(ctx, "/helloworld.Greeter/SayHello", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// GreeterServer is the server API for Greeter service. -// All implementations must embed UnimplementedGreeterServer -// for forward compatibility -type GreeterServer interface { - // Sends a greeting - SayHello(context.Context, *HelloRequest) (*HelloReply, error) - mustEmbedUnimplementedGreeterServer() -} - -// UnimplementedGreeterServer must be embedded to have forward compatible implementations. -type UnimplementedGreeterServer struct { -} - -func (UnimplementedGreeterServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") -} -func (UnimplementedGreeterServer) mustEmbedUnimplementedGreeterServer() {} - -// UnsafeGreeterServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to GreeterServer will -// result in compilation errors. -type UnsafeGreeterServer interface { - mustEmbedUnimplementedGreeterServer() -} - -func RegisterGreeterServer(s grpc.ServiceRegistrar, srv GreeterServer) { - s.RegisterService(&Greeter_ServiceDesc, srv) -} - -func _Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(HelloRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(GreeterServer).SayHello(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/helloworld.Greeter/SayHello", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GreeterServer).SayHello(ctx, req.(*HelloRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// Greeter_ServiceDesc is the grpc.ServiceDesc for Greeter service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Greeter_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "helloworld.Greeter", - HandlerType: (*GreeterServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "SayHello", - Handler: _Greeter_SayHello_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "helloworld/helloworld/helloworld.proto", -} diff --git a/examples/helloworld/helloworld/helloworld_http.pb.go b/examples/helloworld/helloworld/helloworld_http.pb.go deleted file mode 100644 index 8515ed383..000000000 --- a/examples/helloworld/helloworld/helloworld_http.pb.go +++ /dev/null @@ -1,74 +0,0 @@ -// Code generated by protoc-gen-go-http. DO NOT EDIT. -// versions: -// protoc-gen-go-http v2.0.0 - -package helloworld - -import ( - context "context" - http "github.com/go-kratos/kratos/v2/transport/http" - binding "github.com/go-kratos/kratos/v2/transport/http/binding" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the kratos package it is being compiled against. -var _ = new(context.Context) -var _ = binding.EncodeURL - -const _ = http.SupportPackageIsVersion1 - -type GreeterHTTPServer interface { - SayHello(context.Context, *HelloRequest) (*HelloReply, error) -} - -func RegisterGreeterHTTPServer(s *http.Server, srv GreeterHTTPServer) { - r := s.Route("/") - r.GET("/helloworld/{name}", _Greeter_SayHello0_HTTP_Handler(srv)) -} - -func _Greeter_SayHello0_HTTP_Handler(srv GreeterHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in HelloRequest - if err := ctx.BindQuery(&in); err != nil { - return err - } - if err := ctx.BindVars(&in); err != nil { - return err - } - http.SetOperation(ctx, "/helloworld.Greeter/SayHello") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.SayHello(ctx, req.(*HelloRequest)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*HelloReply) - return ctx.Result(200, reply) - } -} - -type GreeterHTTPClient interface { - SayHello(ctx context.Context, req *HelloRequest, opts ...http.CallOption) (rsp *HelloReply, err error) -} - -type GreeterHTTPClientImpl struct { - cc *http.Client -} - -func NewGreeterHTTPClient(client *http.Client) GreeterHTTPClient { - return &GreeterHTTPClientImpl{client} -} - -func (c *GreeterHTTPClientImpl) SayHello(ctx context.Context, in *HelloRequest, opts ...http.CallOption) (*HelloReply, error) { - var out HelloReply - pattern := "/helloworld/{name}" - path := binding.EncodeURL(pattern, in, true) - opts = append(opts, http.Operation("/helloworld.Greeter/SayHello")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} diff --git a/examples/helloworld/server/main.go b/examples/helloworld/server/main.go deleted file mode 100644 index 33a876b73..000000000 --- a/examples/helloworld/server/main.go +++ /dev/null @@ -1,68 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/errors" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name = "helloworld" - // Version is the version of the compiled software. - // Version = "v1.0.0" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - if in.Name == "error" { - return nil, errors.BadRequest("custom_error", fmt.Sprintf("invalid argument %s", in.Name)) - } - if in.Name == "panic" { - panic("server panic") - } - return &helloworld.HelloReply{Message: fmt.Sprintf("Hello %+v", in.Name)}, nil -} - -func main() { - s := &server{} - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - recovery.Recovery(), - ), - ) - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - recovery.Recovery(), - ), - ) - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - app := kratos.New( - kratos.Name(Name), - kratos.Server( - httpSrv, - grpcSrv, - ), - ) - - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/http/README.md b/examples/http/README.md deleted file mode 100644 index 120b8c865..000000000 --- a/examples/http/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Run the examples - -## gin -1、Compile and execute the server code: -```shell -$ go run gin/main.go -``` -2、From a different terminal, access the api to see the output: -```shell -$ curl http://127.0.0.1:8000/helloworld/gin -{"welcome":"gin"} -``` - -## mux -1、Compile and execute the server code: -```shell -$ go run mux/main.go -``` -2、From a different terminal, access the api to see the output: -```shell -$ curl http://127.0.0.1:8000/home -Hello Gorilla Mux! -``` - -## static -1、Compile and execute the server code: -```shell -$ go run static/main.go -``` -2、Access the following url with your browser: -``` -http://127.0.0.1:8000/assets -``` diff --git a/examples/http/cors/main.go b/examples/http/cors/main.go deleted file mode 100644 index 5b61cc1e7..000000000 --- a/examples/http/cors/main.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "log" - - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/gorilla/handlers" -) - -func hello(ctx http.Context) error { - name := ctx.Vars().Get("name") - return ctx.String(200, "hellowolrd "+name) -} - -func main() { - httpSrv := http.NewServer( - http.Address(":8000"), - http.Filter(handlers.CORS( - handlers.AllowedOrigins([]string{"*"}), - handlers.AllowedMethods([]string{"GET", "POST"}), - )), - ) - route := httpSrv.Route("/") - route.GET("/helloworld/{name}", hello) - - app := kratos.New( - kratos.Name("cors"), - kratos.Server( - httpSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/http/echo/main.go b/examples/http/echo/main.go deleted file mode 100644 index ebc8117b7..000000000 --- a/examples/http/echo/main.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "log" - - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/labstack/echo/v4" -) - -func main() { - router := echo.New() - router.GET("/home", func(ctx echo.Context) error { - return ctx.JSON(200, "Hello echo") - }) - - httpSrv := http.NewServer(http.Address(":8000")) - httpSrv.HandlePrefix("/", router) - - app := kratos.New( - kratos.Name("echo"), - kratos.Server( - httpSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/http/errors/main.go b/examples/http/errors/main.go deleted file mode 100644 index 09afb89fb..000000000 --- a/examples/http/errors/main.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "errors" - "fmt" - "log" - stdhttp "net/http" - - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// HTTPError is an HTTP error. -type HTTPError struct { - Code int `json:"code"` - Message string `json:"message"` -} - -func (e *HTTPError) Error() string { - return fmt.Sprintf("HTTPError code: %d message: %s", e.Code, e.Message) -} - -// FromError try to convert an error to *HTTPError. -func FromError(err error) *HTTPError { - if err == nil { - return nil - } - if se := new(HTTPError); errors.As(err, &se) { - return se - } - return &HTTPError{Code: 500} -} - -func errorEncoder(w stdhttp.ResponseWriter, r *stdhttp.Request, err error) { - se := FromError(err) - codec, _ := http.CodecForRequest(r, "Accept") - body, err := codec.Marshal(se) - if err != nil { - w.WriteHeader(500) - return - } - w.Header().Set("Content-Type", "application/"+codec.Name()) - w.WriteHeader(se.Code) - _, _ = w.Write(body) -} - -func main() { - httpSrv := http.NewServer( - http.Address(":8000"), - http.ErrorEncoder(errorEncoder), - ) - router := httpSrv.Route("/") - router.GET("home", func(ctx http.Context) error { - return &HTTPError{Code: 400, Message: "request error"} - }) - app := kratos.New( - kratos.Name("mux"), - kratos.Server( - httpSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/http/gin/main.go b/examples/http/gin/main.go deleted file mode 100644 index 82e9fec33..000000000 --- a/examples/http/gin/main.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - - "github.com/gin-gonic/gin" - kgin "github.com/go-kratos/gin" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/errors" - "github.com/go-kratos/kratos/v2/middleware" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport" - "github.com/go-kratos/kratos/v2/transport/http" -) - -func customMiddleware(handler middleware.Handler) middleware.Handler { - return func(ctx context.Context, req interface{}) (reply interface{}, err error) { - if tr, ok := transport.FromServerContext(ctx); ok { - fmt.Println("operation:", tr.Operation()) - } - reply, err = handler(ctx, req) - return - } -} - -func main() { - router := gin.Default() - // 使用kratos中间件 - router.Use(kgin.Middlewares(recovery.Recovery(), customMiddleware)) - - router.GET("/helloworld/:name", func(ctx *gin.Context) { - name := ctx.Param("name") - if name == "error" { - // 返回kratos error - kgin.Error(ctx, errors.Unauthorized("auth_error", "no authentication")) - } else { - ctx.JSON(200, map[string]string{"welcome": name}) - } - }) - - httpSrv := http.NewServer(http.Address(":8000")) - httpSrv.HandlePrefix("/", router) - - app := kratos.New( - kratos.Name("gin"), - kratos.Server( - httpSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/http/middlewares/handlers.go b/examples/http/middlewares/handlers.go deleted file mode 100644 index 117d5056c..000000000 --- a/examples/http/middlewares/handlers.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "context" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/transport/http" -) - -func sayHelloHandler(ctx http.Context) error { - var in helloworld.HelloRequest - if err := ctx.BindQuery(&in); err != nil { - return err - } - - // binding /hello/{name} to in.Name - if err := ctx.BindVars(&in); err != nil { - return err - } - - http.SetOperation(ctx, "/helloworld.Greeter/SayHello") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return &helloworld.HelloReply{Message: "test:" + req.(*helloworld.HelloRequest).Name}, nil - }) - return ctx.Returns(h(ctx, &in)) -} diff --git a/examples/http/middlewares/main.go b/examples/http/middlewares/main.go deleted file mode 100644 index 81f104996..000000000 --- a/examples/http/middlewares/main.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -import ( - "log" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// this example shows how to add middlewares, -// execution order is globalFilter(http) --> routeFilter(http) --> pathFilter(http) --> serviceFilter(service) -func main() { - s := &server{} - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - // add service filter - serviceMiddleware, - serviceMiddleware2, - ), - // add global filter - http.Filter(globalFilter, globalFilter2), - ) - // register http handler to http server - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - // add route filter - r := httpSrv.Route("/", routeFilter, routeFilter2) - // add path filter to custom route - r.GET("/hello/{name}", sayHelloHandler, pathFilter, pathFilter2) - - // add path filter to router group - r2 := r.Group("/v2", pathFilter, pathFilter2) - r2.GET("/say/{name}", sayHelloHandler) - - app := kratos.New( - kratos.Name("helloworld"), - kratos.Server( - httpSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/http/middlewares/middlewares.go b/examples/http/middlewares/middlewares.go deleted file mode 100644 index 515f7b438..000000000 --- a/examples/http/middlewares/middlewares.go +++ /dev/null @@ -1,75 +0,0 @@ -package main - -import ( - "context" - "fmt" - "net/http" - - "github.com/go-kratos/kratos/v2/middleware" -) - -func globalFilter(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Println("global filter in") - next.ServeHTTP(w, r) - fmt.Println("global filter out") - }) -} - -func globalFilter2(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Println("global filter 2 in") - next.ServeHTTP(w, r) - fmt.Println("global filter 2 out") - }) -} - -func routeFilter(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Println("route filter in") - next.ServeHTTP(w, r) - fmt.Println("route filter out") - }) -} - -func routeFilter2(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Println("route filter 2 in") - next.ServeHTTP(w, r) - fmt.Println("route filter 2 out") - }) -} - -func pathFilter(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Println("path filter in") - next.ServeHTTP(w, r) - fmt.Println("path filter out") - }) -} - -func pathFilter2(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Println("path filter 2 in") - next.ServeHTTP(w, r) - fmt.Println("path filter 2 out") - }) -} - -func serviceMiddleware(handler middleware.Handler) middleware.Handler { - return func(ctx context.Context, req interface{}) (reply interface{}, err error) { - fmt.Println("service middleware in") - reply, err = handler(ctx, req) - fmt.Println("service middleware out") - return - } -} - -func serviceMiddleware2(handler middleware.Handler) middleware.Handler { - return func(ctx context.Context, req interface{}) (reply interface{}, err error) { - fmt.Println("service middleware 2 in") - reply, err = handler(ctx, req) - fmt.Println("service middleware 2 out") - return - } -} diff --git a/examples/http/middlewares/services.go b/examples/http/middlewares/services.go deleted file mode 100644 index 4af9e6888..000000000 --- a/examples/http/middlewares/services.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "context" - "fmt" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/errors" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - if in.Name == "error" { - return nil, errors.BadRequest("custom_error", fmt.Sprintf("invalid argument %s", in.Name)) - } - if in.Name == "panic" { - panic("grpc panic") - } - return &helloworld.HelloReply{Message: fmt.Sprintf("Hello %+v", in.Name)}, nil -} diff --git a/examples/http/mux/main.go b/examples/http/mux/main.go deleted file mode 100644 index 01e8244b2..000000000 --- a/examples/http/mux/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" - - "github.com/go-kratos/kratos/v2" - transhttp "github.com/go-kratos/kratos/v2/transport/http" - "github.com/gorilla/mux" -) - -func main() { - router := mux.NewRouter() - router.HandleFunc("/home", func(w http.ResponseWriter, req *http.Request) { - fmt.Fprint(w, "Hello Gorilla Mux!") - }).Methods("GET") - - httpSrv := transhttp.NewServer(transhttp.Address(":8000")) - httpSrv.HandlePrefix("/", router) - - app := kratos.New( - kratos.Name("mux"), - kratos.Server( - httpSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/http/redirect/main.go b/examples/http/redirect/main.go deleted file mode 100644 index 42b37b4c3..000000000 --- a/examples/http/redirect/main.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - "net/http" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/errors" - khttp "github.com/go-kratos/kratos/v2/transport/http" -) - -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - if in.Name == "error" { - return nil, errors.BadRequest("custom_error", fmt.Sprintf("invalid argument %s", in.Name)) - } - if in.Name == "panic" { - panic("server panic") - } - return &helloworld.HelloReply{Message: fmt.Sprintf("Hello %+v", in.Name)}, nil -} - -func redirectFilter(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/helloworld/kratos" { - http.Redirect(w, r, "https://go-kratos.dev/", http.StatusMovedPermanently) - return - } - next.ServeHTTP(w, r) - }) -} - -func main() { - httpSrv := khttp.NewServer( - khttp.Address(":8000"), - khttp.Filter(redirectFilter), - ) - s := &server{} - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - app := kratos.New( - kratos.Name("cors"), - kratos.Server( - httpSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} - -// get http://127.0.0.1:8000/helloworld/kratos -// get http://127.0.0.1:8000/helloworld/go-kratos.dev diff --git a/examples/http/static/assets/index.html b/examples/http/static/assets/index.html deleted file mode 100644 index 40ff87613..000000000 --- a/examples/http/static/assets/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - -
-This is an example of a simple HTML page with one paragraph.
- - diff --git a/examples/http/static/main.go b/examples/http/static/main.go deleted file mode 100644 index 982ed3df8..000000000 --- a/examples/http/static/main.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - "embed" - "log" - "net/http" - - "github.com/go-kratos/kratos/v2" - transhttp "github.com/go-kratos/kratos/v2/transport/http" - "github.com/gorilla/mux" -) - -//go:embed assets/* -var f embed.FS - -func main() { - router := mux.NewRouter() - // example: /assets/index.html - router.PathPrefix("/assets").Handler(http.FileServer(http.FS(f))) - - httpSrv := transhttp.NewServer(transhttp.Address(":8000")) - httpSrv.HandlePrefix("/", router) - - app := kratos.New( - kratos.Name("static"), - kratos.Server( - httpSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/http/upload/main.go b/examples/http/upload/main.go deleted file mode 100644 index db97ba37c..000000000 --- a/examples/http/upload/main.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "io" - "log" - "os" - - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/transport/http" -) - -func uploadFile(ctx http.Context) error { - req := ctx.Request() - - fileName := req.FormValue("name") - file, handler, err := req.FormFile("file") - if err != nil { - return err - } - defer file.Close() - - f, err := os.OpenFile(handler.Filename, os.O_WRONLY|os.O_CREATE, 0o666) - if err != nil { - return err - } - defer f.Close() - _, _ = io.Copy(f, file) - - return ctx.String(200, "File "+fileName+" Uploaded successfully") -} - -func main() { - httpSrv := http.NewServer( - http.Address(":8000"), - ) - route := httpSrv.Route("/") - route.POST("/upload", uploadFile) - - app := kratos.New( - kratos.Name("upload"), - kratos.Server( - httpSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/i18n/.gitignore b/examples/i18n/.gitignore deleted file mode 100644 index c29907463..000000000 --- a/examples/i18n/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# Reference https://github.com/github/gitignore/blob/master/Go.gitignore -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories (remove the comment below to include it) -vendor/ - -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# OS General -Thumbs.db -.DS_Store - -# project -*.cert -*.key -*.log -bin/ - -# Develop tools -.vscode/ -.idea/ -*.swp diff --git a/examples/i18n/Dockerfile b/examples/i18n/Dockerfile deleted file mode 100644 index 7fa6919c9..000000000 --- a/examples/i18n/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -FROM golang:1.15 AS builder - -COPY . /src -WORKDIR /src - -RUN GOPROXY=https://goproxy.cn make build - -FROM debian:stable-slim - -RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates \ - netbase \ - && rm -rf /var/lib/apt/lists/ \ - && apt-get autoremove -y && apt-get autoclean -y - -COPY --from=builder /src/bin /app - -WORKDIR /app - -EXPOSE 8000 -EXPOSE 9000 -VOLUME /data/conf - -CMD ["./server", "-conf", "/data/conf"] diff --git a/examples/i18n/LICENSE b/examples/i18n/LICENSE deleted file mode 100644 index 684318c72..000000000 --- a/examples/i18n/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 go-kratos - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/examples/i18n/Makefile b/examples/i18n/Makefile deleted file mode 100644 index b936b3431..000000000 --- a/examples/i18n/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -GOPATH:=$(shell go env GOPATH) -VERSION=$(shell git describe --tags --always) -INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) -API_PROTO_FILES=$(shell find api -name *.proto) - -.PHONY: init -# init env -init: - go get -u github.com/go-kratos/kratos/cmd/kratos/v2 - go get -u google.golang.org/protobuf/cmd/protoc-gen-go - go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc - go get -u github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2 - go get -u github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2 - go get -u github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 - go get -u github.com/envoyproxy/protoc-gen-validate - -.PHONY: errors -# generate errors code -errors: - protoc --proto_path=. \ - --proto_path=./third_party \ - --go_out=paths=source_relative:. \ - --go-errors_out=paths=source_relative:. \ - $(API_PROTO_FILES) - -.PHONY: config -# generate internal proto -config: - protoc --proto_path=. \ - --proto_path=./third_party \ - --go_out=paths=source_relative:. \ - $(INTERNAL_PROTO_FILES) - -.PHONY: api -# generate api proto -api: - protoc --proto_path=. \ - --proto_path=./third_party \ - --go_out=paths=source_relative:. \ - --go-http_out=paths=source_relative:. \ - --go-grpc_out=paths=source_relative:. \ - --validate_out=paths=source_relative,lang=go:. \ - --openapiv2_out . \ - $(API_PROTO_FILES) - -.PHONY: all -# generate all -all: - make api; - make errors; - make config; - -# show help -help: - @echo '' - @echo 'Usage:' - @echo ' make [target]' - @echo '' - @echo 'Targets:' - @awk '/^[a-zA-Z\-\_0-9]+:/ { \ - helpMessage = match(lastLine, /^# (.*)/); \ - if (helpMessage) { \ - helpCommand = substr($$1, 0, index($$1, ":")-1); \ - helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \ - printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \ - } \ - } \ - { lastLine = $$0 }' $(MAKEFILE_LIST) - -.DEFAULT_GOAL := help diff --git a/examples/i18n/README.md b/examples/i18n/README.md deleted file mode 100644 index 9815e05de..000000000 --- a/examples/i18n/README.md +++ /dev/null @@ -1,136 +0,0 @@ -# i18n Example -This project is an demo for i18n usage. -We integrated [go-i18n](https://github.com/nicksnyder/go-i18n) into our project for localization. - -We start with the project generate with `kratos-layout`, you could use `kratos new` to generate it. - -The following steps are applied. -## Step 1: install -Install the cli tool `goi18n` and the package. - -```bash -go get -u github.com/nicksnyder/go-i18n/v2/goi18n -go get -u github.com/nicksnyder/go-i18n -``` - -## Step 2: implement and register the middleware -There's a middleware in `internal/pkg/middleware/localize`, -we implement this middleware, and register it into our http server in `internal/server/http.go`. -We init the bundle and load our translation file(we will generate it later). -For convenience, we hard-coded the translation file path here, you should avoid it in your project :) - -Also the middleware will extract `accept-language` header -from our request, then set the correct `localizer` to the context. -In our service request handler, we can use the `FromContext` method to get this `localizer` for localization. - -This middleware is so simple that we can show it as following: -```go -package localize - -import ( - "context" - "github.com/BurntSushi/toml" - "github.com/nicksnyder/go-i18n/v2/i18n" - "golang.org/x/text/language" - - "github.com/go-kratos/kratos/v2/middleware" - "github.com/go-kratos/kratos/v2/transport" -) - -type localizerKey struct{} - -func I18N() middleware.Middleware { - bundle := i18n.NewBundle(language.English) - bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal) - bundle.MustLoadMessageFile("../../active.zh.toml") - - return func(handler middleware.Handler) middleware.Handler { - return func(ctx context.Context, req interface{}) (reply interface{}, err error) { - if tr, ok := transport.FromServerContext(ctx); ok { - accept := tr.Header().Get("accept-language") - println(accept) - localizer := i18n.NewLocalizer(bundle, accept) - ctx = context.WithValue(ctx, localizerKey{}, localizer) - } - return handler(ctx, req) - } - } -} - -func FromContext(ctx context.Context) *i18n.Localizer { - return ctx.Value(localizerKey{}).(*i18n.Localizer) -} -``` - -## Step 3: -Write our request handler code. -In `internal/service/greeter.go`, we use `localize.FromContext(ctx)` to get the localizer, and write the string for localizing. -You should write your message with golang template syntax. -Notice that both `One` and `Other` fields must be filled or you will get an panic on translation file generation with `goi18n` tool. - -```go -func (s *GreeterService) SayHello(ctx context.Context, in *v1.HelloRequest) (*v1.HelloReply, error) { - s.log.WithContext(ctx).Infof("SayHello Received: %v", in.GetName()) - - if in.GetName() == "error" { - return nil, v1.ErrorUserNotFound("user not found: %s", in.GetName()) - } - localizer := localize.FromContext(ctx) - helloMsg, err := localizer.Localize(&i18n.LocalizeConfig{ - DefaultMessage: &i18n.Message{ - Description: "sayhello", - ID: "sayHello", - One: "Hello {{.Name}}", - Other: "Hello {{.Name}}", - }, - TemplateData: map[string]interface{}{ - "Name": in.Name, - }, - }) - if err != nil { - return nil, err - } - return &v1.HelloReply{Message: helloMsg}, nil -} -``` - -## Step 3: Generate and translate - -In the root of this project, generate `active.en.toml` with -```bash -goi18n extract -``` -The string which should be translated will be extracted from your code, and write into `active.en.toml` -You should create the empty target language file: -```bash -touch translate.zh.toml -``` - -Then fill the translate file: -```bash -goi18n merge active.en.toml translate.zh.toml -``` - -You should edit the `translate.zh.toml` to finish the translation work. We translate `Hello` to `你好` in Chinese. -After that, you should rename this file to `active.zh.toml` -And this file is the translation file that we load in the Step 2. -You could also embed these translation files into your binaries for easier deployment. - -## Step 4: Run -Go to `cmd/i18n/`, and run `go run .` to start the service. - -You could try with curl with `Accept-Language` header -```bash -curl "http://localhost:8000/helloworld/eric" \ - -H 'Accept-Language: zh-CN' -``` -Will get the Chinese result `{"message":"你好 eric"}` - -And if no header: -``` -curl "http://localhost:8000/helloworld/eric" -``` -Will get the default English result `{"message":"Hello eric"}` - -## Reference -* [go-i18n](https://github.com/nicksnyder/go-i18n) You could refer to this repository for more detailed document. \ No newline at end of file diff --git a/examples/i18n/active.en.toml b/examples/i18n/active.en.toml deleted file mode 100644 index 2a74ba5ab..000000000 --- a/examples/i18n/active.en.toml +++ /dev/null @@ -1,4 +0,0 @@ -[sayHello] -description = "sayhello" -one = "Hello {{.Name}}" -other = "Hello {{.Name}}" diff --git a/examples/i18n/active.zh.toml b/examples/i18n/active.zh.toml deleted file mode 100644 index 382de637b..000000000 --- a/examples/i18n/active.zh.toml +++ /dev/null @@ -1,4 +0,0 @@ -[sayHello] -description = "sayhello" -hash = "sha1-52d93a5edde18c01bc0ec531f302116b43cdd635" -other = "你好 {{.Name}}" diff --git a/examples/i18n/api/helloworld/v1/error_reason.pb.go b/examples/i18n/api/helloworld/v1/error_reason.pb.go deleted file mode 100644 index 3369f930f..000000000 --- a/examples/i18n/api/helloworld/v1/error_reason.pb.go +++ /dev/null @@ -1,138 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.1 -// protoc v3.6.1 -// source: api/helloworld/v1/error_reason.proto - -package v1 - -import ( - _ "github.com/go-kratos/kratos/v2/errors" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type ErrorReason int32 - -const ( - ErrorReason_USER_NOT_FOUND ErrorReason = 0 - ErrorReason_CONTENT_MISSING ErrorReason = 1 -) - -// Enum value maps for ErrorReason. -var ( - ErrorReason_name = map[int32]string{ - 0: "USER_NOT_FOUND", - 1: "CONTENT_MISSING", - } - ErrorReason_value = map[string]int32{ - "USER_NOT_FOUND": 0, - "CONTENT_MISSING": 1, - } -) - -func (x ErrorReason) Enum() *ErrorReason { - p := new(ErrorReason) - *p = x - return p -} - -func (x ErrorReason) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (ErrorReason) Descriptor() protoreflect.EnumDescriptor { - return file_api_helloworld_v1_error_reason_proto_enumTypes[0].Descriptor() -} - -func (ErrorReason) Type() protoreflect.EnumType { - return &file_api_helloworld_v1_error_reason_proto_enumTypes[0] -} - -func (x ErrorReason) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use ErrorReason.Descriptor instead. -func (ErrorReason) EnumDescriptor() ([]byte, []int) { - return file_api_helloworld_v1_error_reason_proto_rawDescGZIP(), []int{0} -} - -var File_api_helloworld_v1_error_reason_proto protoreflect.FileDescriptor - -var file_api_helloworld_v1_error_reason_proto_rawDesc = []byte{ - 0x0a, 0x24, 0x61, 0x70, 0x69, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, - 0x2f, 0x76, 0x31, 0x2f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x61, 0x70, 0x69, 0x2e, 0x62, 0x6c, 0x6f, 0x67, - 0x2e, 0x76, 0x31, 0x1a, 0x13, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x2f, 0x65, 0x72, 0x72, 0x6f, - 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2a, 0x48, 0x0a, 0x0b, 0x45, 0x72, 0x72, 0x6f, - 0x72, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x0e, 0x55, 0x53, 0x45, 0x52, 0x5f, - 0x4e, 0x4f, 0x54, 0x5f, 0x46, 0x4f, 0x55, 0x4e, 0x44, 0x10, 0x00, 0x1a, 0x04, 0xa8, 0x45, 0x94, - 0x03, 0x12, 0x19, 0x0a, 0x0f, 0x43, 0x4f, 0x4e, 0x54, 0x45, 0x4e, 0x54, 0x5f, 0x4d, 0x49, 0x53, - 0x53, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x1a, 0x04, 0xa8, 0x45, 0x90, 0x03, 0x1a, 0x04, 0xa0, 0x45, - 0xf4, 0x03, 0x42, 0x57, 0x0a, 0x0e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x65, 0x72, - 0x72, 0x6f, 0x72, 0x73, 0x50, 0x01, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, - 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x62, 0x6c, 0x6f, - 0x67, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0xa2, 0x02, 0x0d, 0x41, 0x50, - 0x49, 0x42, 0x6c, 0x6f, 0x67, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, -} - -var ( - file_api_helloworld_v1_error_reason_proto_rawDescOnce sync.Once - file_api_helloworld_v1_error_reason_proto_rawDescData = file_api_helloworld_v1_error_reason_proto_rawDesc -) - -func file_api_helloworld_v1_error_reason_proto_rawDescGZIP() []byte { - file_api_helloworld_v1_error_reason_proto_rawDescOnce.Do(func() { - file_api_helloworld_v1_error_reason_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_helloworld_v1_error_reason_proto_rawDescData) - }) - return file_api_helloworld_v1_error_reason_proto_rawDescData -} - -var file_api_helloworld_v1_error_reason_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_api_helloworld_v1_error_reason_proto_goTypes = []interface{}{ - (ErrorReason)(0), // 0: api.blog.v1.ErrorReason -} -var file_api_helloworld_v1_error_reason_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_api_helloworld_v1_error_reason_proto_init() } -func file_api_helloworld_v1_error_reason_proto_init() { - if File_api_helloworld_v1_error_reason_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_api_helloworld_v1_error_reason_proto_rawDesc, - NumEnums: 1, - NumMessages: 0, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_api_helloworld_v1_error_reason_proto_goTypes, - DependencyIndexes: file_api_helloworld_v1_error_reason_proto_depIdxs, - EnumInfos: file_api_helloworld_v1_error_reason_proto_enumTypes, - }.Build() - File_api_helloworld_v1_error_reason_proto = out.File - file_api_helloworld_v1_error_reason_proto_rawDesc = nil - file_api_helloworld_v1_error_reason_proto_goTypes = nil - file_api_helloworld_v1_error_reason_proto_depIdxs = nil -} diff --git a/examples/i18n/api/helloworld/v1/error_reason.pb.validate.go b/examples/i18n/api/helloworld/v1/error_reason.pb.validate.go deleted file mode 100644 index e5c220dc3..000000000 --- a/examples/i18n/api/helloworld/v1/error_reason.pb.validate.go +++ /dev/null @@ -1,34 +0,0 @@ -// Code generated by protoc-gen-validate. DO NOT EDIT. -// source: api/helloworld/v1/error_reason.proto - -package v1 - -import ( - "bytes" - "errors" - "fmt" - "net" - "net/mail" - "net/url" - "regexp" - "strings" - "time" - "unicode/utf8" - - "google.golang.org/protobuf/types/known/anypb" -) - -// ensure the imports are used -var ( - _ = bytes.MinRead - _ = errors.New("") - _ = fmt.Print - _ = utf8.UTFMax - _ = (*regexp.Regexp)(nil) - _ = (*strings.Reader)(nil) - _ = net.IPv4len - _ = time.Duration(0) - _ = (*url.URL)(nil) - _ = (*mail.Address)(nil) - _ = anypb.Any{} -) diff --git a/examples/i18n/api/helloworld/v1/error_reason.proto b/examples/i18n/api/helloworld/v1/error_reason.proto deleted file mode 100644 index 46f7fbd30..000000000 --- a/examples/i18n/api/helloworld/v1/error_reason.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = "proto3"; - -package api.blog.v1; -import "errors/errors.proto"; - -// 多语言特定包名,用于源代码引用 -option go_package = "github.com/go-kratos/kratos/examples/blog/api/v1;v1"; -option java_multiple_files = true; -option java_package = "blog.v1.errors"; -option objc_class_prefix = "APIBlogErrors"; - -enum ErrorReason { - option (errors.default_code) = 500; - - USER_NOT_FOUND = 0 [(errors.code) = 404]; - CONTENT_MISSING = 1 [(errors.code) = 400];; -} diff --git a/examples/i18n/api/helloworld/v1/error_reason.swagger.json b/examples/i18n/api/helloworld/v1/error_reason.swagger.json deleted file mode 100644 index 95fce0b91..000000000 --- a/examples/i18n/api/helloworld/v1/error_reason.swagger.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "title": "api/helloworld/v1/error_reason.proto", - "version": "version not set" - }, - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "paths": {}, - "definitions": { - "protobufAny": { - "type": "object", - "properties": { - "typeUrl": { - "type": "string" - }, - "value": { - "type": "string", - "format": "byte" - } - } - }, - "rpcStatus": { - "type": "object", - "properties": { - "code": { - "type": "integer", - "format": "int32" - }, - "message": { - "type": "string" - }, - "details": { - "type": "array", - "items": { - "$ref": "#/definitions/protobufAny" - } - } - } - } - } -} diff --git a/examples/i18n/api/helloworld/v1/error_reason_errors.pb.go b/examples/i18n/api/helloworld/v1/error_reason_errors.pb.go deleted file mode 100644 index 2d87f3eff..000000000 --- a/examples/i18n/api/helloworld/v1/error_reason_errors.pb.go +++ /dev/null @@ -1,30 +0,0 @@ -// Code generated by protoc-gen-go-errors. DO NOT EDIT. - -package v1 - -import ( - fmt "fmt" - errors "github.com/go-kratos/kratos/v2/errors" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the kratos package it is being compiled against. -const _ = errors.SupportPackageIsVersion1 - -func IsUserNotFound(err error) bool { - e := errors.FromError(err) - return e.Reason == ErrorReason_USER_NOT_FOUND.String() && e.Code == 404 -} - -func ErrorUserNotFound(format string, args ...interface{}) *errors.Error { - return errors.New(404, ErrorReason_USER_NOT_FOUND.String(), fmt.Sprintf(format, args...)) -} - -func IsContentMissing(err error) bool { - e := errors.FromError(err) - return e.Reason == ErrorReason_CONTENT_MISSING.String() && e.Code == 400 -} - -func ErrorContentMissing(format string, args ...interface{}) *errors.Error { - return errors.New(400, ErrorReason_CONTENT_MISSING.String(), fmt.Sprintf(format, args...)) -} diff --git a/examples/i18n/api/helloworld/v1/greeter.pb.go b/examples/i18n/api/helloworld/v1/greeter.pb.go deleted file mode 100644 index 7f253fa4d..000000000 --- a/examples/i18n/api/helloworld/v1/greeter.pb.go +++ /dev/null @@ -1,226 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.1 -// protoc v3.6.1 -// source: api/helloworld/v1/greeter.proto - -package v1 - -import ( - _ "google.golang.org/genproto/googleapis/api/annotations" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// The request message containing the user's name. -type HelloRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (x *HelloRequest) Reset() { - *x = HelloRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_api_helloworld_v1_greeter_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *HelloRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*HelloRequest) ProtoMessage() {} - -func (x *HelloRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_helloworld_v1_greeter_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead. -func (*HelloRequest) Descriptor() ([]byte, []int) { - return file_api_helloworld_v1_greeter_proto_rawDescGZIP(), []int{0} -} - -func (x *HelloRequest) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -// The response message containing the greetings -type HelloReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` -} - -func (x *HelloReply) Reset() { - *x = HelloReply{} - if protoimpl.UnsafeEnabled { - mi := &file_api_helloworld_v1_greeter_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *HelloReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*HelloReply) ProtoMessage() {} - -func (x *HelloReply) ProtoReflect() protoreflect.Message { - mi := &file_api_helloworld_v1_greeter_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use HelloReply.ProtoReflect.Descriptor instead. -func (*HelloReply) Descriptor() ([]byte, []int) { - return file_api_helloworld_v1_greeter_proto_rawDescGZIP(), []int{1} -} - -func (x *HelloReply) GetMessage() string { - if x != nil { - return x.Message - } - return "" -} - -var File_api_helloworld_v1_greeter_proto protoreflect.FileDescriptor - -var file_api_helloworld_v1_greeter_proto_rawDesc = []byte{ - 0x0a, 0x1f, 0x61, 0x70, 0x69, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, - 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x12, 0x0d, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x76, 0x31, - 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, - 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x22, - 0x0a, 0x0c, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, - 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x22, 0x26, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, - 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x69, 0x0a, 0x07, 0x47, 0x72, - 0x65, 0x65, 0x74, 0x65, 0x72, 0x12, 0x5e, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, - 0x6f, 0x12, 0x1b, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x76, - 0x31, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, - 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x48, - 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x1a, 0x82, 0xd3, 0xe4, 0x93, 0x02, - 0x14, 0x12, 0x12, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x7b, - 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x42, 0x73, 0x0a, 0x1c, 0x64, 0x65, 0x76, 0x2e, 0x6b, 0x72, 0x61, - 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, - 0x6c, 0x64, 0x2e, 0x76, 0x31, 0x42, 0x11, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x57, 0x6f, 0x72, 0x6c, - 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x56, 0x31, 0x50, 0x01, 0x5a, 0x3e, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, - 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, - 0x2f, 0x69, 0x31, 0x38, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, - 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, -} - -var ( - file_api_helloworld_v1_greeter_proto_rawDescOnce sync.Once - file_api_helloworld_v1_greeter_proto_rawDescData = file_api_helloworld_v1_greeter_proto_rawDesc -) - -func file_api_helloworld_v1_greeter_proto_rawDescGZIP() []byte { - file_api_helloworld_v1_greeter_proto_rawDescOnce.Do(func() { - file_api_helloworld_v1_greeter_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_helloworld_v1_greeter_proto_rawDescData) - }) - return file_api_helloworld_v1_greeter_proto_rawDescData -} - -var file_api_helloworld_v1_greeter_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_api_helloworld_v1_greeter_proto_goTypes = []interface{}{ - (*HelloRequest)(nil), // 0: helloworld.v1.HelloRequest - (*HelloReply)(nil), // 1: helloworld.v1.HelloReply -} -var file_api_helloworld_v1_greeter_proto_depIdxs = []int32{ - 0, // 0: helloworld.v1.Greeter.SayHello:input_type -> helloworld.v1.HelloRequest - 1, // 1: helloworld.v1.Greeter.SayHello:output_type -> helloworld.v1.HelloReply - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_api_helloworld_v1_greeter_proto_init() } -func file_api_helloworld_v1_greeter_proto_init() { - if File_api_helloworld_v1_greeter_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_api_helloworld_v1_greeter_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*HelloRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_api_helloworld_v1_greeter_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*HelloReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_api_helloworld_v1_greeter_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_api_helloworld_v1_greeter_proto_goTypes, - DependencyIndexes: file_api_helloworld_v1_greeter_proto_depIdxs, - MessageInfos: file_api_helloworld_v1_greeter_proto_msgTypes, - }.Build() - File_api_helloworld_v1_greeter_proto = out.File - file_api_helloworld_v1_greeter_proto_rawDesc = nil - file_api_helloworld_v1_greeter_proto_goTypes = nil - file_api_helloworld_v1_greeter_proto_depIdxs = nil -} diff --git a/examples/i18n/api/helloworld/v1/greeter.pb.validate.go b/examples/i18n/api/helloworld/v1/greeter.pb.validate.go deleted file mode 100644 index 5918b0686..000000000 --- a/examples/i18n/api/helloworld/v1/greeter.pb.validate.go +++ /dev/null @@ -1,167 +0,0 @@ -// Code generated by protoc-gen-validate. DO NOT EDIT. -// source: api/helloworld/v1/greeter.proto - -package v1 - -import ( - "bytes" - "errors" - "fmt" - "net" - "net/mail" - "net/url" - "regexp" - "strings" - "time" - "unicode/utf8" - - "google.golang.org/protobuf/types/known/anypb" -) - -// ensure the imports are used -var ( - _ = bytes.MinRead - _ = errors.New("") - _ = fmt.Print - _ = utf8.UTFMax - _ = (*regexp.Regexp)(nil) - _ = (*strings.Reader)(nil) - _ = net.IPv4len - _ = time.Duration(0) - _ = (*url.URL)(nil) - _ = (*mail.Address)(nil) - _ = anypb.Any{} -) - -// Validate checks the field values on HelloRequest with the rules defined in -// the proto definition for this message. If any rules are violated, an error -// is returned. -func (m *HelloRequest) Validate() error { - if m == nil { - return nil - } - - // no validation rules for Name - - return nil -} - -// HelloRequestValidationError is the validation error returned by -// HelloRequest.Validate if the designated constraints aren't met. -type HelloRequestValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e HelloRequestValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e HelloRequestValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e HelloRequestValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e HelloRequestValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e HelloRequestValidationError) ErrorName() string { return "HelloRequestValidationError" } - -// Error satisfies the builtin error interface -func (e HelloRequestValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sHelloRequest.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = HelloRequestValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = HelloRequestValidationError{} - -// Validate checks the field values on HelloReply with the rules defined in the -// proto definition for this message. If any rules are violated, an error is returned. -func (m *HelloReply) Validate() error { - if m == nil { - return nil - } - - // no validation rules for Message - - return nil -} - -// HelloReplyValidationError is the validation error returned by -// HelloReply.Validate if the designated constraints aren't met. -type HelloReplyValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e HelloReplyValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e HelloReplyValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e HelloReplyValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e HelloReplyValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e HelloReplyValidationError) ErrorName() string { return "HelloReplyValidationError" } - -// Error satisfies the builtin error interface -func (e HelloReplyValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sHelloReply.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = HelloReplyValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = HelloReplyValidationError{} diff --git a/examples/i18n/api/helloworld/v1/greeter.proto b/examples/i18n/api/helloworld/v1/greeter.proto deleted file mode 100644 index d3308d617..000000000 --- a/examples/i18n/api/helloworld/v1/greeter.proto +++ /dev/null @@ -1,30 +0,0 @@ -syntax = "proto3"; - -package helloworld.v1; - -import "google/api/annotations.proto"; - -option go_package = "github.com/go-kratos/kratos/examples/i18n/api/helloworld/v1;v1"; -option java_multiple_files = true; -option java_package = "dev.kratos.api.helloworld.v1"; -option java_outer_classname = "HelloWorldProtoV1"; - -// The greeting service definition. -service Greeter { - // Sends a greeting - rpc SayHello (HelloRequest) returns (HelloReply) { - option (google.api.http) = { - get: "/helloworld/{name}" - }; - } -} - -// The request message containing the user's name. -message HelloRequest { - string name = 1; -} - -// The response message containing the greetings -message HelloReply { - string message = 1; -} diff --git a/examples/i18n/api/helloworld/v1/greeter.swagger.json b/examples/i18n/api/helloworld/v1/greeter.swagger.json deleted file mode 100644 index f62a7a6f4..000000000 --- a/examples/i18n/api/helloworld/v1/greeter.swagger.json +++ /dev/null @@ -1,92 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "title": "api/helloworld/v1/greeter.proto", - "version": "version not set" - }, - "tags": [ - { - "name": "Greeter" - } - ], - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "paths": { - "/helloworld/{name}": { - "get": { - "summary": "Sends a greeting", - "operationId": "Greeter_SayHello", - "responses": { - "200": { - "description": "A successful response.", - "schema": { - "$ref": "#/definitions/v1HelloReply" - } - }, - "default": { - "description": "An unexpected error response.", - "schema": { - "$ref": "#/definitions/rpcStatus" - } - } - }, - "parameters": [ - { - "name": "name", - "in": "path", - "required": true, - "type": "string" - } - ], - "tags": [ - "Greeter" - ] - } - } - }, - "definitions": { - "protobufAny": { - "type": "object", - "properties": { - "typeUrl": { - "type": "string" - }, - "value": { - "type": "string", - "format": "byte" - } - } - }, - "rpcStatus": { - "type": "object", - "properties": { - "code": { - "type": "integer", - "format": "int32" - }, - "message": { - "type": "string" - }, - "details": { - "type": "array", - "items": { - "$ref": "#/definitions/protobufAny" - } - } - } - }, - "v1HelloReply": { - "type": "object", - "properties": { - "message": { - "type": "string" - } - }, - "title": "The response message containing the greetings" - } - } -} diff --git a/examples/i18n/api/helloworld/v1/greeter_grpc.pb.go b/examples/i18n/api/helloworld/v1/greeter_grpc.pb.go deleted file mode 100644 index 8fcb3c8e2..000000000 --- a/examples/i18n/api/helloworld/v1/greeter_grpc.pb.go +++ /dev/null @@ -1,103 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package v1 - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// GreeterClient is the client API for Greeter service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type GreeterClient interface { - // Sends a greeting - SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) -} - -type greeterClient struct { - cc grpc.ClientConnInterface -} - -func NewGreeterClient(cc grpc.ClientConnInterface) GreeterClient { - return &greeterClient{cc} -} - -func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) { - out := new(HelloReply) - err := c.cc.Invoke(ctx, "/helloworld.v1.Greeter/SayHello", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// GreeterServer is the server API for Greeter service. -// All implementations must embed UnimplementedGreeterServer -// for forward compatibility -type GreeterServer interface { - // Sends a greeting - SayHello(context.Context, *HelloRequest) (*HelloReply, error) - mustEmbedUnimplementedGreeterServer() -} - -// UnimplementedGreeterServer must be embedded to have forward compatible implementations. -type UnimplementedGreeterServer struct { -} - -func (UnimplementedGreeterServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") -} -func (UnimplementedGreeterServer) mustEmbedUnimplementedGreeterServer() {} - -// UnsafeGreeterServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to GreeterServer will -// result in compilation errors. -type UnsafeGreeterServer interface { - mustEmbedUnimplementedGreeterServer() -} - -func RegisterGreeterServer(s grpc.ServiceRegistrar, srv GreeterServer) { - s.RegisterService(&Greeter_ServiceDesc, srv) -} - -func _Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(HelloRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(GreeterServer).SayHello(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/helloworld.v1.Greeter/SayHello", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GreeterServer).SayHello(ctx, req.(*HelloRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// Greeter_ServiceDesc is the grpc.ServiceDesc for Greeter service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Greeter_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "helloworld.v1.Greeter", - HandlerType: (*GreeterServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "SayHello", - Handler: _Greeter_SayHello_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "api/helloworld/v1/greeter.proto", -} diff --git a/examples/i18n/api/helloworld/v1/greeter_http.pb.go b/examples/i18n/api/helloworld/v1/greeter_http.pb.go deleted file mode 100644 index 5bbbfece4..000000000 --- a/examples/i18n/api/helloworld/v1/greeter_http.pb.go +++ /dev/null @@ -1,74 +0,0 @@ -// Code generated by protoc-gen-go-http. DO NOT EDIT. -// versions: -// protoc-gen-go-http v2.0.0-rc7 - -package v1 - -import ( - context "context" - http "github.com/go-kratos/kratos/v2/transport/http" - binding "github.com/go-kratos/kratos/v2/transport/http/binding" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the kratos package it is being compiled against. -var _ = new(context.Context) -var _ = binding.EncodeURL - -const _ = http.SupportPackageIsVersion1 - -type GreeterHTTPServer interface { - SayHello(context.Context, *HelloRequest) (*HelloReply, error) -} - -func RegisterGreeterHTTPServer(s *http.Server, srv GreeterHTTPServer) { - r := s.Route("/") - r.GET("/helloworld/{name}", _Greeter_SayHello0_HTTP_Handler(srv)) -} - -func _Greeter_SayHello0_HTTP_Handler(srv GreeterHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in HelloRequest - if err := ctx.BindQuery(&in); err != nil { - return err - } - if err := ctx.BindVars(&in); err != nil { - return err - } - http.SetOperation(ctx, "/helloworld.v1.Greeter/SayHello") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.SayHello(ctx, req.(*HelloRequest)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*HelloReply) - return ctx.Result(200, reply) - } -} - -type GreeterHTTPClient interface { - SayHello(ctx context.Context, req *HelloRequest, opts ...http.CallOption) (rsp *HelloReply, err error) -} - -type GreeterHTTPClientImpl struct { - cc *http.Client -} - -func NewGreeterHTTPClient(client *http.Client) GreeterHTTPClient { - return &GreeterHTTPClientImpl{client} -} - -func (c *GreeterHTTPClientImpl) SayHello(ctx context.Context, in *HelloRequest, opts ...http.CallOption) (*HelloReply, error) { - var out HelloReply - pattern := "/helloworld/{name}" - path := binding.EncodeURL(pattern, in, true) - opts = append(opts, http.Operation("/helloworld.v1.Greeter/SayHello")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} diff --git a/examples/i18n/cmd/i18n/main.go b/examples/i18n/cmd/i18n/main.go deleted file mode 100644 index 23ad83f7a..000000000 --- a/examples/i18n/cmd/i18n/main.go +++ /dev/null @@ -1,79 +0,0 @@ -package main - -import ( - "flag" - "os" - - "github.com/go-kratos/kratos/examples/i18n/internal/conf" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/config" - "github.com/go-kratos/kratos/v2/config/file" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name string - // Version is the version of the compiled software. - Version string - // flagconf is the config flag. - flagconf string - - id, _ = os.Hostname() -) - -func init() { - flag.StringVar(&flagconf, "conf", "../../configs", "config path, eg: -conf config.yaml") -} - -func newApp(logger log.Logger, hs *http.Server, gs *grpc.Server) *kratos.App { - return kratos.New( - kratos.ID(id), - kratos.Name(Name), - kratos.Version(Version), - kratos.Metadata(map[string]string{}), - kratos.Logger(logger), - kratos.Server( - hs, - gs, - ), - ) -} - -func main() { - flag.Parse() - logger := log.With(log.NewStdLogger(os.Stdout), - "ts", log.DefaultTimestamp, - "caller", log.DefaultCaller, - "service.id", id, - "service.name", Name, - "service.version", Version, - ) - c := config.New( - config.WithSource( - file.NewSource(flagconf), - ), - ) - if err := c.Load(); err != nil { - panic(err) - } - - var bc conf.Bootstrap - if err := c.Scan(&bc); err != nil { - panic(err) - } - - app, cleanup, err := initApp(bc.Server, bc.Data, logger) - if err != nil { - panic(err) - } - defer cleanup() - - // start and wait for stop signal - if err := app.Run(); err != nil { - panic(err) - } -} diff --git a/examples/i18n/cmd/i18n/wire.go b/examples/i18n/cmd/i18n/wire.go deleted file mode 100644 index a06ff9578..000000000 --- a/examples/i18n/cmd/i18n/wire.go +++ /dev/null @@ -1,22 +0,0 @@ -//go:build wireinject -// +build wireinject - -// The build tag makes sure the stub is not built in the final build. - -package main - -import ( - "github.com/go-kratos/kratos/examples/i18n/internal/biz" - "github.com/go-kratos/kratos/examples/i18n/internal/conf" - "github.com/go-kratos/kratos/examples/i18n/internal/data" - "github.com/go-kratos/kratos/examples/i18n/internal/server" - "github.com/go-kratos/kratos/examples/i18n/internal/service" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" - "github.com/google/wire" -) - -// initApp init kratos application. -func initApp(*conf.Server, *conf.Data, log.Logger) (*kratos.App, func(), error) { - panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) -} diff --git a/examples/i18n/cmd/i18n/wire_gen.go b/examples/i18n/cmd/i18n/wire_gen.go deleted file mode 100644 index 4983e47eb..000000000 --- a/examples/i18n/cmd/i18n/wire_gen.go +++ /dev/null @@ -1,36 +0,0 @@ -// Code generated by Wire. DO NOT EDIT. - -//go:generate go run github.com/google/wire/cmd/wire -//go:build !wireinject -// +build !wireinject - -package main - -import ( - "github.com/go-kratos/kratos/examples/i18n/internal/biz" - "github.com/go-kratos/kratos/examples/i18n/internal/conf" - "github.com/go-kratos/kratos/examples/i18n/internal/data" - "github.com/go-kratos/kratos/examples/i18n/internal/server" - "github.com/go-kratos/kratos/examples/i18n/internal/service" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" -) - -// Injectors from wire.go: - -// initApp init kratos application. -func initApp(confServer *conf.Server, confData *conf.Data, logger log.Logger) (*kratos.App, func(), error) { - dataData, cleanup, err := data.NewData(confData, logger) - if err != nil { - return nil, nil, err - } - greeterRepo := data.NewGreeterRepo(dataData, logger) - greeterUsecase := biz.NewGreeterUsecase(greeterRepo, logger) - greeterService := service.NewGreeterService(greeterUsecase, logger) - httpServer := server.NewHTTPServer(confServer, greeterService, logger) - grpcServer := server.NewGRPCServer(confServer, greeterService, logger) - app := newApp(logger, httpServer, grpcServer) - return app, func() { - cleanup() - }, nil -} diff --git a/examples/i18n/configs/config.yaml b/examples/i18n/configs/config.yaml deleted file mode 100644 index e90a878ab..000000000 --- a/examples/i18n/configs/config.yaml +++ /dev/null @@ -1,15 +0,0 @@ -server: - http: - addr: 0.0.0.0:8000 - timeout: 1s - grpc: - addr: 0.0.0.0:9000 - timeout: 1s -data: - database: - driver: mysql - source: root:root@tcp(127.0.0.1:3306)/test - redis: - addr: 127.0.0.1:6379 - read_timeout: 0.2s - write_timeout: 0.2s diff --git a/examples/i18n/generate.go b/examples/i18n/generate.go deleted file mode 100644 index 91fa45735..000000000 --- a/examples/i18n/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package generate - -//go:generate kratos proto client api diff --git a/examples/i18n/internal/biz/README.md b/examples/i18n/internal/biz/README.md deleted file mode 100644 index 26a66b630..000000000 --- a/examples/i18n/internal/biz/README.md +++ /dev/null @@ -1 +0,0 @@ -# Biz diff --git a/examples/i18n/internal/biz/biz.go b/examples/i18n/internal/biz/biz.go deleted file mode 100644 index d0a973bc2..000000000 --- a/examples/i18n/internal/biz/biz.go +++ /dev/null @@ -1,6 +0,0 @@ -package biz - -import "github.com/google/wire" - -// ProviderSet is biz providers. -var ProviderSet = wire.NewSet(NewGreeterUsecase) diff --git a/examples/i18n/internal/biz/greeter.go b/examples/i18n/internal/biz/greeter.go deleted file mode 100644 index 8b35979ed..000000000 --- a/examples/i18n/internal/biz/greeter.go +++ /dev/null @@ -1,33 +0,0 @@ -package biz - -import ( - "context" - - "github.com/go-kratos/kratos/v2/log" -) - -type Greeter struct { - Hello string -} - -type GreeterRepo interface { - CreateGreeter(context.Context, *Greeter) error - UpdateGreeter(context.Context, *Greeter) error -} - -type GreeterUsecase struct { - repo GreeterRepo - log *log.Helper -} - -func NewGreeterUsecase(repo GreeterRepo, logger log.Logger) *GreeterUsecase { - return &GreeterUsecase{repo: repo, log: log.NewHelper(logger)} -} - -func (uc *GreeterUsecase) Create(ctx context.Context, g *Greeter) error { - return uc.repo.CreateGreeter(ctx, g) -} - -func (uc *GreeterUsecase) Update(ctx context.Context, g *Greeter) error { - return uc.repo.UpdateGreeter(ctx, g) -} diff --git a/examples/i18n/internal/conf/conf.pb.go b/examples/i18n/internal/conf/conf.pb.go deleted file mode 100644 index 38c272919..000000000 --- a/examples/i18n/internal/conf/conf.pb.go +++ /dev/null @@ -1,653 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.15.7 -// source: internal/conf/conf.proto - -package conf - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - durationpb "google.golang.org/protobuf/types/known/durationpb" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Bootstrap struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Server *Server `protobuf:"bytes,1,opt,name=server,proto3" json:"server,omitempty"` - Data *Data `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` -} - -func (x *Bootstrap) Reset() { - *x = Bootstrap{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_conf_conf_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Bootstrap) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Bootstrap) ProtoMessage() {} - -func (x *Bootstrap) ProtoReflect() protoreflect.Message { - mi := &file_internal_conf_conf_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Bootstrap.ProtoReflect.Descriptor instead. -func (*Bootstrap) Descriptor() ([]byte, []int) { - return file_internal_conf_conf_proto_rawDescGZIP(), []int{0} -} - -func (x *Bootstrap) GetServer() *Server { - if x != nil { - return x.Server - } - return nil -} - -func (x *Bootstrap) GetData() *Data { - if x != nil { - return x.Data - } - return nil -} - -type Server struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Http *Server_HTTP `protobuf:"bytes,1,opt,name=http,proto3" json:"http,omitempty"` - Grpc *Server_GRPC `protobuf:"bytes,2,opt,name=grpc,proto3" json:"grpc,omitempty"` -} - -func (x *Server) Reset() { - *x = Server{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_conf_conf_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server) ProtoMessage() {} - -func (x *Server) ProtoReflect() protoreflect.Message { - mi := &file_internal_conf_conf_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server.ProtoReflect.Descriptor instead. -func (*Server) Descriptor() ([]byte, []int) { - return file_internal_conf_conf_proto_rawDescGZIP(), []int{1} -} - -func (x *Server) GetHttp() *Server_HTTP { - if x != nil { - return x.Http - } - return nil -} - -func (x *Server) GetGrpc() *Server_GRPC { - if x != nil { - return x.Grpc - } - return nil -} - -type Data struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Database *Data_Database `protobuf:"bytes,1,opt,name=database,proto3" json:"database,omitempty"` - Redis *Data_Redis `protobuf:"bytes,2,opt,name=redis,proto3" json:"redis,omitempty"` -} - -func (x *Data) Reset() { - *x = Data{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_conf_conf_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data) ProtoMessage() {} - -func (x *Data) ProtoReflect() protoreflect.Message { - mi := &file_internal_conf_conf_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data.ProtoReflect.Descriptor instead. -func (*Data) Descriptor() ([]byte, []int) { - return file_internal_conf_conf_proto_rawDescGZIP(), []int{2} -} - -func (x *Data) GetDatabase() *Data_Database { - if x != nil { - return x.Database - } - return nil -} - -func (x *Data) GetRedis() *Data_Redis { - if x != nil { - return x.Redis - } - return nil -} - -type Server_HTTP struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - Timeout *durationpb.Duration `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"` -} - -func (x *Server_HTTP) Reset() { - *x = Server_HTTP{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_conf_conf_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server_HTTP) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server_HTTP) ProtoMessage() {} - -func (x *Server_HTTP) ProtoReflect() protoreflect.Message { - mi := &file_internal_conf_conf_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server_HTTP.ProtoReflect.Descriptor instead. -func (*Server_HTTP) Descriptor() ([]byte, []int) { - return file_internal_conf_conf_proto_rawDescGZIP(), []int{1, 0} -} - -func (x *Server_HTTP) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Server_HTTP) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Server_HTTP) GetTimeout() *durationpb.Duration { - if x != nil { - return x.Timeout - } - return nil -} - -type Server_GRPC struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - Timeout *durationpb.Duration `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"` -} - -func (x *Server_GRPC) Reset() { - *x = Server_GRPC{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_conf_conf_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server_GRPC) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server_GRPC) ProtoMessage() {} - -func (x *Server_GRPC) ProtoReflect() protoreflect.Message { - mi := &file_internal_conf_conf_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server_GRPC.ProtoReflect.Descriptor instead. -func (*Server_GRPC) Descriptor() ([]byte, []int) { - return file_internal_conf_conf_proto_rawDescGZIP(), []int{1, 1} -} - -func (x *Server_GRPC) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Server_GRPC) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Server_GRPC) GetTimeout() *durationpb.Duration { - if x != nil { - return x.Timeout - } - return nil -} - -type Data_Database struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Driver string `protobuf:"bytes,1,opt,name=driver,proto3" json:"driver,omitempty"` - Source string `protobuf:"bytes,2,opt,name=source,proto3" json:"source,omitempty"` -} - -func (x *Data_Database) Reset() { - *x = Data_Database{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_conf_conf_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data_Database) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data_Database) ProtoMessage() {} - -func (x *Data_Database) ProtoReflect() protoreflect.Message { - mi := &file_internal_conf_conf_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data_Database.ProtoReflect.Descriptor instead. -func (*Data_Database) Descriptor() ([]byte, []int) { - return file_internal_conf_conf_proto_rawDescGZIP(), []int{2, 0} -} - -func (x *Data_Database) GetDriver() string { - if x != nil { - return x.Driver - } - return "" -} - -func (x *Data_Database) GetSource() string { - if x != nil { - return x.Source - } - return "" -} - -type Data_Redis struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - ReadTimeout *durationpb.Duration `protobuf:"bytes,3,opt,name=read_timeout,json=readTimeout,proto3" json:"read_timeout,omitempty"` - WriteTimeout *durationpb.Duration `protobuf:"bytes,4,opt,name=write_timeout,json=writeTimeout,proto3" json:"write_timeout,omitempty"` -} - -func (x *Data_Redis) Reset() { - *x = Data_Redis{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_conf_conf_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data_Redis) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data_Redis) ProtoMessage() {} - -func (x *Data_Redis) ProtoReflect() protoreflect.Message { - mi := &file_internal_conf_conf_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data_Redis.ProtoReflect.Descriptor instead. -func (*Data_Redis) Descriptor() ([]byte, []int) { - return file_internal_conf_conf_proto_rawDescGZIP(), []int{2, 1} -} - -func (x *Data_Redis) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Data_Redis) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Data_Redis) GetReadTimeout() *durationpb.Duration { - if x != nil { - return x.ReadTimeout - } - return nil -} - -func (x *Data_Redis) GetWriteTimeout() *durationpb.Duration { - if x != nil { - return x.WriteTimeout - } - return nil -} - -var File_internal_conf_conf_proto protoreflect.FileDescriptor - -var file_internal_conf_conf_proto_rawDesc = []byte{ - 0x0a, 0x18, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x2f, - 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x6b, 0x72, 0x61, 0x74, - 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5d, 0x0a, 0x09, 0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74, - 0x72, 0x61, 0x70, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, - 0x24, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, - 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x52, - 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xb8, 0x02, 0x0a, 0x06, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x12, 0x2b, 0x0a, 0x04, 0x68, 0x74, 0x74, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, - 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x65, 0x72, 0x76, - 0x65, 0x72, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x04, 0x68, 0x74, 0x74, 0x70, 0x12, 0x2b, 0x0a, - 0x04, 0x67, 0x72, 0x70, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6b, 0x72, - 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, - 0x47, 0x52, 0x50, 0x43, 0x52, 0x04, 0x67, 0x72, 0x70, 0x63, 0x1a, 0x69, 0x0a, 0x04, 0x48, 0x54, - 0x54, 0x50, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, - 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, - 0x12, 0x33, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, - 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x1a, 0x69, 0x0a, 0x04, 0x47, 0x52, 0x50, 0x43, 0x12, 0x18, 0x0a, - 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x33, 0x0a, 0x07, 0x74, - 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, - 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, - 0x22, 0xdd, 0x02, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, 0x35, 0x0a, 0x08, 0x64, 0x61, 0x74, - 0x61, 0x62, 0x61, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x6b, 0x72, - 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x44, 0x61, - 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, - 0x12, 0x2c, 0x0a, 0x05, 0x72, 0x65, 0x64, 0x69, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x16, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x61, 0x74, - 0x61, 0x2e, 0x52, 0x65, 0x64, 0x69, 0x73, 0x52, 0x05, 0x72, 0x65, 0x64, 0x69, 0x73, 0x1a, 0x3a, - 0x0a, 0x08, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x72, - 0x69, 0x76, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x72, 0x69, 0x76, - 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0xb3, 0x01, 0x0a, 0x05, 0x52, - 0x65, 0x64, 0x69, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, - 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, - 0x64, 0x72, 0x12, 0x3c, 0x0a, 0x0c, 0x72, 0x65, 0x61, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, - 0x75, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x72, 0x65, 0x61, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, - 0x12, 0x3e, 0x0a, 0x0d, 0x77, 0x72, 0x69, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, - 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x52, 0x0c, 0x77, 0x72, 0x69, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, - 0x42, 0x37, 0x5a, 0x35, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, - 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2d, - 0x6c, 0x61, 0x79, 0x6f, 0x75, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, - 0x63, 0x6f, 0x6e, 0x66, 0x3b, 0x63, 0x6f, 0x6e, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, -} - -var ( - file_internal_conf_conf_proto_rawDescOnce sync.Once - file_internal_conf_conf_proto_rawDescData = file_internal_conf_conf_proto_rawDesc -) - -func file_internal_conf_conf_proto_rawDescGZIP() []byte { - file_internal_conf_conf_proto_rawDescOnce.Do(func() { - file_internal_conf_conf_proto_rawDescData = protoimpl.X.CompressGZIP(file_internal_conf_conf_proto_rawDescData) - }) - return file_internal_conf_conf_proto_rawDescData -} - -var file_internal_conf_conf_proto_msgTypes = make([]protoimpl.MessageInfo, 7) -var file_internal_conf_conf_proto_goTypes = []interface{}{ - (*Bootstrap)(nil), // 0: kratos.api.Bootstrap - (*Server)(nil), // 1: kratos.api.Server - (*Data)(nil), // 2: kratos.api.Data - (*Server_HTTP)(nil), // 3: kratos.api.Server.HTTP - (*Server_GRPC)(nil), // 4: kratos.api.Server.GRPC - (*Data_Database)(nil), // 5: kratos.api.Data.Database - (*Data_Redis)(nil), // 6: kratos.api.Data.Redis - (*durationpb.Duration)(nil), // 7: google.protobuf.Duration -} -var file_internal_conf_conf_proto_depIdxs = []int32{ - 1, // 0: kratos.api.Bootstrap.server:type_name -> kratos.api.Server - 2, // 1: kratos.api.Bootstrap.data:type_name -> kratos.api.Data - 3, // 2: kratos.api.Server.http:type_name -> kratos.api.Server.HTTP - 4, // 3: kratos.api.Server.grpc:type_name -> kratos.api.Server.GRPC - 5, // 4: kratos.api.Data.database:type_name -> kratos.api.Data.Database - 6, // 5: kratos.api.Data.redis:type_name -> kratos.api.Data.Redis - 7, // 6: kratos.api.Server.HTTP.timeout:type_name -> google.protobuf.Duration - 7, // 7: kratos.api.Server.GRPC.timeout:type_name -> google.protobuf.Duration - 7, // 8: kratos.api.Data.Redis.read_timeout:type_name -> google.protobuf.Duration - 7, // 9: kratos.api.Data.Redis.write_timeout:type_name -> google.protobuf.Duration - 10, // [10:10] is the sub-list for method output_type - 10, // [10:10] is the sub-list for method input_type - 10, // [10:10] is the sub-list for extension type_name - 10, // [10:10] is the sub-list for extension extendee - 0, // [0:10] is the sub-list for field type_name -} - -func init() { file_internal_conf_conf_proto_init() } -func file_internal_conf_conf_proto_init() { - if File_internal_conf_conf_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_internal_conf_conf_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Bootstrap); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_conf_conf_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_conf_conf_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_conf_conf_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server_HTTP); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_conf_conf_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server_GRPC); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_conf_conf_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data_Database); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_conf_conf_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data_Redis); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_internal_conf_conf_proto_rawDesc, - NumEnums: 0, - NumMessages: 7, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_internal_conf_conf_proto_goTypes, - DependencyIndexes: file_internal_conf_conf_proto_depIdxs, - MessageInfos: file_internal_conf_conf_proto_msgTypes, - }.Build() - File_internal_conf_conf_proto = out.File - file_internal_conf_conf_proto_rawDesc = nil - file_internal_conf_conf_proto_goTypes = nil - file_internal_conf_conf_proto_depIdxs = nil -} diff --git a/examples/i18n/internal/conf/conf.proto b/examples/i18n/internal/conf/conf.proto deleted file mode 100644 index 6fabfa5f0..000000000 --- a/examples/i18n/internal/conf/conf.proto +++ /dev/null @@ -1,41 +0,0 @@ -syntax = "proto3"; -package kratos.api; - -option go_package = "github.com/go-kratos/kratos/examples/i18n/internal/conf;conf"; - -import "google/protobuf/duration.proto"; - -message Bootstrap { - Server server = 1; - Data data = 2; -} - -message Server { - message HTTP { - string network = 1; - string addr = 2; - google.protobuf.Duration timeout = 3; - } - message GRPC { - string network = 1; - string addr = 2; - google.protobuf.Duration timeout = 3; - } - HTTP http = 1; - GRPC grpc = 2; -} - -message Data { - message Database { - string driver = 1; - string source = 2; - } - message Redis { - string network = 1; - string addr = 2; - google.protobuf.Duration read_timeout = 3; - google.protobuf.Duration write_timeout = 4; - } - Database database = 1; - Redis redis = 2; -} diff --git a/examples/i18n/internal/data/README.md b/examples/i18n/internal/data/README.md deleted file mode 100644 index 599c41b4d..000000000 --- a/examples/i18n/internal/data/README.md +++ /dev/null @@ -1 +0,0 @@ -# Data diff --git a/examples/i18n/internal/data/data.go b/examples/i18n/internal/data/data.go deleted file mode 100644 index 269e9f18d..000000000 --- a/examples/i18n/internal/data/data.go +++ /dev/null @@ -1,22 +0,0 @@ -package data - -import ( - "github.com/go-kratos/kratos/examples/i18n/internal/conf" - "github.com/go-kratos/kratos/v2/log" - "github.com/google/wire" -) - -// ProviderSet is data providers. -var ProviderSet = wire.NewSet(NewData, NewGreeterRepo) - -// Data . -type Data struct { // TODO wrapped database client -} - -// NewData . -func NewData(c *conf.Data, logger log.Logger) (*Data, func(), error) { - cleanup := func() { - _ = logger.Log(log.LevelInfo, "closing the data resources") - } - return &Data{}, cleanup, nil -} diff --git a/examples/i18n/internal/data/greeter.go b/examples/i18n/internal/data/greeter.go deleted file mode 100644 index 20002cb99..000000000 --- a/examples/i18n/internal/data/greeter.go +++ /dev/null @@ -1,29 +0,0 @@ -package data - -import ( - "context" - - "github.com/go-kratos/kratos/examples/i18n/internal/biz" - "github.com/go-kratos/kratos/v2/log" -) - -type greeterRepo struct { - data *Data - log *log.Helper -} - -// NewGreeterRepo . -func NewGreeterRepo(data *Data, logger log.Logger) biz.GreeterRepo { - return &greeterRepo{ - data: data, - log: log.NewHelper(logger), - } -} - -func (r *greeterRepo) CreateGreeter(ctx context.Context, g *biz.Greeter) error { - return nil -} - -func (r *greeterRepo) UpdateGreeter(ctx context.Context, g *biz.Greeter) error { - return nil -} diff --git a/examples/i18n/internal/pkg/middleware/localize/localize.go b/examples/i18n/internal/pkg/middleware/localize/localize.go deleted file mode 100644 index d865a647c..000000000 --- a/examples/i18n/internal/pkg/middleware/localize/localize.go +++ /dev/null @@ -1,36 +0,0 @@ -package localize - -import ( - "context" - - "github.com/BurntSushi/toml" - "github.com/nicksnyder/go-i18n/v2/i18n" - "golang.org/x/text/language" - - "github.com/go-kratos/kratos/v2/middleware" - "github.com/go-kratos/kratos/v2/transport" -) - -type localizerKey struct{} - -func I18N() middleware.Middleware { - bundle := i18n.NewBundle(language.English) - bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal) - bundle.MustLoadMessageFile("../../active.zh.toml") - - return func(handler middleware.Handler) middleware.Handler { - return func(ctx context.Context, req interface{}) (reply interface{}, err error) { - if tr, ok := transport.FromServerContext(ctx); ok { - accept := tr.RequestHeader().Get("accept-language") - println(accept) - localizer := i18n.NewLocalizer(bundle, accept) - ctx = context.WithValue(ctx, localizerKey{}, localizer) - } - return handler(ctx, req) - } - } -} - -func FromContext(ctx context.Context) *i18n.Localizer { - return ctx.Value(localizerKey{}).(*i18n.Localizer) -} diff --git a/examples/i18n/internal/server/grpc.go b/examples/i18n/internal/server/grpc.go deleted file mode 100644 index 2858baece..000000000 --- a/examples/i18n/internal/server/grpc.go +++ /dev/null @@ -1,39 +0,0 @@ -package server - -import ( - v1 "github.com/go-kratos/kratos/examples/i18n/api/helloworld/v1" - "github.com/go-kratos/kratos/examples/i18n/internal/conf" - "github.com/go-kratos/kratos/examples/i18n/internal/service" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/metrics" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/middleware/tracing" - "github.com/go-kratos/kratos/v2/middleware/validate" - "github.com/go-kratos/kratos/v2/transport/grpc" -) - -// NewGRPCServer new a gRPC server. -func NewGRPCServer(c *conf.Server, greeter *service.GreeterService, logger log.Logger) *grpc.Server { - opts := []grpc.ServerOption{ - grpc.Middleware( - recovery.Recovery(), - tracing.Server(), - logging.Server(logger), - metrics.Server(), - validate.Validator(), - ), - } - if c.Grpc.Network != "" { - opts = append(opts, grpc.Network(c.Grpc.Network)) - } - if c.Grpc.Addr != "" { - opts = append(opts, grpc.Address(c.Grpc.Addr)) - } - if c.Grpc.Timeout != nil { - opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) - } - srv := grpc.NewServer(opts...) - v1.RegisterGreeterServer(srv, greeter) - return srv -} diff --git a/examples/i18n/internal/server/http.go b/examples/i18n/internal/server/http.go deleted file mode 100644 index cb94fdc37..000000000 --- a/examples/i18n/internal/server/http.go +++ /dev/null @@ -1,41 +0,0 @@ -package server - -import ( - v1 "github.com/go-kratos/kratos/examples/i18n/api/helloworld/v1" - "github.com/go-kratos/kratos/examples/i18n/internal/conf" - "github.com/go-kratos/kratos/examples/i18n/internal/pkg/middleware/localize" - "github.com/go-kratos/kratos/examples/i18n/internal/service" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/metrics" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/middleware/tracing" - "github.com/go-kratos/kratos/v2/middleware/validate" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// NewHTTPServer new a HTTP server. -func NewHTTPServer(c *conf.Server, greeter *service.GreeterService, logger log.Logger) *http.Server { - opts := []http.ServerOption{ - http.Middleware( - recovery.Recovery(), - tracing.Server(), - logging.Server(logger), - metrics.Server(), - localize.I18N(), - validate.Validator(), - ), - } - if c.Http.Network != "" { - opts = append(opts, http.Network(c.Http.Network)) - } - if c.Http.Addr != "" { - opts = append(opts, http.Address(c.Http.Addr)) - } - if c.Http.Timeout != nil { - opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration())) - } - srv := http.NewServer(opts...) - v1.RegisterGreeterHTTPServer(srv, greeter) - return srv -} diff --git a/examples/i18n/internal/server/server.go b/examples/i18n/internal/server/server.go deleted file mode 100644 index 4d267a7a3..000000000 --- a/examples/i18n/internal/server/server.go +++ /dev/null @@ -1,8 +0,0 @@ -package server - -import ( - "github.com/google/wire" -) - -// ProviderSet is server providers. -var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer) diff --git a/examples/i18n/internal/service/README.md b/examples/i18n/internal/service/README.md deleted file mode 100644 index 42321b7b1..000000000 --- a/examples/i18n/internal/service/README.md +++ /dev/null @@ -1 +0,0 @@ -# Service diff --git a/examples/i18n/internal/service/greeter.go b/examples/i18n/internal/service/greeter.go deleted file mode 100644 index 8ddf181da..000000000 --- a/examples/i18n/internal/service/greeter.go +++ /dev/null @@ -1,50 +0,0 @@ -package service - -import ( - "context" - - "github.com/go-kratos/kratos/examples/i18n/internal/pkg/middleware/localize" - "github.com/nicksnyder/go-i18n/v2/i18n" - - v1 "github.com/go-kratos/kratos/examples/i18n/api/helloworld/v1" - "github.com/go-kratos/kratos/examples/i18n/internal/biz" - "github.com/go-kratos/kratos/v2/log" -) - -// GreeterService is a greeter service. -type GreeterService struct { - v1.UnimplementedGreeterServer - - uc *biz.GreeterUsecase - log *log.Helper -} - -// NewGreeterService new a greeter service. -func NewGreeterService(uc *biz.GreeterUsecase, logger log.Logger) *GreeterService { - return &GreeterService{uc: uc, log: log.NewHelper(logger)} -} - -// SayHello implements helloworld.GreeterServer -func (s *GreeterService) SayHello(ctx context.Context, in *v1.HelloRequest) (*v1.HelloReply, error) { - s.log.WithContext(ctx).Infof("SayHello Received: %v", in.GetName()) - - if in.GetName() == "error" { - return nil, v1.ErrorUserNotFound("user not found: %s", in.GetName()) - } - localizer := localize.FromContext(ctx) - helloMsg, err := localizer.Localize(&i18n.LocalizeConfig{ - DefaultMessage: &i18n.Message{ - Description: "sayhello", - ID: "sayHello", - One: "Hello {{.Name}}", - Other: "Hello {{.Name}}", - }, - TemplateData: map[string]interface{}{ - "Name": in.Name, - }, - }) - if err != nil { - return nil, err - } - return &v1.HelloReply{Message: helloMsg}, nil -} diff --git a/examples/i18n/internal/service/service.go b/examples/i18n/internal/service/service.go deleted file mode 100644 index 5e328403f..000000000 --- a/examples/i18n/internal/service/service.go +++ /dev/null @@ -1,6 +0,0 @@ -package service - -import "github.com/google/wire" - -// ProviderSet is service providers. -var ProviderSet = wire.NewSet(NewGreeterService) diff --git a/examples/i18n/third_party/README.md b/examples/i18n/third_party/README.md deleted file mode 100644 index 005faa2cf..000000000 --- a/examples/i18n/third_party/README.md +++ /dev/null @@ -1 +0,0 @@ -# third_party diff --git a/examples/i18n/third_party/errors/errors.proto b/examples/i18n/third_party/errors/errors.proto deleted file mode 100644 index 0963d91aa..000000000 --- a/examples/i18n/third_party/errors/errors.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; - -package errors; - -option go_package = "github.com/go-kratos/kratos/v2/errors;errors"; -option java_multiple_files = true; -option java_package = "com.github.kratos.errors"; -option objc_class_prefix = "KratosErrors"; - -import "google/protobuf/descriptor.proto"; - -extend google.protobuf.EnumOptions { - int32 default_code = 1108; -} - -extend google.protobuf.EnumValueOptions { - int32 code = 1109; -} \ No newline at end of file diff --git a/examples/i18n/third_party/google/api/annotations.proto b/examples/i18n/third_party/google/api/annotations.proto deleted file mode 100644 index 85c361b47..000000000 --- a/examples/i18n/third_party/google/api/annotations.proto +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2015, Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package google.api; - -import "google/api/http.proto"; -import "google/protobuf/descriptor.proto"; - -option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; -option java_multiple_files = true; -option java_outer_classname = "AnnotationsProto"; -option java_package = "com.google.api"; -option objc_class_prefix = "GAPI"; - -extend google.protobuf.MethodOptions { - // See `HttpRule`. - HttpRule http = 72295728; -} diff --git a/examples/i18n/third_party/google/api/http.proto b/examples/i18n/third_party/google/api/http.proto deleted file mode 100644 index 69460cf79..000000000 --- a/examples/i18n/third_party/google/api/http.proto +++ /dev/null @@ -1,375 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package google.api; - -option cc_enable_arenas = true; -option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; -option java_multiple_files = true; -option java_outer_classname = "HttpProto"; -option java_package = "com.google.api"; -option objc_class_prefix = "GAPI"; - -// Defines the HTTP configuration for an API service. It contains a list of -// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method -// to one or more HTTP REST API methods. -message Http { - // A list of HTTP configuration rules that apply to individual API methods. - // - // **NOTE:** All service configuration rules follow "last one wins" order. - repeated HttpRule rules = 1; - - // When set to true, URL path parameters will be fully URI-decoded except in - // cases of single segment matches in reserved expansion, where "%2F" will be - // left encoded. - // - // The default behavior is to not decode RFC 6570 reserved characters in multi - // segment matches. - bool fully_decode_reserved_expansion = 2; -} - -// # gRPC Transcoding -// -// gRPC Transcoding is a feature for mapping between a gRPC method and one or -// more HTTP REST endpoints. It allows developers to build a single API service -// that supports both gRPC APIs and REST APIs. Many systems, including [Google -// APIs](https://github.com/googleapis/googleapis), -// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC -// Gateway](https://github.com/grpc-ecosystem/grpc-gateway), -// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature -// and use it for large scale production services. -// -// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies -// how different portions of the gRPC request message are mapped to the URL -// path, URL query parameters, and HTTP request body. It also controls how the -// gRPC response message is mapped to the HTTP response body. `HttpRule` is -// typically specified as an `google.api.http` annotation on the gRPC method. -// -// Each mapping specifies a URL path template and an HTTP method. The path -// template may refer to one or more fields in the gRPC request message, as long -// as each field is a non-repeated field with a primitive (non-message) type. -// The path template controls how fields of the request message are mapped to -// the URL path. -// -// Example: -// -// service Messaging { -// rpc GetMessage(GetMessageRequest) returns (Message) { -// option (google.api.http) = { -// get: "/v1/{name=messages/*}" -// }; -// } -// } -// message GetMessageRequest { -// string name = 1; // Mapped to URL path. -// } -// message Message { -// string text = 1; // The resource content. -// } -// -// This enables an HTTP REST to gRPC mapping as below: -// -// HTTP | gRPC -// -----|----- -// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` -// -// Any fields in the request message which are not bound by the path template -// automatically become HTTP query parameters if there is no HTTP request body. -// For example: -// -// service Messaging { -// rpc GetMessage(GetMessageRequest) returns (Message) { -// option (google.api.http) = { -// get:"/v1/messages/{message_id}" -// }; -// } -// } -// message GetMessageRequest { -// message SubMessage { -// string subfield = 1; -// } -// string message_id = 1; // Mapped to URL path. -// int64 revision = 2; // Mapped to URL query parameter `revision`. -// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. -// } -// -// This enables a HTTP JSON to RPC mapping as below: -// -// HTTP | gRPC -// -----|----- -// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | -// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: -// "foo"))` -// -// Note that fields which are mapped to URL query parameters must have a -// primitive type or a repeated primitive type or a non-repeated message type. -// In the case of a repeated type, the parameter can be repeated in the URL -// as `...?param=A¶m=B`. In the case of a message type, each field of the -// message is mapped to a separate parameter, such as -// `...?foo.a=A&foo.b=B&foo.c=C`. -// -// For HTTP methods that allow a request body, the `body` field -// specifies the mapping. Consider a REST update method on the -// message resource collection: -// -// service Messaging { -// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { -// option (google.api.http) = { -// patch: "/v1/messages/{message_id}" -// body: "message" -// }; -// } -// } -// message UpdateMessageRequest { -// string message_id = 1; // mapped to the URL -// Message message = 2; // mapped to the body -// } -// -// The following HTTP JSON to RPC mapping is enabled, where the -// representation of the JSON in the request body is determined by -// protos JSON encoding: -// -// HTTP | gRPC -// -----|----- -// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: -// "123456" message { text: "Hi!" })` -// -// The special name `*` can be used in the body mapping to define that -// every field not bound by the path template should be mapped to the -// request body. This enables the following alternative definition of -// the update method: -// -// service Messaging { -// rpc UpdateMessage(Message) returns (Message) { -// option (google.api.http) = { -// patch: "/v1/messages/{message_id}" -// body: "*" -// }; -// } -// } -// message Message { -// string message_id = 1; -// string text = 2; -// } -// -// -// The following HTTP JSON to RPC mapping is enabled: -// -// HTTP | gRPC -// -----|----- -// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: -// "123456" text: "Hi!")` -// -// Note that when using `*` in the body mapping, it is not possible to -// have HTTP parameters, as all fields not bound by the path end in -// the body. This makes this option more rarely used in practice when -// defining REST APIs. The common usage of `*` is in custom methods -// which don't use the URL at all for transferring data. -// -// It is possible to define multiple HTTP methods for one RPC by using -// the `additional_bindings` option. Example: -// -// service Messaging { -// rpc GetMessage(GetMessageRequest) returns (Message) { -// option (google.api.http) = { -// get: "/v1/messages/{message_id}" -// additional_bindings { -// get: "/v1/users/{user_id}/messages/{message_id}" -// } -// }; -// } -// } -// message GetMessageRequest { -// string message_id = 1; -// string user_id = 2; -// } -// -// This enables the following two alternative HTTP JSON to RPC mappings: -// -// HTTP | gRPC -// -----|----- -// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` -// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: -// "123456")` -// -// ## Rules for HTTP mapping -// -// 1. Leaf request fields (recursive expansion nested messages in the request -// message) are classified into three categories: -// - Fields referred by the path template. They are passed via the URL path. -// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They are passed via the HTTP -// request body. -// - All other fields are passed via the URL query parameters, and the -// parameter name is the field path in the request message. A repeated -// field can be represented as multiple query parameters under the same -// name. -// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL query parameter, all fields -// are passed via URL path and HTTP request body. -// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP request body, all -// fields are passed via URL path and URL query parameters. -// -// ### Path template syntax -// -// Template = "/" Segments [ Verb ] ; -// Segments = Segment { "/" Segment } ; -// Segment = "*" | "**" | LITERAL | Variable ; -// Variable = "{" FieldPath [ "=" Segments ] "}" ; -// FieldPath = IDENT { "." IDENT } ; -// Verb = ":" LITERAL ; -// -// The syntax `*` matches a single URL path segment. The syntax `**` matches -// zero or more URL path segments, which must be the last part of the URL path -// except the `Verb`. -// -// The syntax `Variable` matches part of the URL path as specified by its -// template. A variable template must not contain other variables. If a variable -// matches a single path segment, its template may be omitted, e.g. `{var}` -// is equivalent to `{var=*}`. -// -// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` -// contains any reserved character, such characters should be percent-encoded -// before the matching. -// -// If a variable contains exactly one path segment, such as `"{var}"` or -// `"{var=*}"`, when such a variable is expanded into a URL path on the client -// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The -// server side does the reverse decoding. Such variables show up in the -// [Discovery -// Document](https://developers.google.com/discovery/v1/reference/apis) as -// `{var}`. -// -// If a variable contains multiple path segments, such as `"{var=foo/*}"` -// or `"{var=**}"`, when such a variable is expanded into a URL path on the -// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. -// The server side does the reverse decoding, except "%2F" and "%2f" are left -// unchanged. Such variables show up in the -// [Discovery -// Document](https://developers.google.com/discovery/v1/reference/apis) as -// `{+var}`. -// -// ## Using gRPC API Service Configuration -// -// gRPC API Service Configuration (service config) is a configuration language -// for configuring a gRPC service to become a user-facing product. The -// service config is simply the YAML representation of the `google.api.Service` -// proto message. -// -// As an alternative to annotating your proto file, you can configure gRPC -// transcoding in your service config YAML files. You do this by specifying a -// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same -// effect as the proto annotation. This can be particularly useful if you -// have a proto that is reused in multiple services. Note that any transcoding -// specified in the service config will override any matching transcoding -// configuration in the proto. -// -// Example: -// -// http: -// rules: -// # Selects a gRPC method and applies HttpRule to it. -// - selector: example.v1.Messaging.GetMessage -// get: /v1/messages/{message_id}/{sub.subfield} -// -// ## Special notes -// -// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the -// proto to JSON conversion must follow the [proto3 -// specification](https://developers.google.com/protocol-buffers/docs/proto3#json). -// -// While the single segment variable follows the semantics of -// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String -// Expansion, the multi segment variable **does not** follow RFC 6570 Section -// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion -// does not expand special characters like `?` and `#`, which would lead -// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding -// for multi segment variables. -// -// The path variables **must not** refer to any repeated or mapped field, -// because client libraries are not capable of handling such variable expansion. -// -// The path variables **must not** capture the leading "/" character. The reason -// is that the most common use case "{var}" does not capture the leading "/" -// character. For consistency, all path variables must share the same behavior. -// -// Repeated message fields must not be mapped to URL query parameters, because -// no client library can support such complicated mapping. -// -// If an API needs to use a JSON array for request or response body, it can map -// the request or response body to a repeated field. However, some gRPC -// Transcoding implementations may not support this feature. -message HttpRule { - // Selects a method to which this rule applies. - // - // Refer to [selector][google.api.DocumentationRule.selector] for syntax details. - string selector = 1; - - // Determines the URL pattern is matched by this rules. This pattern can be - // used with any of the {get|put|post|delete|patch} methods. A custom method - // can be defined using the 'custom' field. - oneof pattern { - // Maps to HTTP GET. Used for listing and getting information about - // resources. - string get = 2; - - // Maps to HTTP PUT. Used for replacing a resource. - string put = 3; - - // Maps to HTTP POST. Used for creating a resource or performing an action. - string post = 4; - - // Maps to HTTP DELETE. Used for deleting a resource. - string delete = 5; - - // Maps to HTTP PATCH. Used for updating a resource. - string patch = 6; - - // The custom pattern is used for specifying an HTTP method that is not - // included in the `pattern` field, such as HEAD, or "*" to leave the - // HTTP method unspecified for this rule. The wild-card rule is useful - // for services that provide content to Web (HTML) clients. - CustomHttpPattern custom = 8; - } - - // The name of the request field whose value is mapped to the HTTP request - // body, or `*` for mapping all request fields not captured by the path - // pattern to the HTTP body, or omitted for not having any HTTP request body. - // - // NOTE: the referred field must be present at the top-level of the request - // message type. - string body = 7; - - // Optional. The name of the response field whose value is mapped to the HTTP - // response body. When omitted, the entire response message will be used - // as the HTTP response body. - // - // NOTE: The referred field must be present at the top-level of the response - // message type. - string response_body = 12; - - // Additional HTTP bindings for the selector. Nested bindings must - // not contain an `additional_bindings` field themselves (that is, - // the nesting may only be one level deep). - repeated HttpRule additional_bindings = 11; -} - -// A custom pattern is used for defining custom HTTP verb. -message CustomHttpPattern { - // The name of this custom HTTP verb. - string kind = 1; - - // The path matched by this custom verb. - string path = 2; -} diff --git a/examples/i18n/third_party/google/api/httpbody.proto b/examples/i18n/third_party/google/api/httpbody.proto deleted file mode 100644 index 1a5bb78be..000000000 --- a/examples/i18n/third_party/google/api/httpbody.proto +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package google.api; - -import "google/protobuf/any.proto"; - -option cc_enable_arenas = true; -option go_package = "google.golang.org/genproto/googleapis/api/httpbody;httpbody"; -option java_multiple_files = true; -option java_outer_classname = "HttpBodyProto"; -option java_package = "com.google.api"; -option objc_class_prefix = "GAPI"; - -// Message that represents an arbitrary HTTP body. It should only be used for -// payload formats that can't be represented as JSON, such as raw binary or -// an HTML page. -// -// -// This message can be used both in streaming and non-streaming API methods in -// the request as well as the response. -// -// It can be used as a top-level request field, which is convenient if one -// wants to extract parameters from either the URL or HTTP template into the -// request fields and also want access to the raw HTTP body. -// -// Example: -// -// message GetResourceRequest { -// // A unique request id. -// string request_id = 1; -// -// // The raw HTTP body is bound to this field. -// google.api.HttpBody http_body = 2; -// } -// -// service ResourceService { -// rpc GetResource(GetResourceRequest) returns (google.api.HttpBody); -// rpc UpdateResource(google.api.HttpBody) returns -// (google.protobuf.Empty); -// } -// -// Example with streaming methods: -// -// service CaldavService { -// rpc GetCalendar(stream google.api.HttpBody) -// returns (stream google.api.HttpBody); -// rpc UpdateCalendar(stream google.api.HttpBody) -// returns (stream google.api.HttpBody); -// } -// -// Use of this type only changes how the request and response bodies are -// handled, all other features will continue to work unchanged. -message HttpBody { - // The HTTP Content-Type header value specifying the content type of the body. - string content_type = 1; - - // The HTTP request/response body as raw binary. - bytes data = 2; - - // Application specific response metadata. Must be set in the first response - // for streaming APIs. - repeated google.protobuf.Any extensions = 3; -} diff --git a/examples/i18n/third_party/validate/README.md b/examples/i18n/third_party/validate/README.md deleted file mode 100644 index 56698db8e..000000000 --- a/examples/i18n/third_party/validate/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# protoc-gen-validate (PGV) - -* https://github.com/envoyproxy/protoc-gen-validate diff --git a/examples/i18n/third_party/validate/validate.proto b/examples/i18n/third_party/validate/validate.proto deleted file mode 100644 index 867d4f76e..000000000 --- a/examples/i18n/third_party/validate/validate.proto +++ /dev/null @@ -1,863 +0,0 @@ -syntax = "proto2"; -package validate; - -option go_package = "github.com/envoyproxy/protoc-gen-validate/validate"; -option java_package = "io.envoyproxy.pgv.validate"; - -import "google/protobuf/descriptor.proto"; -import "google/protobuf/duration.proto"; -import "google/protobuf/timestamp.proto"; - -// Validation rules applied at the message level -extend google.protobuf.MessageOptions { - // Disabled nullifies any validation rules for this message, including any - // message fields associated with it that do support validation. - optional bool disabled = 1071; - // Ignore skips generation of validation methods for this message. - optional bool ignored = 1072; -} - -// Validation rules applied at the oneof level -extend google.protobuf.OneofOptions { - // Required ensures that exactly one the field options in a oneof is set; - // validation fails if no fields in the oneof are set. - optional bool required = 1071; -} - -// Validation rules applied at the field level -extend google.protobuf.FieldOptions { - // Rules specify the validations to be performed on this field. By default, - // no validation is performed against a field. - optional FieldRules rules = 1071; -} - -// FieldRules encapsulates the rules for each type of field. Depending on the -// field, the correct set should be used to ensure proper validations. -message FieldRules { - optional MessageRules message = 17; - oneof type { - // Scalar Field Types - FloatRules float = 1; - DoubleRules double = 2; - Int32Rules int32 = 3; - Int64Rules int64 = 4; - UInt32Rules uint32 = 5; - UInt64Rules uint64 = 6; - SInt32Rules sint32 = 7; - SInt64Rules sint64 = 8; - Fixed32Rules fixed32 = 9; - Fixed64Rules fixed64 = 10; - SFixed32Rules sfixed32 = 11; - SFixed64Rules sfixed64 = 12; - BoolRules bool = 13; - StringRules string = 14; - BytesRules bytes = 15; - - // Complex Field Types - EnumRules enum = 16; - RepeatedRules repeated = 18; - MapRules map = 19; - - // Well-Known Field Types - AnyRules any = 20; - DurationRules duration = 21; - TimestampRules timestamp = 22; - } -} - -// FloatRules describes the constraints applied to `float` values -message FloatRules { - // Const specifies that this field must be exactly the specified value - optional float const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional float lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional float lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional float gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional float gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated float in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated float not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// DoubleRules describes the constraints applied to `double` values -message DoubleRules { - // Const specifies that this field must be exactly the specified value - optional double const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional double lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional double lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional double gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional double gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated double in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated double not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// Int32Rules describes the constraints applied to `int32` values -message Int32Rules { - // Const specifies that this field must be exactly the specified value - optional int32 const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional int32 lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional int32 lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional int32 gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional int32 gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated int32 in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated int32 not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// Int64Rules describes the constraints applied to `int64` values -message Int64Rules { - // Const specifies that this field must be exactly the specified value - optional int64 const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional int64 lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional int64 lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional int64 gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional int64 gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated int64 in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated int64 not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// UInt32Rules describes the constraints applied to `uint32` values -message UInt32Rules { - // Const specifies that this field must be exactly the specified value - optional uint32 const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional uint32 lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional uint32 lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional uint32 gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional uint32 gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated uint32 in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated uint32 not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// UInt64Rules describes the constraints applied to `uint64` values -message UInt64Rules { - // Const specifies that this field must be exactly the specified value - optional uint64 const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional uint64 lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional uint64 lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional uint64 gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional uint64 gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated uint64 in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated uint64 not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// SInt32Rules describes the constraints applied to `sint32` values -message SInt32Rules { - // Const specifies that this field must be exactly the specified value - optional sint32 const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional sint32 lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional sint32 lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional sint32 gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional sint32 gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated sint32 in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated sint32 not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// SInt64Rules describes the constraints applied to `sint64` values -message SInt64Rules { - // Const specifies that this field must be exactly the specified value - optional sint64 const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional sint64 lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional sint64 lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional sint64 gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional sint64 gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated sint64 in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated sint64 not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// Fixed32Rules describes the constraints applied to `fixed32` values -message Fixed32Rules { - // Const specifies that this field must be exactly the specified value - optional fixed32 const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional fixed32 lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional fixed32 lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional fixed32 gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional fixed32 gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated fixed32 in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated fixed32 not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// Fixed64Rules describes the constraints applied to `fixed64` values -message Fixed64Rules { - // Const specifies that this field must be exactly the specified value - optional fixed64 const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional fixed64 lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional fixed64 lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional fixed64 gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional fixed64 gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated fixed64 in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated fixed64 not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// SFixed32Rules describes the constraints applied to `sfixed32` values -message SFixed32Rules { - // Const specifies that this field must be exactly the specified value - optional sfixed32 const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional sfixed32 lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional sfixed32 lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional sfixed32 gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional sfixed32 gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated sfixed32 in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated sfixed32 not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// SFixed64Rules describes the constraints applied to `sfixed64` values -message SFixed64Rules { - // Const specifies that this field must be exactly the specified value - optional sfixed64 const = 1; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional sfixed64 lt = 2; - - // Lte specifies that this field must be less than or equal to the - // specified value, inclusive - optional sfixed64 lte = 3; - - // Gt specifies that this field must be greater than the specified value, - // exclusive. If the value of Gt is larger than a specified Lt or Lte, the - // range is reversed. - optional sfixed64 gt = 4; - - // Gte specifies that this field must be greater than or equal to the - // specified value, inclusive. If the value of Gte is larger than a - // specified Lt or Lte, the range is reversed. - optional sfixed64 gte = 5; - - // In specifies that this field must be equal to one of the specified - // values - repeated sfixed64 in = 6; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated sfixed64 not_in = 7; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 8; -} - -// BoolRules describes the constraints applied to `bool` values -message BoolRules { - // Const specifies that this field must be exactly the specified value - optional bool const = 1; -} - -// StringRules describe the constraints applied to `string` values -message StringRules { - // Const specifies that this field must be exactly the specified value - optional string const = 1; - - // Len specifies that this field must be the specified number of - // characters (Unicode code points). Note that the number of - // characters may differ from the number of bytes in the string. - optional uint64 len = 19; - - // MinLen specifies that this field must be the specified number of - // characters (Unicode code points) at a minimum. Note that the number of - // characters may differ from the number of bytes in the string. - optional uint64 min_len = 2; - - // MaxLen specifies that this field must be the specified number of - // characters (Unicode code points) at a maximum. Note that the number of - // characters may differ from the number of bytes in the string. - optional uint64 max_len = 3; - - // LenBytes specifies that this field must be the specified number of bytes - // at a minimum - optional uint64 len_bytes = 20; - - // MinBytes specifies that this field must be the specified number of bytes - // at a minimum - optional uint64 min_bytes = 4; - - // MaxBytes specifies that this field must be the specified number of bytes - // at a maximum - optional uint64 max_bytes = 5; - - // Pattern specifes that this field must match against the specified - // regular expression (RE2 syntax). The included expression should elide - // any delimiters. - optional string pattern = 6; - - // Prefix specifies that this field must have the specified substring at - // the beginning of the string. - optional string prefix = 7; - - // Suffix specifies that this field must have the specified substring at - // the end of the string. - optional string suffix = 8; - - // Contains specifies that this field must have the specified substring - // anywhere in the string. - optional string contains = 9; - - // NotContains specifies that this field cannot have the specified substring - // anywhere in the string. - optional string not_contains = 23; - - // In specifies that this field must be equal to one of the specified - // values - repeated string in = 10; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated string not_in = 11; - - // WellKnown rules provide advanced constraints against common string - // patterns - oneof well_known { - // Email specifies that the field must be a valid email address as - // defined by RFC 5322 - bool email = 12; - - // Hostname specifies that the field must be a valid hostname as - // defined by RFC 1034. This constraint does not support - // internationalized domain names (IDNs). - bool hostname = 13; - - // Ip specifies that the field must be a valid IP (v4 or v6) address. - // Valid IPv6 addresses should not include surrounding square brackets. - bool ip = 14; - - // Ipv4 specifies that the field must be a valid IPv4 address. - bool ipv4 = 15; - - // Ipv6 specifies that the field must be a valid IPv6 address. Valid - // IPv6 addresses should not include surrounding square brackets. - bool ipv6 = 16; - - // Uri specifies that the field must be a valid, absolute URI as defined - // by RFC 3986 - bool uri = 17; - - // UriRef specifies that the field must be a valid URI as defined by RFC - // 3986 and may be relative or absolute. - bool uri_ref = 18; - - // Address specifies that the field must be either a valid hostname as - // defined by RFC 1034 (which does not support internationalized domain - // names or IDNs), or it can be a valid IP (v4 or v6). - bool address = 21; - - // Uuid specifies that the field must be a valid UUID as defined by - // RFC 4122 - bool uuid = 22; - - // WellKnownRegex specifies a common well known pattern defined as a regex. - KnownRegex well_known_regex = 24; - } - - // This applies to regexes HTTP_HEADER_NAME and HTTP_HEADER_VALUE to enable - // strict header validation. - // By default, this is true, and HTTP header validations are RFC-compliant. - // Setting to false will enable a looser validations that only disallows - // \r\n\0 characters, which can be used to bypass header matching rules. - optional bool strict = 25 [default = true]; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 26; -} - -// WellKnownRegex contain some well-known patterns. -enum KnownRegex { - UNKNOWN = 0; - - // HTTP header name as defined by RFC 7230. - HTTP_HEADER_NAME = 1; - - // HTTP header value as defined by RFC 7230. - HTTP_HEADER_VALUE = 2; -} - -// BytesRules describe the constraints applied to `bytes` values -message BytesRules { - // Const specifies that this field must be exactly the specified value - optional bytes const = 1; - - // Len specifies that this field must be the specified number of bytes - optional uint64 len = 13; - - // MinLen specifies that this field must be the specified number of bytes - // at a minimum - optional uint64 min_len = 2; - - // MaxLen specifies that this field must be the specified number of bytes - // at a maximum - optional uint64 max_len = 3; - - // Pattern specifes that this field must match against the specified - // regular expression (RE2 syntax). The included expression should elide - // any delimiters. - optional string pattern = 4; - - // Prefix specifies that this field must have the specified bytes at the - // beginning of the string. - optional bytes prefix = 5; - - // Suffix specifies that this field must have the specified bytes at the - // end of the string. - optional bytes suffix = 6; - - // Contains specifies that this field must have the specified bytes - // anywhere in the string. - optional bytes contains = 7; - - // In specifies that this field must be equal to one of the specified - // values - repeated bytes in = 8; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated bytes not_in = 9; - - // WellKnown rules provide advanced constraints against common byte - // patterns - oneof well_known { - // Ip specifies that the field must be a valid IP (v4 or v6) address in - // byte format - bool ip = 10; - - // Ipv4 specifies that the field must be a valid IPv4 address in byte - // format - bool ipv4 = 11; - - // Ipv6 specifies that the field must be a valid IPv6 address in byte - // format - bool ipv6 = 12; - } - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 14; -} - -// EnumRules describe the constraints applied to enum values -message EnumRules { - // Const specifies that this field must be exactly the specified value - optional int32 const = 1; - - // DefinedOnly specifies that this field must be only one of the defined - // values for this enum, failing on any undefined value. - optional bool defined_only = 2; - - // In specifies that this field must be equal to one of the specified - // values - repeated int32 in = 3; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated int32 not_in = 4; -} - -// MessageRules describe the constraints applied to embedded message values. -// For message-type fields, validation is performed recursively. -message MessageRules { - // Skip specifies that the validation rules of this field should not be - // evaluated - optional bool skip = 1; - - // Required specifies that this field must be set - optional bool required = 2; -} - -// RepeatedRules describe the constraints applied to `repeated` values -message RepeatedRules { - // MinItems specifies that this field must have the specified number of - // items at a minimum - optional uint64 min_items = 1; - - // MaxItems specifies that this field must have the specified number of - // items at a maximum - optional uint64 max_items = 2; - - // Unique specifies that all elements in this field must be unique. This - // constraint is only applicable to scalar and enum types (messages are not - // supported). - optional bool unique = 3; - - // Items specifies the constraints to be applied to each item in the field. - // Repeated message fields will still execute validation against each item - // unless skip is specified here. - optional FieldRules items = 4; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 5; -} - -// MapRules describe the constraints applied to `map` values -message MapRules { - // MinPairs specifies that this field must have the specified number of - // KVs at a minimum - optional uint64 min_pairs = 1; - - // MaxPairs specifies that this field must have the specified number of - // KVs at a maximum - optional uint64 max_pairs = 2; - - // NoSparse specifies values in this field cannot be unset. This only - // applies to map's with message value types. - optional bool no_sparse = 3; - - // Keys specifies the constraints to be applied to each key in the field. - optional FieldRules keys = 4; - - // Values specifies the constraints to be applied to the value of each key - // in the field. Message values will still have their validations evaluated - // unless skip is specified here. - optional FieldRules values = 5; - - // IgnoreEmpty specifies that the validation rules of this field should be - // evaluated only if the field is not empty - optional bool ignore_empty = 6; -} - -// AnyRules describe constraints applied exclusively to the -// `google.protobuf.Any` well-known type -message AnyRules { - // Required specifies that this field must be set - optional bool required = 1; - - // In specifies that this field's `type_url` must be equal to one of the - // specified values. - repeated string in = 2; - - // NotIn specifies that this field's `type_url` must not be equal to any of - // the specified values. - repeated string not_in = 3; -} - -// DurationRules describe the constraints applied exclusively to the -// `google.protobuf.Duration` well-known type -message DurationRules { - // Required specifies that this field must be set - optional bool required = 1; - - // Const specifies that this field must be exactly the specified value - optional google.protobuf.Duration const = 2; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional google.protobuf.Duration lt = 3; - - // Lt specifies that this field must be less than the specified value, - // inclusive - optional google.protobuf.Duration lte = 4; - - // Gt specifies that this field must be greater than the specified value, - // exclusive - optional google.protobuf.Duration gt = 5; - - // Gte specifies that this field must be greater than the specified value, - // inclusive - optional google.protobuf.Duration gte = 6; - - // In specifies that this field must be equal to one of the specified - // values - repeated google.protobuf.Duration in = 7; - - // NotIn specifies that this field cannot be equal to one of the specified - // values - repeated google.protobuf.Duration not_in = 8; -} - -// TimestampRules describe the constraints applied exclusively to the -// `google.protobuf.Timestamp` well-known type -message TimestampRules { - // Required specifies that this field must be set - optional bool required = 1; - - // Const specifies that this field must be exactly the specified value - optional google.protobuf.Timestamp const = 2; - - // Lt specifies that this field must be less than the specified value, - // exclusive - optional google.protobuf.Timestamp lt = 3; - - // Lte specifies that this field must be less than the specified value, - // inclusive - optional google.protobuf.Timestamp lte = 4; - - // Gt specifies that this field must be greater than the specified value, - // exclusive - optional google.protobuf.Timestamp gt = 5; - - // Gte specifies that this field must be greater than the specified value, - // inclusive - optional google.protobuf.Timestamp gte = 6; - - // LtNow specifies that this must be less than the current time. LtNow - // can only be used with the Within rule. - optional bool lt_now = 7; - - // GtNow specifies that this must be greater than the current time. GtNow - // can only be used with the Within rule. - optional bool gt_now = 8; - - // Within specifies that this field must be within this duration of the - // current time. This constraint can be used alone or with the LtNow and - // GtNow rules. - optional google.protobuf.Duration within = 9; -} diff --git a/examples/log/logrus.go b/examples/log/logrus.go deleted file mode 100644 index 1053a21a5..000000000 --- a/examples/log/logrus.go +++ /dev/null @@ -1,100 +0,0 @@ -package log - -import ( - "io" - "os" - - "github.com/go-kratos/kratos/v2/log" - "github.com/sirupsen/logrus" -) - -var _ log.Logger = (*LogrusLogger)(nil) - -type LogrusLogger struct { - log *logrus.Logger -} - -func NewLogrusLogger(options ...Option) log.Logger { - logger := logrus.New() - logger.Level = logrus.DebugLevel - logger.Out = os.Stdout - logger.Formatter = &logrus.JSONFormatter{} - for _, option := range options { - option(logger) - } - - return &LogrusLogger{ - log: logger, - } -} - -func (l *LogrusLogger) Log(level log.Level, keyvals ...interface{}) (err error) { - var ( - logrusLevel logrus.Level - fields logrus.Fields = make(map[string]interface{}) - msg string - ) - - switch level { - case log.LevelDebug: - logrusLevel = logrus.DebugLevel - case log.LevelInfo: - logrusLevel = logrus.InfoLevel - case log.LevelWarn: - logrusLevel = logrus.WarnLevel - case log.LevelError: - logrusLevel = logrus.ErrorLevel - default: - logrusLevel = logrus.DebugLevel - } - - if logrusLevel > l.log.Level { - return - } - - if len(keyvals) == 0 { - return nil - } - if len(keyvals)%2 != 0 { - keyvals = append(keyvals, "") - } - for i := 0; i < len(keyvals); i += 2 { - key, ok := keyvals[i].(string) - if !ok { - continue - } - if key == logrus.FieldKeyMsg { - msg, _ = keyvals[i+1].(string) - continue - } - fields[key] = keyvals[i+1] - } - - if len(fields) > 0 { - l.log.WithFields(fields).Log(logrusLevel, msg) - } else { - l.log.Log(logrusLevel, msg) - } - - return -} - -type Option func(log *logrus.Logger) - -func Level(level logrus.Level) Option { - return func(log *logrus.Logger) { - log.Level = level - } -} - -func Output(w io.Writer) Option { - return func(log *logrus.Logger) { - log.Out = w - } -} - -func Formatter(formatter logrus.Formatter) Option { - return func(log *logrus.Logger) { - log.Formatter = formatter - } -} diff --git a/examples/log/logrus_test.go b/examples/log/logrus_test.go deleted file mode 100644 index d5bbc7d32..000000000 --- a/examples/log/logrus_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package log - -import ( - "bytes" - "strings" - "testing" - - "github.com/go-kratos/kratos/v2/log" - "github.com/sirupsen/logrus" -) - -func TestLoggerLog(t *testing.T) { - tests := map[string]struct { - level logrus.Level - formatter logrus.Formatter - logLevel log.Level - kvs []interface{} - want string - }{ - "json format": { - level: logrus.InfoLevel, - formatter: &logrus.JSONFormatter{}, - logLevel: log.LevelInfo, - kvs: []interface{}{"case", "json format", "msg", "1"}, - want: `{"case":"json format","level":"info","msg":"1"`, - }, - "level unmatch": { - level: logrus.InfoLevel, - formatter: &logrus.JSONFormatter{}, - logLevel: log.LevelDebug, - kvs: []interface{}{"case", "level unmatch", "msg", "1"}, - want: "", - }, - "no tags": { - level: logrus.InfoLevel, - formatter: &logrus.JSONFormatter{}, - logLevel: log.LevelInfo, - kvs: []interface{}{"msg", "1"}, - want: `{"level":"info","msg":"1"`, - }, - } - - for name, test := range tests { - t.Run(name, func(t *testing.T) { - output := new(bytes.Buffer) - logger := NewLogrusLogger(Level(test.level), Formatter(test.formatter), Output(output)) - _ = logger.Log(test.logLevel, test.kvs...) - if !strings.HasPrefix(output.String(), test.want) { - t.Errorf("strings.HasPrefix(output.String(), test.want) got %v want: %v", strings.HasPrefix(output.String(), test.want), true) - } - }) - } -} diff --git a/examples/log/zap.go b/examples/log/zap.go deleted file mode 100644 index 338c465d5..000000000 --- a/examples/log/zap.go +++ /dev/null @@ -1,53 +0,0 @@ -package log - -import ( - "fmt" - "os" - - "github.com/go-kratos/kratos/v2/log" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -var _ log.Logger = (*ZapLogger)(nil) - -// ZapLogger is a logger impl. -type ZapLogger struct { - log *zap.Logger - Sync func() error -} - -// NewZapLogger return a zap logger. -func NewZapLogger(encoder zapcore.EncoderConfig, level zap.AtomicLevel, opts ...zap.Option) *ZapLogger { - core := zapcore.NewCore( - zapcore.NewConsoleEncoder(encoder), - zapcore.NewMultiWriteSyncer( - zapcore.AddSync(os.Stdout), - ), level) - zapLogger := zap.New(core, opts...) - return &ZapLogger{log: zapLogger, Sync: zapLogger.Sync} -} - -// Log Implementation of logger interface. -func (l *ZapLogger) Log(level log.Level, keyvals ...interface{}) error { - if len(keyvals) == 0 || len(keyvals)%2 != 0 { - l.log.Warn(fmt.Sprint("Keyvalues must appear in pairs: ", keyvals)) - return nil - } - // Zap.Field is used when keyvals pairs appear - var data []zap.Field - for i := 0; i < len(keyvals); i += 2 { - data = append(data, zap.Any(fmt.Sprint(keyvals[i]), fmt.Sprint(keyvals[i+1]))) - } - switch level { - case log.LevelDebug: - l.log.Debug("", data...) - case log.LevelInfo: - l.log.Info("", data...) - case log.LevelWarn: - l.log.Warn("", data...) - case log.LevelError: - l.log.Error("", data...) - } - return nil -} diff --git a/examples/log/zap_test.go b/examples/log/zap_test.go deleted file mode 100644 index d41de9aba..000000000 --- a/examples/log/zap_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package log - -import ( - "testing" - - "github.com/go-kratos/kratos/v2/log" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -func TestZapLogger(t *testing.T) { - encoder := zapcore.EncoderConfig{ - TimeKey: "t", - LevelKey: "level", - NameKey: "logger", - CallerKey: "caller", - MessageKey: "msg", - StacktraceKey: "stack", - EncodeTime: zapcore.ISO8601TimeEncoder, - LineEnding: zapcore.DefaultLineEnding, - EncodeLevel: zapcore.LowercaseLevelEncoder, - EncodeDuration: zapcore.SecondsDurationEncoder, - EncodeCaller: zapcore.FullCallerEncoder, - } - logger := NewZapLogger( - encoder, - zap.NewAtomicLevelAt(zapcore.DebugLevel), - zap.AddStacktrace( - zap.NewAtomicLevelAt(zapcore.ErrorLevel)), - zap.AddCaller(), - zap.AddCallerSkip(2), - zap.Development(), - ) - zlog := log.NewHelper(logger) - zlog.Infow("name", "kratos", "from", "opensource") - zlog.Infow("name", "kratos", "from") - - // zap stdout/stderr Sync bugs in OSX, see https://github.com/uber-go/zap/issues/370 - _ = logger.Sync() -} diff --git a/examples/metadata/client/main.go b/examples/metadata/client/main.go deleted file mode 100644 index 643a2a489..000000000 --- a/examples/metadata/client/main.go +++ /dev/null @@ -1,61 +0,0 @@ -package main - -import ( - "context" - "log" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/metadata" - mmd "github.com/go-kratos/kratos/v2/middleware/metadata" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -func main() { - callHTTP() - callGRPC() -} - -func callHTTP() { - conn, err := http.NewClient( - context.Background(), - http.WithMiddleware( - mmd.Client(), - ), - http.WithEndpoint("127.0.0.1:8000"), - ) - if err != nil { - panic(err) - } - defer conn.Close() - client := helloworld.NewGreeterHTTPClient(conn) - ctx := context.Background() - ctx = metadata.AppendToClientContext(ctx, "x-md-global-extra", "2233") - reply, err := client.SayHello(ctx, &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[http] SayHello %s\n", reply) -} - -func callGRPC() { - conn, err := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("127.0.0.1:9000"), - grpc.WithMiddleware( - mmd.Client(), - ), - ) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - client := helloworld.NewGreeterClient(conn) - ctx := context.Background() - ctx = metadata.AppendToClientContext(ctx, "x-md-global-extra", "2233") - reply, err := client.SayHello(ctx, &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[grpc] SayHello %+v \n", reply) -} diff --git a/examples/metadata/server/main.go b/examples/metadata/server/main.go deleted file mode 100644 index 3c92f8bad..000000000 --- a/examples/metadata/server/main.go +++ /dev/null @@ -1,66 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/metadata" - mmd "github.com/go-kratos/kratos/v2/middleware/metadata" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name = "helloworld" - // Version is the version of the compiled software. - // Version = "v1.0.0" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - var extra string - if md, ok := metadata.FromServerContext(ctx); ok { - extra = md.Get("x-md-global-extra") - } - return &helloworld.HelloReply{Message: fmt.Sprintf("Hello %s extra_meta: %s", in.Name, extra)}, nil -} - -func main() { - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - mmd.Server(), - )) - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - mmd.Server(), - ), - ) - - s := &server{} - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - app := kratos.New( - kratos.Name(Name), - kratos.Server( - httpSrv, - grpcSrv, - ), - ) - - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/metrics/main.go b/examples/metrics/main.go deleted file mode 100644 index c7a84d80c..000000000 --- a/examples/metrics/main.go +++ /dev/null @@ -1,92 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - - prom "github.com/go-kratos/kratos/contrib/metrics/prometheus/v2" - "github.com/go-kratos/kratos/v2/middleware/metrics" - "github.com/prometheus/client_golang/prometheus/promhttp" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/prometheus/client_golang/prometheus" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name = "metrics" - // Version is the version of the compiled software. - // Version = "v1.0.0" - - _metricSeconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: "server", - Subsystem: "requests", - Name: "duration_sec", - Help: "server requests duration(sec).", - Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.250, 0.5, 1}, - }, []string{"kind", "operation"}) - - _metricRequests = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "client", - Subsystem: "requests", - Name: "code_total", - Help: "The total number of processed requests", - }, []string{"kind", "operation", "code", "reason"}) -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - return &helloworld.HelloReply{Message: fmt.Sprintf("Hello %+v", in.Name)}, nil -} - -func init() { - prometheus.MustRegister(_metricSeconds, _metricRequests) -} - -func main() { - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - metrics.Server( - metrics.WithSeconds(prom.NewHistogram(_metricSeconds)), - metrics.WithRequests(prom.NewCounter(_metricRequests)), - ), - ), - ) - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - metrics.Server( - metrics.WithSeconds(prom.NewHistogram(_metricSeconds)), - metrics.WithRequests(prom.NewCounter(_metricRequests)), - ), - ), - ) - httpSrv.Handle("/metrics", promhttp.Handler()) - - s := &server{} - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - app := kratos.New( - kratos.Name(Name), - kratos.Server( - httpSrv, - grpcSrv, - ), - ) - - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/middleware/main.go b/examples/middleware/main.go deleted file mode 100644 index a0a58035b..000000000 --- a/examples/middleware/main.go +++ /dev/null @@ -1,69 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/middleware" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -type server struct { - helloworld.UnimplementedGreeterServer -} - -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - return &helloworld.HelloReply{Message: "hello"}, nil -} - -func authMiddleware(handler middleware.Handler) middleware.Handler { - return func(ctx context.Context, req interface{}) (reply interface{}, err error) { - log.Println("auth middleware in", req) - reply, err = handler(ctx, req) - fmt.Println("auth middleware out", reply) - return - } -} - -func loggingMiddleware(handler middleware.Handler) middleware.Handler { - return func(ctx context.Context, req interface{}) (reply interface{}, err error) { - fmt.Println("logging middleware in", req) - reply, err = handler(ctx, req) - fmt.Println("logging middleware out", reply) - return - } -} - -func main() { - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - loggingMiddleware, - authMiddleware, - ), - ) - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - loggingMiddleware, - authMiddleware, - ), - ) - s := &server{} - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - app := kratos.New( - kratos.Name("helloworld"), - kratos.Server( - httpSrv, - grpcSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/registry/consul/client/main.go b/examples/registry/consul/client/main.go deleted file mode 100644 index 8a81efb28..000000000 --- a/examples/registry/consul/client/main.go +++ /dev/null @@ -1,71 +0,0 @@ -package main - -import ( - "context" - "log" - "time" - - "github.com/go-kratos/kratos/contrib/registry/consul/v2" - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/hashicorp/consul/api" -) - -func main() { - consulCli, err := api.NewClient(api.DefaultConfig()) - if err != nil { - panic(err) - } - r := consul.New(consulCli) - - // new grpc client - conn, err := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("discovery:///helloworld"), - grpc.WithDiscovery(r), - ) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - gClient := helloworld.NewGreeterClient(conn) - - // new http client - hConn, err := http.NewClient( - context.Background(), - http.WithMiddleware( - recovery.Recovery(), - ), - http.WithEndpoint("discovery:///helloworld"), - http.WithDiscovery(r), - ) - if err != nil { - log.Fatal(err) - } - defer hConn.Close() - hClient := helloworld.NewGreeterHTTPClient(hConn) - - for { - time.Sleep(time.Second) - callGRPC(gClient) - callHTTP(hClient) - } -} - -func callGRPC(client helloworld.GreeterClient) { - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[grpc] SayHello %+v\n", reply) -} - -func callHTTP(client helloworld.GreeterHTTPClient) { - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[http] SayHello %s\n", reply.Message) -} diff --git a/examples/registry/consul/server/main.go b/examples/registry/consul/server/main.go deleted file mode 100644 index 6c19c00c8..000000000 --- a/examples/registry/consul/server/main.go +++ /dev/null @@ -1,70 +0,0 @@ -package main - -import ( - "context" - "fmt" - "os" - - "github.com/go-kratos/kratos/contrib/registry/consul/v2" - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/hashicorp/consul/api" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - return &helloworld.HelloReply{Message: fmt.Sprintf("Welcome %+v!", in.Name)}, nil -} - -func main() { - logger := log.NewStdLogger(os.Stdout) - log := log.NewHelper(logger) - - consulClient, err := api.NewClient(api.DefaultConfig()) - if err != nil { - log.Fatal(err) - } - - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - recovery.Recovery(), - logging.Server(logger), - ), - ) - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - recovery.Recovery(), - logging.Server(logger), - ), - ) - - s := &server{} - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - r := consul.New(consulClient) - app := kratos.New( - kratos.Name("helloworld"), - kratos.Server( - grpcSrv, - httpSrv, - ), - kratos.Registrar(r), - ) - - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/registry/discovery/client/main.go b/examples/registry/discovery/client/main.go deleted file mode 100644 index fbfab54b8..000000000 --- a/examples/registry/discovery/client/main.go +++ /dev/null @@ -1,58 +0,0 @@ -package main - -import ( - "context" - "log" - "time" - - srcgrpc "google.golang.org/grpc" - - "github.com/go-kratos/kratos/contrib/registry/discovery/v2" - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/transport/grpc" -) - -func main() { - r := discovery.New(&discovery.Config{ - Nodes: []string{"0.0.0.0:7171"}, - Env: "dev", - Region: "sh1", - Zone: "zone1", - Host: "localhost", - }, nil) - - connGRPC, err := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("discovery:///helloworld"), - grpc.WithDiscovery(r), - ) - if err != nil { - log.Fatal(err) - } - defer connGRPC.Close() - - //connHTTP, err := http.NewClient( - // context.Background(), - // http.WithEndpoint("discovery:///helloworld"), - // http.WithDiscovery(r), - // http.WithBlock(), - //) - //if err != nil { - // log.Fatal(err) - //} - //defer connHTTP.Close() - - for { - callGRPC(connGRPC) - time.Sleep(time.Second) - } -} - -func callGRPC(conn *srcgrpc.ClientConn) { - client := helloworld.NewGreeterClient(conn) - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[grpc] SayHello %+v\n", reply) -} diff --git a/examples/registry/discovery/server/main.go b/examples/registry/discovery/server/main.go deleted file mode 100644 index f54d47795..000000000 --- a/examples/registry/discovery/server/main.go +++ /dev/null @@ -1,70 +0,0 @@ -package main - -import ( - "context" - "fmt" - "os" - - "github.com/go-kratos/kratos/contrib/registry/discovery/v2" - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - return &helloworld.HelloReply{Message: fmt.Sprintf("Welcome %+v!", in.Name)}, nil -} - -func main() { - logger := log.NewStdLogger(os.Stdout) - logger = log.With(logger, "service", "example.registry.discovery") - - r := discovery.New(&discovery.Config{ - Nodes: []string{"0.0.0.0:7171"}, - Env: "dev", - Region: "sh1", - Zone: "zone1", - Host: "localhost", - }, logger) - - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - recovery.Recovery(), - ), - ) - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - recovery.Recovery(), - logging.Server(logger), - ), - ) - - s := &server{} - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - app := kratos.New( - kratos.Name("helloworld"), - kratos.Server( - httpSrv, - grpcSrv, - ), - kratos.Metadata(map[string]string{"color": "gray"}), - kratos.Registrar(r), - ) - if err := app.Run(); err != nil { - log.NewHelper(logger).Fatal(err) - } -} diff --git a/examples/registry/etcd/client/main.go b/examples/registry/etcd/client/main.go deleted file mode 100644 index c63feacd7..000000000 --- a/examples/registry/etcd/client/main.go +++ /dev/null @@ -1,69 +0,0 @@ -package main - -import ( - "context" - "log" - "time" - - "github.com/go-kratos/kratos/contrib/registry/etcd/v2" - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - clientv3 "go.etcd.io/etcd/client/v3" - srcgrpc "google.golang.org/grpc" -) - -func main() { - cli, err := clientv3.New(clientv3.Config{ - Endpoints: []string{"127.0.0.1:2379"}, - }) - if err != nil { - panic(err) - } - r := etcd.New(cli) - - connGRPC, err := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("discovery:///helloworld"), - grpc.WithDiscovery(r), - ) - if err != nil { - log.Fatal(err) - } - defer connGRPC.Close() - - connHTTP, err := http.NewClient( - context.Background(), - http.WithEndpoint("discovery:///helloworld"), - http.WithDiscovery(r), - http.WithBlock(), - ) - if err != nil { - log.Fatal(err) - } - defer connHTTP.Close() - - for { - callHTTP(r, connHTTP) - callGRPC(r, connGRPC) - time.Sleep(time.Second) - } -} - -func callGRPC(r *etcd.Registry, conn *srcgrpc.ClientConn) { - client := helloworld.NewGreeterClient(conn) - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[grpc] SayHello %+v\n", reply) -} - -func callHTTP(r *etcd.Registry, conn *http.Client) { - client := helloworld.NewGreeterHTTPClient(conn) - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[http] SayHello %+v\n", reply) -} diff --git a/examples/registry/etcd/cmuxServer/main.go b/examples/registry/etcd/cmuxServer/main.go deleted file mode 100644 index 7237c3aec..000000000 --- a/examples/registry/etcd/cmuxServer/main.go +++ /dev/null @@ -1,80 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - "net" - "strings" - - "github.com/go-kratos/kratos/contrib/registry/etcd/v2" - pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/soheilhy/cmux" - etcdclient "go.etcd.io/etcd/client/v3" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - pb.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { - return &pb.HelloReply{Message: fmt.Sprintf("Welcome %+v!", in.Name)}, nil -} - -func main() { - l, err := net.Listen("tcp", ":9091") - if err != nil { - log.Panic(err) - } - m := cmux.New(l) - - client, err := etcdclient.New(etcdclient.Config{ - Endpoints: []string{"127.0.0.1:2379"}, - }) - if err != nil { - log.Fatal(err) - } - - grpcSrv := grpc.NewServer( - grpc.Listener(m.MatchWithWriters(cmux.HTTP2MatchHeaderFieldPrefixSendSettings("content-type", "application/grpc"))), - grpc.Middleware( - recovery.Recovery(), - ), - ) - httpSrv := http.NewServer( - http.Listener(m.Match(cmux.Any())), - http.Middleware( - recovery.Recovery(), - ), - ) - - s := &server{} - pb.RegisterGreeterServer(grpcSrv, s) - pb.RegisterGreeterHTTPServer(httpSrv, s) - - r := etcd.New(client) - app := kratos.New( - kratos.Name("helloworld"), - kratos.Server( - httpSrv, - grpcSrv, - ), - kratos.Registrar(r), - ) - - go func() { - if err := m.Serve(); !strings.Contains(err.Error(), "use of closed network connection") { - panic(err) - } - }() - - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/registry/etcd/server/main.go b/examples/registry/etcd/server/main.go deleted file mode 100644 index 9589d4345..000000000 --- a/examples/registry/etcd/server/main.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - - "github.com/go-kratos/kratos/contrib/registry/etcd/v2" - pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - etcdclient "go.etcd.io/etcd/client/v3" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - pb.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { - return &pb.HelloReply{Message: fmt.Sprintf("Welcome %+v!", in.Name)}, nil -} - -func main() { - client, err := etcdclient.New(etcdclient.Config{ - Endpoints: []string{"127.0.0.1:2379"}, - }) - if err != nil { - log.Fatal(err) - } - - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - recovery.Recovery(), - ), - ) - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - recovery.Recovery(), - ), - ) - - s := &server{} - pb.RegisterGreeterServer(grpcSrv, s) - pb.RegisterGreeterHTTPServer(httpSrv, s) - - r := etcd.New(client) - app := kratos.New( - kratos.Name("helloworld"), - kratos.Server( - httpSrv, - grpcSrv, - ), - kratos.Registrar(r), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/registry/nacos/client/main.go b/examples/registry/nacos/client/main.go deleted file mode 100644 index 0b120e2f7..000000000 --- a/examples/registry/nacos/client/main.go +++ /dev/null @@ -1,57 +0,0 @@ -package main - -import ( - "context" - "log" - - "github.com/go-kratos/kratos/contrib/registry/nacos/v2" - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/nacos-group/nacos-sdk-go/clients" - "github.com/nacos-group/nacos-sdk-go/common/constant" - "github.com/nacos-group/nacos-sdk-go/vo" -) - -func main() { - sc := []constant.ServerConfig{ - *constant.NewServerConfig("127.0.0.1", 8848), - } - - cc := &constant.ClientConfig{ - NamespaceId: "public", - TimeoutMs: 5000, - NotLoadCacheAtStart: true, - LogDir: "/tmp/nacos/log", - CacheDir: "/tmp/nacos/cache", - RotateTime: "1h", - MaxAge: 3, - LogLevel: "debug", - } - - cli, err := clients.NewNamingClient( - vo.NacosClientParam{ - ClientConfig: cc, - ServerConfigs: sc, - }, - ) - if err != nil { - log.Panic(err) - } - - conn, err := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("discovery:///helloworld.grpc"), - grpc.WithDiscovery(nacos.New(cli)), - ) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - - client := helloworld.NewGreeterClient(conn) - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[grpc] SayHello %+v\n", reply) -} diff --git a/examples/registry/nacos/server/main.go b/examples/registry/nacos/server/main.go deleted file mode 100644 index f7e739247..000000000 --- a/examples/registry/nacos/server/main.go +++ /dev/null @@ -1,84 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - - "github.com/go-kratos/kratos/contrib/registry/nacos/v2" - pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/nacos-group/nacos-sdk-go/clients" - "github.com/nacos-group/nacos-sdk-go/common/constant" - "github.com/nacos-group/nacos-sdk-go/vo" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - pb.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { - return &pb.HelloReply{Message: fmt.Sprintf("Welcome %+v!", in.Name)}, nil -} - -func main() { - sc := []constant.ServerConfig{ - *constant.NewServerConfig("127.0.0.1", 8848), - } - - cc := constant.ClientConfig{ - NamespaceId: "public", - TimeoutMs: 5000, - NotLoadCacheAtStart: true, - LogDir: "/tmp/nacos/log", - CacheDir: "/tmp/nacos/cache", - RotateTime: "1h", - MaxAge: 3, - LogLevel: "debug", - } - - client, err := clients.NewNamingClient( - vo.NacosClientParam{ - ClientConfig: &cc, - ServerConfigs: sc, - }, - ) - if err != nil { - log.Panic(err) - } - - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - recovery.Recovery(), - ), - ) - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - recovery.Recovery(), - ), - ) - - s := &server{} - pb.RegisterGreeterServer(grpcSrv, s) - pb.RegisterGreeterHTTPServer(httpSrv, s) - - r := nacos.New(client) - app := kratos.New( - kratos.Name("helloworld"), - kratos.Server( - httpSrv, - grpcSrv, - ), - kratos.Registrar(r), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/registry/polaris/client/main.go b/examples/registry/polaris/client/main.go deleted file mode 100644 index 4bb591df3..000000000 --- a/examples/registry/polaris/client/main.go +++ /dev/null @@ -1,82 +0,0 @@ -package main - -import ( - "context" - "log" - "time" - - "github.com/go-kratos/kratos/contrib/registry/polaris/v2" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/registry" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/polarismesh/polaris-go/api" - "github.com/polarismesh/polaris-go/pkg/config" -) - -func main() { - conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) - provider, err := api.NewProviderAPIByConfig(conf) - if err != nil { - panic(err) - } - consumer, err := api.NewConsumerAPIByConfig(conf) - if err != nil { - panic(err) - } - - if err != nil { - panic(err) - } - - defer consumer.Destroy() - defer provider.Destroy() - - r := polaris.NewRegistry( - provider, - consumer, - polaris.WithTimeout(10000), - polaris.WithRetryCount(3), - ) - callHTTP(r) - callGRPC(r) -} - -func callGRPC(r registry.Discovery) { - conn, err := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("discovery:///helloworldgrpc"), - grpc.WithDiscovery(r), - grpc.WithTimeout(100*time.Second), - ) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - client := helloworld.NewGreeterClient(conn) - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[grpc] SayHello %+v\n", reply) -} - -func callHTTP(r registry.Discovery) { - conn, err := http.NewClient( - context.Background(), - http.WithEndpoint("discovery:///helloworldhttp"), - http.WithDiscovery(r), - http.WithBlock(), - ) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - client := helloworld.NewGreeterHTTPClient(conn) - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[http] SayHello %+v\n", reply) -} diff --git a/examples/registry/polaris/server/main.go b/examples/registry/polaris/server/main.go deleted file mode 100644 index 118c8cf5d..000000000 --- a/examples/registry/polaris/server/main.go +++ /dev/null @@ -1,78 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - - "github.com/go-kratos/kratos/contrib/registry/polaris/v2" - "github.com/polarismesh/polaris-go/api" - "github.com/polarismesh/polaris-go/pkg/config" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - return &helloworld.HelloReply{Message: fmt.Sprintf("Welcome %+v!", in.Name)}, nil -} - -func main() { - conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"}) - provider, err := api.NewProviderAPIByConfig(conf) - if err != nil { - panic(err) - } - - consumer, err := api.NewConsumerAPIByConfig(conf) - if err != nil { - panic(err) - } - defer consumer.Destroy() - defer provider.Destroy() - - registry := polaris.NewRegistry( - provider, - consumer, - polaris.WithTTL(5), - ) - - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - recovery.Recovery(), - ), - ) - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - recovery.Recovery(), - ), - ) - - s := &server{} - - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - app := kratos.New( - kratos.Name("helloworld"), - kratos.Server( - grpcSrv, - httpSrv, - ), - kratos.Registrar(registry), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/registry/registry_test.go b/examples/registry/registry_test.go deleted file mode 100644 index e83fb537e..000000000 --- a/examples/registry/registry_test.go +++ /dev/null @@ -1,129 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - "testing" - "time" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" - - consulregistry "github.com/go-kratos/kratos/contrib/registry/consul/v2" - etcdregistry "github.com/go-kratos/kratos/contrib/registry/etcd/v2" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/registry" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - consul "github.com/hashicorp/consul/api" - etcd "go.etcd.io/etcd/client/v3" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - pb.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { - return &pb.HelloReply{Message: fmt.Sprintf("Welcome %+v!", in.Name)}, nil -} - -func startServer(r registry.Registrar) (app *kratos.App, err error) { - httpSrv := http.NewServer() - grpcSrv := grpc.NewServer() - - s := &server{} - pb.RegisterGreeterServer(grpcSrv, s) - pb.RegisterGreeterHTTPServer(httpSrv, s) - - app = kratos.New( - kratos.Name("helloworld"), - kratos.Server( - httpSrv, - grpcSrv, - ), - kratos.Registrar(r), - kratos.RegistrarTimeout(5*time.Second), - ) - go func() { - err = app.Run() - }() - time.Sleep(time.Second) - return -} - -func callGRPC(t *testing.T, r registry.Discovery) { - conn, err := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("discovery:///helloworld"), - grpc.WithDiscovery(r), - ) - if err != nil { - t.Fatal(err) - } - defer conn.Close() - client := helloworld.NewGreeterClient(conn) - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - t.Fatal(err) - } - t.Logf("[grpc] SayHello %+v\n", reply) -} - -func callHTTP(t *testing.T, r registry.Discovery) { - conn, err := http.NewClient( - context.Background(), - http.WithEndpoint("discovery:///helloworld"), - http.WithDiscovery(r), - http.WithBlock(), - ) - if err != nil { - t.Fatal(err) - } - defer conn.Close() - client := helloworld.NewGreeterHTTPClient(conn) - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - t.Fatal(err) - } - t.Logf("[http] SayHello %+v\n", reply) -} - -func TestETCD(t *testing.T) { - client, err := etcd.New(etcd.Config{ - Endpoints: []string{"127.0.0.1:2379"}, - }) - if err != nil { - t.Fatal(err) - } - r := etcdregistry.New(client) - srv, err := startServer(r) - if err != nil { - t.Fatal(err) - } - callHTTP(t, r) - callGRPC(t, r) - if srv.Stop() != nil { - t.Errorf("srv.Stop() got error: %v", err) - } -} - -func TestConsul(t *testing.T) { - client, err := consul.NewClient(consul.DefaultConfig()) - if err != nil { - log.Fatal(err) - } - r := consulregistry.New(client) - srv, err := startServer(r) - if err != nil { - t.Fatal(err) - } - callHTTP(t, r) - callGRPC(t, r) - - if srv.Stop() != nil { - t.Errorf("srv.Stop() got error: %v", err) - } -} diff --git a/examples/registry/zookeeper/client/main.go b/examples/registry/zookeeper/client/main.go deleted file mode 100644 index 9e8ce7cd0..000000000 --- a/examples/registry/zookeeper/client/main.go +++ /dev/null @@ -1,61 +0,0 @@ -package main - -import ( - "context" - "log" - "time" - - "github.com/go-kratos/kratos/contrib/registry/zookeeper/v2" - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -func main() { - r, err := zookeeper.New([]string{"127.0.0.1:2181"}) - if err != nil { - panic(err) - } - for { - callHTTP(r) - callGRPC(r) - time.Sleep(time.Second) - } -} - -func callGRPC(r *zookeeper.Registry) { - conn, err := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("discovery:///helloworld"), - grpc.WithDiscovery(r), - ) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - client := helloworld.NewGreeterClient(conn) - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[grpc] SayHello %+v\n", reply) -} - -func callHTTP(r *zookeeper.Registry) { - conn, err := http.NewClient( - context.Background(), - http.WithEndpoint("discovery:///helloworld"), - http.WithDiscovery(r), - http.WithBlock(), - ) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - client := helloworld.NewGreeterHTTPClient(conn) - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[http] SayHello %s\n", reply) -} diff --git a/examples/registry/zookeeper/server/main.go b/examples/registry/zookeeper/server/main.go deleted file mode 100644 index ef9947d55..000000000 --- a/examples/registry/zookeeper/server/main.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - - "github.com/go-kratos/kratos/contrib/registry/zookeeper/v2" - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - return &helloworld.HelloReply{Message: fmt.Sprintf("Welcome %+v!", in.Name)}, nil -} - -func main() { - r, err := zookeeper.New([]string{"127.0.0.1:2181"}) - if err != nil { - log.Fatal(err) - } - - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - recovery.Recovery(), - ), - ) - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - recovery.Recovery(), - ), - ) - - s := &server{} - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - app := kratos.New( - kratos.Name("helloworld"), - kratos.Server( - grpcSrv, - httpSrv, - ), - kratos.Registrar(r), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/selector/client/main.go b/examples/selector/client/main.go deleted file mode 100644 index f490646a7..000000000 --- a/examples/selector/client/main.go +++ /dev/null @@ -1,84 +0,0 @@ -package main - -import ( - "context" - "log" - "time" - - "github.com/go-kratos/kratos/contrib/registry/consul/v2" - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/selector/filter" - "github.com/go-kratos/kratos/v2/selector/p2c" - "github.com/go-kratos/kratos/v2/selector/wrr" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/hashicorp/consul/api" -) - -func main() { - consulCli, err := api.NewClient(api.DefaultConfig()) - if err != nil { - panic(err) - } - r := consul.New(consulCli) - - // new grpc client - conn, err := grpc.DialInsecure( - context.Background(), - grpc.WithEndpoint("discovery:///helloworld"), - grpc.WithDiscovery(r), - // 由于gRPC框架的限制只能使用全局balancer+filter的方式来实现selector - // 这里使用weighted round robin算法的balancer+静态version=1.0.0的Filter - grpc.WithBalancerName(wrr.Name), - grpc.WithFilter( - filter.Version("1.0.0"), - ), - ) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - gClient := helloworld.NewGreeterClient(conn) - - // new http client - hConn, err := http.NewClient( - context.Background(), - http.WithMiddleware( - recovery.Recovery(), - ), - http.WithEndpoint("discovery:///helloworld"), - http.WithDiscovery(r), - // 这里使用p2c算法的balancer+静态version=2.0.0的Filter组成一个selector - http.WithSelector( - p2c.New(p2c.WithFilter(filter.Version("2.0.0"))), - ), - ) - if err != nil { - log.Fatal(err) - } - defer hConn.Close() - hClient := helloworld.NewGreeterHTTPClient(hConn) - - for { - time.Sleep(time.Second) - callGRPC(gClient) - callHTTP(hClient) - } -} - -func callGRPC(client helloworld.GreeterClient) { - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[grpc] SayHello %+v\n", reply) -} - -func callHTTP(client helloworld.GreeterHTTPClient) { - reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[http] SayHello %s\n", reply.Message) -} diff --git a/examples/selector/server/main.go b/examples/selector/server/main.go deleted file mode 100644 index 247bdc4ca..000000000 --- a/examples/selector/server/main.go +++ /dev/null @@ -1,79 +0,0 @@ -package main - -import ( - "context" - "fmt" - "os" - - "github.com/go-kratos/kratos/contrib/registry/consul/v2" - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/hashicorp/consul/api" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - return &helloworld.HelloReply{Message: fmt.Sprintf("Welcome %+v!", in.Name)}, nil -} - -func main() { - logger := log.NewStdLogger(os.Stdout) - - consulClient, err := api.NewClient(api.DefaultConfig()) - if err != nil { - log.NewHelper(logger).Fatal(err) - } - go runServer("1.0.0", logger, consulClient, 8000) - go runServer("1.0.0", logger, consulClient, 8010) - - runServer("2.0.0", logger, consulClient, 8020) -} - -func runServer(version string, logger log.Logger, client *api.Client, port int) { - logger = log.With(logger, "version", version, "port:", port) - log := log.NewHelper(logger) - - httpSrv := http.NewServer( - http.Address(fmt.Sprintf(":%d", port)), - http.Middleware( - recovery.Recovery(), - logging.Server(logger), - ), - ) - grpcSrv := grpc.NewServer( - grpc.Address(fmt.Sprintf(":%d", port+1000)), - grpc.Middleware( - recovery.Recovery(), - logging.Server(logger), - ), - ) - - s := &server{} - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - r := consul.New(client) - app := kratos.New( - kratos.Name("helloworld"), - kratos.Server( - grpcSrv, - httpSrv, - ), - kratos.Version(version), - kratos.Registrar(r), - ) - - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/stream/client/main.go b/examples/stream/client/main.go deleted file mode 100644 index 20a78c9c3..000000000 --- a/examples/stream/client/main.go +++ /dev/null @@ -1,102 +0,0 @@ -package main - -import ( - "context" - "fmt" - "io" - "log" - "strconv" - "sync" - "time" - - "github.com/go-kratos/kratos/examples/stream/hello" - "github.com/go-kratos/kratos/v2/middleware/recovery" - transgrpc "github.com/go-kratos/kratos/v2/transport/grpc" -) - -var wg = sync.WaitGroup{} - -func main() { - conn, err := transgrpc.DialInsecure( - context.Background(), - transgrpc.WithEndpoint("127.0.0.1:9001"), - transgrpc.WithMiddleware( - recovery.Recovery(), - ), - ) - if err != nil { - panic(err) - } - defer conn.Close() - - client := hello.NewHelloClient(conn) - - wg.Add(3) - - go getNumber(client) - go uploadLog(client) - go chat(client) - - wg.Wait() -} - -func getNumber(client hello.HelloClient) { - defer wg.Done() - stream, err := client.GetNumber(context.Background(), &hello.GetNumberRequest{Data: "2021/08/01"}) - if err != nil { - log.Fatal(err) - } - for { - res, err := stream.Recv() - if err == io.EOF { - break - } - if err != nil { - log.Fatalf("ListStr get stream err: %v", err) - } - // 打印返回值 - log.Println(res.Number) - } -} - -func uploadLog(client hello.HelloClient) { - defer wg.Done() - stream, err := client.UploadLog(context.Background()) - if err != nil { - log.Fatal(err) - } - var number int - for { - err := stream.Send(&hello.UploadLogRequest{Log: "log:" + strconv.Itoa(number)}) - if err != nil { - log.Fatalf("ListStr get stream err: %v", err) - } - time.Sleep(time.Millisecond * 50) - number++ - } -} - -func chat(client hello.HelloClient) { - defer wg.Done() - stream, err := client.Chat(context.Background()) - if err != nil { - log.Fatal(err) - } - var number int - for { - err = stream.Send(&hello.ChatRequest{UpMsg: "kratos:" + strconv.Itoa(number)}) - if err != nil { - log.Fatalf("ListStr get stream err: %v", err) - } - res, err := stream.Recv() - if err == io.EOF { - break - } - if err != nil { - log.Fatalf("ListStr get stream err: %v", err) - } - fmt.Println(res.DownMsg) - time.Sleep(time.Millisecond * 50) - number++ - } -} diff --git a/examples/stream/hello/hello.pb.go b/examples/stream/hello/hello.pb.go deleted file mode 100644 index b1b001228..000000000 --- a/examples/stream/hello/hello.pb.go +++ /dev/null @@ -1,479 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.1 -// protoc v3.17.3 -// source: stream/hello/hello.proto - -package hello - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type GetNumberRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` -} - -func (x *GetNumberRequest) Reset() { - *x = GetNumberRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_stream_hello_hello_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetNumberRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetNumberRequest) ProtoMessage() {} - -func (x *GetNumberRequest) ProtoReflect() protoreflect.Message { - mi := &file_stream_hello_hello_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetNumberRequest.ProtoReflect.Descriptor instead. -func (*GetNumberRequest) Descriptor() ([]byte, []int) { - return file_stream_hello_hello_proto_rawDescGZIP(), []int{0} -} - -func (x *GetNumberRequest) GetData() string { - if x != nil { - return x.Data - } - return "" -} - -type GetNumberReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Number int64 `protobuf:"varint,1,opt,name=number,proto3" json:"number,omitempty"` -} - -func (x *GetNumberReply) Reset() { - *x = GetNumberReply{} - if protoimpl.UnsafeEnabled { - mi := &file_stream_hello_hello_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetNumberReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetNumberReply) ProtoMessage() {} - -func (x *GetNumberReply) ProtoReflect() protoreflect.Message { - mi := &file_stream_hello_hello_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetNumberReply.ProtoReflect.Descriptor instead. -func (*GetNumberReply) Descriptor() ([]byte, []int) { - return file_stream_hello_hello_proto_rawDescGZIP(), []int{1} -} - -func (x *GetNumberReply) GetNumber() int64 { - if x != nil { - return x.Number - } - return 0 -} - -type UploadLogRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Log string `protobuf:"bytes,1,opt,name=log,proto3" json:"log,omitempty"` -} - -func (x *UploadLogRequest) Reset() { - *x = UploadLogRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_stream_hello_hello_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *UploadLogRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*UploadLogRequest) ProtoMessage() {} - -func (x *UploadLogRequest) ProtoReflect() protoreflect.Message { - mi := &file_stream_hello_hello_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use UploadLogRequest.ProtoReflect.Descriptor instead. -func (*UploadLogRequest) Descriptor() ([]byte, []int) { - return file_stream_hello_hello_proto_rawDescGZIP(), []int{2} -} - -func (x *UploadLogRequest) GetLog() string { - if x != nil { - return x.Log - } - return "" -} - -type UploadLogReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Res string `protobuf:"bytes,1,opt,name=res,proto3" json:"res,omitempty"` -} - -func (x *UploadLogReply) Reset() { - *x = UploadLogReply{} - if protoimpl.UnsafeEnabled { - mi := &file_stream_hello_hello_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *UploadLogReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*UploadLogReply) ProtoMessage() {} - -func (x *UploadLogReply) ProtoReflect() protoreflect.Message { - mi := &file_stream_hello_hello_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use UploadLogReply.ProtoReflect.Descriptor instead. -func (*UploadLogReply) Descriptor() ([]byte, []int) { - return file_stream_hello_hello_proto_rawDescGZIP(), []int{3} -} - -func (x *UploadLogReply) GetRes() string { - if x != nil { - return x.Res - } - return "" -} - -type ChatRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - UpMsg string `protobuf:"bytes,1,opt,name=up_msg,json=upMsg,proto3" json:"up_msg,omitempty"` -} - -func (x *ChatRequest) Reset() { - *x = ChatRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_stream_hello_hello_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ChatRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ChatRequest) ProtoMessage() {} - -func (x *ChatRequest) ProtoReflect() protoreflect.Message { - mi := &file_stream_hello_hello_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ChatRequest.ProtoReflect.Descriptor instead. -func (*ChatRequest) Descriptor() ([]byte, []int) { - return file_stream_hello_hello_proto_rawDescGZIP(), []int{4} -} - -func (x *ChatRequest) GetUpMsg() string { - if x != nil { - return x.UpMsg - } - return "" -} - -type ChatReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - DownMsg string `protobuf:"bytes,1,opt,name=down_msg,json=downMsg,proto3" json:"down_msg,omitempty"` -} - -func (x *ChatReply) Reset() { - *x = ChatReply{} - if protoimpl.UnsafeEnabled { - mi := &file_stream_hello_hello_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ChatReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ChatReply) ProtoMessage() {} - -func (x *ChatReply) ProtoReflect() protoreflect.Message { - mi := &file_stream_hello_hello_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ChatReply.ProtoReflect.Descriptor instead. -func (*ChatReply) Descriptor() ([]byte, []int) { - return file_stream_hello_hello_proto_rawDescGZIP(), []int{5} -} - -func (x *ChatReply) GetDownMsg() string { - if x != nil { - return x.DownMsg - } - return "" -} - -var File_stream_hello_hello_proto protoreflect.FileDescriptor - -var file_stream_hello_hello_proto_rawDesc = []byte{ - 0x0a, 0x18, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2f, 0x68, - 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x73, 0x74, 0x72, 0x65, - 0x61, 0x6d, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x26, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x4e, - 0x75, 0x6d, 0x62, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, - 0x22, 0x28, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x52, 0x65, 0x70, - 0x6c, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x24, 0x0a, 0x10, 0x55, 0x70, - 0x6c, 0x6f, 0x61, 0x64, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, - 0x0a, 0x03, 0x6c, 0x6f, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6c, 0x6f, 0x67, - 0x22, 0x22, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x70, - 0x6c, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x03, 0x72, 0x65, 0x73, 0x22, 0x24, 0x0a, 0x0b, 0x43, 0x68, 0x61, 0x74, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x15, 0x0a, 0x06, 0x75, 0x70, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x05, 0x75, 0x70, 0x4d, 0x73, 0x67, 0x22, 0x26, 0x0a, 0x09, 0x43, 0x68, - 0x61, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x64, 0x6f, 0x77, 0x6e, 0x5f, - 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x64, 0x6f, 0x77, 0x6e, 0x4d, - 0x73, 0x67, 0x32, 0xe1, 0x01, 0x0a, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x4b, 0x0a, 0x09, - 0x47, 0x65, 0x74, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1e, 0x2e, 0x73, 0x74, 0x72, 0x65, - 0x61, 0x6d, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x4e, 0x75, 0x6d, 0x62, - 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x73, 0x74, 0x72, 0x65, - 0x61, 0x6d, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x4e, 0x75, 0x6d, 0x62, - 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x30, 0x01, 0x12, 0x4b, 0x0a, 0x09, 0x55, 0x70, 0x6c, - 0x6f, 0x61, 0x64, 0x4c, 0x6f, 0x67, 0x12, 0x1e, 0x2e, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, - 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x4c, 0x6f, 0x67, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, - 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x4c, 0x6f, 0x67, 0x52, - 0x65, 0x70, 0x6c, 0x79, 0x28, 0x01, 0x12, 0x3e, 0x0a, 0x04, 0x43, 0x68, 0x61, 0x74, 0x12, 0x19, - 0x2e, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x43, 0x68, - 0x61, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x73, 0x74, 0x72, 0x65, - 0x61, 0x6d, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x52, 0x65, 0x70, - 0x6c, 0x79, 0x28, 0x01, 0x30, 0x01, 0x42, 0x49, 0x0a, 0x0c, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, - 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x50, 0x01, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x6b, - 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x73, - 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x3b, 0x68, 0x65, 0x6c, 0x6c, - 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_stream_hello_hello_proto_rawDescOnce sync.Once - file_stream_hello_hello_proto_rawDescData = file_stream_hello_hello_proto_rawDesc -) - -func file_stream_hello_hello_proto_rawDescGZIP() []byte { - file_stream_hello_hello_proto_rawDescOnce.Do(func() { - file_stream_hello_hello_proto_rawDescData = protoimpl.X.CompressGZIP(file_stream_hello_hello_proto_rawDescData) - }) - return file_stream_hello_hello_proto_rawDescData -} - -var file_stream_hello_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 6) -var file_stream_hello_hello_proto_goTypes = []interface{}{ - (*GetNumberRequest)(nil), // 0: stream.hello.GetNumberRequest - (*GetNumberReply)(nil), // 1: stream.hello.GetNumberReply - (*UploadLogRequest)(nil), // 2: stream.hello.UploadLogRequest - (*UploadLogReply)(nil), // 3: stream.hello.UploadLogReply - (*ChatRequest)(nil), // 4: stream.hello.ChatRequest - (*ChatReply)(nil), // 5: stream.hello.ChatReply -} -var file_stream_hello_hello_proto_depIdxs = []int32{ - 0, // 0: stream.hello.Hello.GetNumber:input_type -> stream.hello.GetNumberRequest - 2, // 1: stream.hello.Hello.UploadLog:input_type -> stream.hello.UploadLogRequest - 4, // 2: stream.hello.Hello.Chat:input_type -> stream.hello.ChatRequest - 1, // 3: stream.hello.Hello.GetNumber:output_type -> stream.hello.GetNumberReply - 3, // 4: stream.hello.Hello.UploadLog:output_type -> stream.hello.UploadLogReply - 5, // 5: stream.hello.Hello.Chat:output_type -> stream.hello.ChatReply - 3, // [3:6] is the sub-list for method output_type - 0, // [0:3] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_stream_hello_hello_proto_init() } -func file_stream_hello_hello_proto_init() { - if File_stream_hello_hello_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_stream_hello_hello_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetNumberRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_stream_hello_hello_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetNumberReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_stream_hello_hello_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*UploadLogRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_stream_hello_hello_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*UploadLogReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_stream_hello_hello_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ChatRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_stream_hello_hello_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ChatReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_stream_hello_hello_proto_rawDesc, - NumEnums: 0, - NumMessages: 6, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_stream_hello_hello_proto_goTypes, - DependencyIndexes: file_stream_hello_hello_proto_depIdxs, - MessageInfos: file_stream_hello_hello_proto_msgTypes, - }.Build() - File_stream_hello_hello_proto = out.File - file_stream_hello_hello_proto_rawDesc = nil - file_stream_hello_hello_proto_goTypes = nil - file_stream_hello_hello_proto_depIdxs = nil -} diff --git a/examples/stream/hello/hello_grpc.pb.go b/examples/stream/hello/hello_grpc.pb.go deleted file mode 100644 index 11590f889..000000000 --- a/examples/stream/hello/hello_grpc.pb.go +++ /dev/null @@ -1,266 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package hello - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// HelloClient is the client API for Hello service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type HelloClient interface { - GetNumber(ctx context.Context, in *GetNumberRequest, opts ...grpc.CallOption) (Hello_GetNumberClient, error) - UploadLog(ctx context.Context, opts ...grpc.CallOption) (Hello_UploadLogClient, error) - Chat(ctx context.Context, opts ...grpc.CallOption) (Hello_ChatClient, error) -} - -type helloClient struct { - cc grpc.ClientConnInterface -} - -func NewHelloClient(cc grpc.ClientConnInterface) HelloClient { - return &helloClient{cc} -} - -func (c *helloClient) GetNumber(ctx context.Context, in *GetNumberRequest, opts ...grpc.CallOption) (Hello_GetNumberClient, error) { - stream, err := c.cc.NewStream(ctx, &Hello_ServiceDesc.Streams[0], "/stream.hello.Hello/GetNumber", opts...) - if err != nil { - return nil, err - } - x := &helloGetNumberClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type Hello_GetNumberClient interface { - Recv() (*GetNumberReply, error) - grpc.ClientStream -} - -type helloGetNumberClient struct { - grpc.ClientStream -} - -func (x *helloGetNumberClient) Recv() (*GetNumberReply, error) { - m := new(GetNumberReply) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *helloClient) UploadLog(ctx context.Context, opts ...grpc.CallOption) (Hello_UploadLogClient, error) { - stream, err := c.cc.NewStream(ctx, &Hello_ServiceDesc.Streams[1], "/stream.hello.Hello/UploadLog", opts...) - if err != nil { - return nil, err - } - x := &helloUploadLogClient{stream} - return x, nil -} - -type Hello_UploadLogClient interface { - Send(*UploadLogRequest) error - CloseAndRecv() (*UploadLogReply, error) - grpc.ClientStream -} - -type helloUploadLogClient struct { - grpc.ClientStream -} - -func (x *helloUploadLogClient) Send(m *UploadLogRequest) error { - return x.ClientStream.SendMsg(m) -} - -func (x *helloUploadLogClient) CloseAndRecv() (*UploadLogReply, error) { - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - m := new(UploadLogReply) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *helloClient) Chat(ctx context.Context, opts ...grpc.CallOption) (Hello_ChatClient, error) { - stream, err := c.cc.NewStream(ctx, &Hello_ServiceDesc.Streams[2], "/stream.hello.Hello/Chat", opts...) - if err != nil { - return nil, err - } - x := &helloChatClient{stream} - return x, nil -} - -type Hello_ChatClient interface { - Send(*ChatRequest) error - Recv() (*ChatReply, error) - grpc.ClientStream -} - -type helloChatClient struct { - grpc.ClientStream -} - -func (x *helloChatClient) Send(m *ChatRequest) error { - return x.ClientStream.SendMsg(m) -} - -func (x *helloChatClient) Recv() (*ChatReply, error) { - m := new(ChatReply) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// HelloServer is the service API for Hello service. -// All implementations must embed UnimplementedHelloServer -// for forward compatibility -type HelloServer interface { - GetNumber(*GetNumberRequest, Hello_GetNumberServer) error - UploadLog(Hello_UploadLogServer) error - Chat(Hello_ChatServer) error - mustEmbedUnimplementedHelloServer() -} - -// UnimplementedHelloServer must be embedded to have forward compatible implementations. -type UnimplementedHelloServer struct { -} - -func (UnimplementedHelloServer) GetNumber(*GetNumberRequest, Hello_GetNumberServer) error { - return status.Errorf(codes.Unimplemented, "method GetNumber not implemented") -} -func (UnimplementedHelloServer) UploadLog(Hello_UploadLogServer) error { - return status.Errorf(codes.Unimplemented, "method UploadLog not implemented") -} -func (UnimplementedHelloServer) Chat(Hello_ChatServer) error { - return status.Errorf(codes.Unimplemented, "method Chat not implemented") -} -func (UnimplementedHelloServer) mustEmbedUnimplementedHelloServer() {} - -// UnsafeHelloServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to HelloServer will -// result in compilation errors. -type UnsafeHelloServer interface { - mustEmbedUnimplementedHelloServer() -} - -func RegisterHelloServer(s grpc.ServiceRegistrar, srv HelloServer) { - s.RegisterService(&Hello_ServiceDesc, srv) -} - -func _Hello_GetNumber_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(GetNumberRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(HelloServer).GetNumber(m, &helloGetNumberServer{stream}) -} - -type Hello_GetNumberServer interface { - Send(*GetNumberReply) error - grpc.ServerStream -} - -type helloGetNumberServer struct { - grpc.ServerStream -} - -func (x *helloGetNumberServer) Send(m *GetNumberReply) error { - return x.ServerStream.SendMsg(m) -} - -func _Hello_UploadLog_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(HelloServer).UploadLog(&helloUploadLogServer{stream}) -} - -type Hello_UploadLogServer interface { - SendAndClose(*UploadLogReply) error - Recv() (*UploadLogRequest, error) - grpc.ServerStream -} - -type helloUploadLogServer struct { - grpc.ServerStream -} - -func (x *helloUploadLogServer) SendAndClose(m *UploadLogReply) error { - return x.ServerStream.SendMsg(m) -} - -func (x *helloUploadLogServer) Recv() (*UploadLogRequest, error) { - m := new(UploadLogRequest) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func _Hello_Chat_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(HelloServer).Chat(&helloChatServer{stream}) -} - -type Hello_ChatServer interface { - Send(*ChatReply) error - Recv() (*ChatRequest, error) - grpc.ServerStream -} - -type helloChatServer struct { - grpc.ServerStream -} - -func (x *helloChatServer) Send(m *ChatReply) error { - return x.ServerStream.SendMsg(m) -} - -func (x *helloChatServer) Recv() (*ChatRequest, error) { - m := new(ChatRequest) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// Hello_ServiceDesc is the grpc.ServiceDesc for Hello service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Hello_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "stream.hello.Hello", - HandlerType: (*HelloServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{ - { - StreamName: "GetNumber", - Handler: _Hello_GetNumber_Handler, - ServerStreams: true, - }, - { - StreamName: "UploadLog", - Handler: _Hello_UploadLog_Handler, - ClientStreams: true, - }, - { - StreamName: "Chat", - Handler: _Hello_Chat_Handler, - ServerStreams: true, - ClientStreams: true, - }, - }, - Metadata: "stream/hello/hello.proto", -} diff --git a/examples/stream/server/main.go b/examples/stream/server/main.go deleted file mode 100644 index b25612175..000000000 --- a/examples/stream/server/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "log" - - "github.com/go-kratos/kratos/examples/stream/hello" - "github.com/go-kratos/kratos/examples/stream/service" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/transport/grpc" -) - -func main() { - grpcSrv := grpc.NewServer( - grpc.Address(":9001"), - grpc.Middleware( - recovery.Recovery(), - ), - ) - hello.RegisterHelloServer(grpcSrv, service.NewHelloService()) - - app := kratos.New( - kratos.Name("hello"), - kratos.Server( - grpcSrv, - ), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/stream/service/hello.go b/examples/stream/service/hello.go deleted file mode 100644 index cf95a2699..000000000 --- a/examples/stream/service/hello.go +++ /dev/null @@ -1,60 +0,0 @@ -package service - -import ( - "fmt" - "io" - "time" - - pb "github.com/go-kratos/kratos/examples/stream/hello" -) - -type HelloService struct { - pb.UnimplementedHelloServer -} - -func NewHelloService() *HelloService { - return &HelloService{} -} - -func (s *HelloService) GetNumber(req *pb.GetNumberRequest, conn pb.Hello_GetNumberServer) error { - var number int64 - for { - fmt.Println(req.Data) - err := conn.Send(&pb.GetNumberReply{Number: number}) - if err != nil { - return err - } - number++ - time.Sleep(time.Second) - } -} - -func (s *HelloService) UploadLog(conn pb.Hello_UploadLogServer) error { - for { - req, err := conn.Recv() - if err == io.EOF { - return conn.SendAndClose(&pb.UploadLogReply{Res: "ok"}) - } - if err != nil { - return err - } - fmt.Println(req.Log) - } -} - -func (s *HelloService) Chat(conn pb.Hello_ChatServer) error { - for { - req, err := conn.Recv() - if err == io.EOF { - return nil - } - if err != nil { - return err - } - - err = conn.Send(&pb.ChatReply{DownMsg: "hello " + req.UpMsg}) - if err != nil { - return err - } - } -} diff --git a/examples/swagger/helloworld/helloworld.pb.go b/examples/swagger/helloworld/helloworld.pb.go deleted file mode 100644 index 4091f8b33..000000000 --- a/examples/swagger/helloworld/helloworld.pb.go +++ /dev/null @@ -1,251 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.1-devel -// protoc v3.17.3 -// source: helloworld/helloworld.proto - -package helloworld - -import ( - reply "github.com/go-kratos/kratos/examples/swagger/reply" - _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options" - _ "google.golang.org/genproto/googleapis/api/annotations" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// The request message containing the user's name. -type HelloRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (x *HelloRequest) Reset() { - *x = HelloRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_helloworld_helloworld_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *HelloRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*HelloRequest) ProtoMessage() {} - -func (x *HelloRequest) ProtoReflect() protoreflect.Message { - mi := &file_helloworld_helloworld_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead. -func (*HelloRequest) Descriptor() ([]byte, []int) { - return file_helloworld_helloworld_proto_rawDescGZIP(), []int{0} -} - -func (x *HelloRequest) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -// The response message containing the greetings -type HelloReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Reply *reply.Reply `protobuf:"bytes,1,opt,name=reply,proto3" json:"reply,omitempty"` -} - -func (x *HelloReply) Reset() { - *x = HelloReply{} - if protoimpl.UnsafeEnabled { - mi := &file_helloworld_helloworld_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *HelloReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*HelloReply) ProtoMessage() {} - -func (x *HelloReply) ProtoReflect() protoreflect.Message { - mi := &file_helloworld_helloworld_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use HelloReply.ProtoReflect.Descriptor instead. -func (*HelloReply) Descriptor() ([]byte, []int) { - return file_helloworld_helloworld_proto_rawDescGZIP(), []int{1} -} - -func (x *HelloReply) GetReply() *reply.Reply { - if x != nil { - return x.Reply - } - return nil -} - -var File_helloworld_helloworld_proto protoreflect.FileDescriptor - -var file_helloworld_helloworld_proto_rawDesc = []byte{ - 0x0a, 0x1b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x68, 0x65, 0x6c, - 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x68, - 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x11, 0x72, 0x65, 0x70, 0x6c, 0x79, 0x2f, 0x72, - 0x65, 0x70, 0x6c, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x6f, 0x70, 0x65, 0x6e, 0x61, 0x70, 0x69, 0x76, 0x32, - 0x2f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x22, 0x0a, 0x0c, 0x48, 0x65, - 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x30, - 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x22, 0x0a, 0x05, - 0x72, 0x65, 0x70, 0x6c, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x72, 0x65, - 0x70, 0x6c, 0x79, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x05, 0x72, 0x65, 0x70, 0x6c, 0x79, - 0x32, 0xa9, 0x01, 0x0a, 0x07, 0x47, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x12, 0x9d, 0x01, 0x0a, - 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x18, 0x2e, 0x68, 0x65, 0x6c, 0x6c, - 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, - 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x5f, 0x82, 0xd3, 0xe4, - 0x93, 0x02, 0x14, 0x12, 0x12, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, - 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x92, 0x41, 0x42, 0x22, 0x40, 0x0a, 0x0e, 0x53, 0x61, - 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x2e, 0x68, 0x74, - 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, 0x65, 0x63, 0x6f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, - 0x67, 0x72, 0x70, 0x63, 0x2d, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x42, 0xc1, 0x02, 0x5a, - 0x42, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, - 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x73, 0x77, 0x61, 0x67, 0x67, 0x65, 0x72, 0x2f, 0x68, 0x65, - 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x3b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, - 0x72, 0x6c, 0x64, 0x92, 0x41, 0xf9, 0x01, 0x12, 0xf6, 0x01, 0x0a, 0x13, 0x48, 0x65, 0x6c, 0x6c, - 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x20, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x22, - 0x58, 0x0a, 0x14, 0x67, 0x52, 0x50, 0x43, 0x2d, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x20, - 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, - 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x70, 0x63, - 0x2d, 0x65, 0x63, 0x6f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, - 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x1a, 0x10, 0x6e, 0x6f, 0x6e, 0x65, 0x40, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2a, 0x5e, 0x0a, 0x14, 0x42, 0x53, 0x44, - 0x20, 0x33, 0x2d, 0x43, 0x6c, 0x61, 0x75, 0x73, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, - 0x65, 0x12, 0x46, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, 0x65, 0x63, 0x6f, 0x73, 0x79, - 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, - 0x79, 0x2f, 0x62, 0x6c, 0x6f, 0x62, 0x2f, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x2f, 0x4c, 0x49, - 0x43, 0x45, 0x4e, 0x53, 0x45, 0x2e, 0x74, 0x78, 0x74, 0x32, 0x03, 0x31, 0x2e, 0x30, 0x3a, 0x20, - 0x0a, 0x15, 0x78, 0x2d, 0x73, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x6f, - 0x6d, 0x65, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x12, 0x07, 0x1a, 0x05, 0x79, 0x61, 0x64, 0x64, 0x61, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_helloworld_helloworld_proto_rawDescOnce sync.Once - file_helloworld_helloworld_proto_rawDescData = file_helloworld_helloworld_proto_rawDesc -) - -func file_helloworld_helloworld_proto_rawDescGZIP() []byte { - file_helloworld_helloworld_proto_rawDescOnce.Do(func() { - file_helloworld_helloworld_proto_rawDescData = protoimpl.X.CompressGZIP(file_helloworld_helloworld_proto_rawDescData) - }) - return file_helloworld_helloworld_proto_rawDescData -} - -var file_helloworld_helloworld_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_helloworld_helloworld_proto_goTypes = []interface{}{ - (*HelloRequest)(nil), // 0: helloworld.HelloRequest - (*HelloReply)(nil), // 1: helloworld.HelloReply - (*reply.Reply)(nil), // 2: reply.Reply -} -var file_helloworld_helloworld_proto_depIdxs = []int32{ - 2, // 0: helloworld.HelloReply.reply:type_name -> reply.Reply - 0, // 1: helloworld.Greeter.SayHello:input_type -> helloworld.HelloRequest - 1, // 2: helloworld.Greeter.SayHello:output_type -> helloworld.HelloReply - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_helloworld_helloworld_proto_init() } -func file_helloworld_helloworld_proto_init() { - if File_helloworld_helloworld_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_helloworld_helloworld_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*HelloRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_helloworld_helloworld_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*HelloReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_helloworld_helloworld_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_helloworld_helloworld_proto_goTypes, - DependencyIndexes: file_helloworld_helloworld_proto_depIdxs, - MessageInfos: file_helloworld_helloworld_proto_msgTypes, - }.Build() - File_helloworld_helloworld_proto = out.File - file_helloworld_helloworld_proto_rawDesc = nil - file_helloworld_helloworld_proto_goTypes = nil - file_helloworld_helloworld_proto_depIdxs = nil -} diff --git a/examples/swagger/helloworld/helloworld.proto b/examples/swagger/helloworld/helloworld.proto deleted file mode 100644 index 77f482ff7..000000000 --- a/examples/swagger/helloworld/helloworld.proto +++ /dev/null @@ -1,57 +0,0 @@ -syntax = "proto3"; - -package helloworld; - -import "google/api/annotations.proto"; -import "reply/reply.proto"; -import "protoc-gen-openapiv2/options/annotations.proto"; - -option go_package = "github.com/go-kratos/kratos/examples/swagger/helloworld;helloworld"; - -option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { - info: { - title: "Helloworld examples"; - version: "1.0"; - contact: { - name: "gRPC-Gateway project"; - url: "https://github.com/grpc-ecosystem/grpc-gateway"; - email: "none@example.com"; - }; - license: { - name: "BSD 3-Clause License"; - url: "https://github.com/grpc-ecosystem/grpc-gateway/blob/master/LICENSE.txt"; - }; - extensions: { - key: "x-something-something"; - value { - string_value: "yadda"; - } - } - }; -}; - -// The greeting service definition. -service Greeter { - // Sends a greeting - rpc SayHello (HelloRequest) returns (HelloReply) { - option (google.api.http) = { - get: "/helloworld/{name}", - }; - option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = { - external_docs: { - url: "https://github.com/grpc-ecosystem/grpc-gateway"; - description: "SayHello Query"; - } - }; - } -} - -// The request message containing the user's name. -message HelloRequest { - string name = 1; -} - -// The response message containing the greetings -message HelloReply { - reply.Reply reply = 1; -} diff --git a/examples/swagger/helloworld/helloworld_grpc.pb.go b/examples/swagger/helloworld/helloworld_grpc.pb.go deleted file mode 100644 index 4e1c32b3d..000000000 --- a/examples/swagger/helloworld/helloworld_grpc.pb.go +++ /dev/null @@ -1,103 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package helloworld - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// GreeterClient is the client API for Greeter service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type GreeterClient interface { - // Sends a greeting - SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) -} - -type greeterClient struct { - cc grpc.ClientConnInterface -} - -func NewGreeterClient(cc grpc.ClientConnInterface) GreeterClient { - return &greeterClient{cc} -} - -func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) { - out := new(HelloReply) - err := c.cc.Invoke(ctx, "/helloworld.Greeter/SayHello", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// GreeterServer is the server API for Greeter service. -// All implementations must embed UnimplementedGreeterServer -// for forward compatibility -type GreeterServer interface { - // Sends a greeting - SayHello(context.Context, *HelloRequest) (*HelloReply, error) - mustEmbedUnimplementedGreeterServer() -} - -// UnimplementedGreeterServer must be embedded to have forward compatible implementations. -type UnimplementedGreeterServer struct { -} - -func (UnimplementedGreeterServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") -} -func (UnimplementedGreeterServer) mustEmbedUnimplementedGreeterServer() {} - -// UnsafeGreeterServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to GreeterServer will -// result in compilation errors. -type UnsafeGreeterServer interface { - mustEmbedUnimplementedGreeterServer() -} - -func RegisterGreeterServer(s grpc.ServiceRegistrar, srv GreeterServer) { - s.RegisterService(&Greeter_ServiceDesc, srv) -} - -func _Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(HelloRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(GreeterServer).SayHello(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/helloworld.Greeter/SayHello", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GreeterServer).SayHello(ctx, req.(*HelloRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// Greeter_ServiceDesc is the grpc.ServiceDesc for Greeter service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Greeter_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "helloworld.Greeter", - HandlerType: (*GreeterServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "SayHello", - Handler: _Greeter_SayHello_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "helloworld/helloworld.proto", -} diff --git a/examples/swagger/helloworld/helloworld_http.pb.go b/examples/swagger/helloworld/helloworld_http.pb.go deleted file mode 100644 index d5c73d03c..000000000 --- a/examples/swagger/helloworld/helloworld_http.pb.go +++ /dev/null @@ -1,74 +0,0 @@ -// Code generated by protoc-gen-go-http. DO NOT EDIT. -// versions: -// protoc-gen-go-http v2.0.3 - -package helloworld - -import ( - context "context" - http "github.com/go-kratos/kratos/v2/transport/http" - binding "github.com/go-kratos/kratos/v2/transport/http/binding" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the kratos package it is being compiled against. -var _ = new(context.Context) -var _ = binding.EncodeURL - -const _ = http.SupportPackageIsVersion1 - -type GreeterHTTPServer interface { - SayHello(context.Context, *HelloRequest) (*HelloReply, error) -} - -func RegisterGreeterHTTPServer(s *http.Server, srv GreeterHTTPServer) { - r := s.Route("/") - r.GET("/helloworld/{name}", _Greeter_SayHello0_HTTP_Handler(srv)) -} - -func _Greeter_SayHello0_HTTP_Handler(srv GreeterHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in HelloRequest - if err := ctx.BindQuery(&in); err != nil { - return err - } - if err := ctx.BindVars(&in); err != nil { - return err - } - http.SetOperation(ctx, "/helloworld.Greeter/SayHello") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.SayHello(ctx, req.(*HelloRequest)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*HelloReply) - return ctx.Result(200, reply) - } -} - -type GreeterHTTPClient interface { - SayHello(ctx context.Context, req *HelloRequest, opts ...http.CallOption) (rsp *HelloReply, err error) -} - -type GreeterHTTPClientImpl struct { - cc *http.Client -} - -func NewGreeterHTTPClient(client *http.Client) GreeterHTTPClient { - return &GreeterHTTPClientImpl{client} -} - -func (c *GreeterHTTPClientImpl) SayHello(ctx context.Context, in *HelloRequest, opts ...http.CallOption) (*HelloReply, error) { - var out HelloReply - pattern := "/helloworld/{name}" - path := binding.EncodeURL(pattern, in, true) - opts = append(opts, http.Operation("/helloworld.Greeter/SayHello")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} diff --git a/examples/swagger/reply/reply.pb.go b/examples/swagger/reply/reply.pb.go deleted file mode 100644 index 8a7bfd06e..000000000 --- a/examples/swagger/reply/reply.pb.go +++ /dev/null @@ -1,145 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.15.8 -// source: reply/reply.proto - -package reply - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Reply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` -} - -func (x *Reply) Reset() { - *x = Reply{} - if protoimpl.UnsafeEnabled { - mi := &file_reply_reply_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Reply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Reply) ProtoMessage() {} - -func (x *Reply) ProtoReflect() protoreflect.Message { - mi := &file_reply_reply_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Reply.ProtoReflect.Descriptor instead. -func (*Reply) Descriptor() ([]byte, []int) { - return file_reply_reply_proto_rawDescGZIP(), []int{0} -} - -func (x *Reply) GetValue() string { - if x != nil { - return x.Value - } - return "" -} - -var File_reply_reply_proto protoreflect.FileDescriptor - -var file_reply_reply_proto_rawDesc = []byte{ - 0x0a, 0x11, 0x72, 0x65, 0x70, 0x6c, 0x79, 0x2f, 0x72, 0x65, 0x70, 0x6c, 0x79, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x72, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x1d, 0x0a, 0x05, 0x52, 0x65, - 0x70, 0x6c, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x42, 0x5a, 0x40, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, - 0x73, 0x2f, 0x73, 0x77, 0x61, 0x67, 0x67, 0x65, 0x72, 0x2d, 0x61, 0x70, 0x69, 0x2f, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, - 0x64, 0x2f, 0x72, 0x65, 0x70, 0x6c, 0x79, 0x3b, 0x72, 0x65, 0x70, 0x6c, 0x79, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_reply_reply_proto_rawDescOnce sync.Once - file_reply_reply_proto_rawDescData = file_reply_reply_proto_rawDesc -) - -func file_reply_reply_proto_rawDescGZIP() []byte { - file_reply_reply_proto_rawDescOnce.Do(func() { - file_reply_reply_proto_rawDescData = protoimpl.X.CompressGZIP(file_reply_reply_proto_rawDescData) - }) - return file_reply_reply_proto_rawDescData -} - -var file_reply_reply_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_reply_reply_proto_goTypes = []interface{}{ - (*Reply)(nil), // 0: reply.Reply -} -var file_reply_reply_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_reply_reply_proto_init() } -func file_reply_reply_proto_init() { - if File_reply_reply_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_reply_reply_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Reply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_reply_reply_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_reply_reply_proto_goTypes, - DependencyIndexes: file_reply_reply_proto_depIdxs, - MessageInfos: file_reply_reply_proto_msgTypes, - }.Build() - File_reply_reply_proto = out.File - file_reply_reply_proto_rawDesc = nil - file_reply_reply_proto_goTypes = nil - file_reply_reply_proto_depIdxs = nil -} diff --git a/examples/swagger/reply/reply.proto b/examples/swagger/reply/reply.proto deleted file mode 100644 index cb51450bc..000000000 --- a/examples/swagger/reply/reply.proto +++ /dev/null @@ -1,9 +0,0 @@ -syntax = "proto3"; - -package reply; - -option go_package = "github.com/go-kratos/kratos/examples/swagger/reply;reply"; - -message Reply { - string value = 1; -} \ No newline at end of file diff --git a/examples/swagger/server/main.go b/examples/swagger/server/main.go deleted file mode 100644 index 26787b875..000000000 --- a/examples/swagger/server/main.go +++ /dev/null @@ -1,67 +0,0 @@ -package main - -import ( - "context" - "fmt" - "os" - - pb "github.com/go-kratos/kratos/examples/swagger/helloworld" - "github.com/go-kratos/kratos/examples/swagger/reply" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/errors" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/go-kratos/swagger-api/openapiv2" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name = "helloworld" - // Version is the version of the compiled software. - // Version = "v1.0.0" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - pb.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(_ context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { - if in.Name == "error" { - return nil, errors.BadRequest("custom_error", fmt.Sprintf("invalid argument %s", in.Name)) - } - if in.Name == "panic" { - panic("grpc panic") - } - - return &pb.HelloReply{Reply: &reply.Reply{Value: fmt.Sprintf("Hello %+v", in.Name)}}, nil -} - -func main() { - stdLogger := log.NewStdLogger(os.Stdout) - - logger := log.NewHelper(stdLogger) - s := &server{} - - httpSrv := http.NewServer(http.Address(":8000")) - pb.RegisterGreeterHTTPServer(httpSrv, s) - - h := openapiv2.NewHandler() - httpSrv.HandlePrefix("/q/", h) - - /* fs := httpx.FileServer(httpx.Dir("./dist")) - httpSrv.HandlePrefix("/swaggerui/", httpx.StripPrefix("/swaggerui/", fs))*/ - - app := kratos.New( - kratos.Name(Name), - kratos.Server( - httpSrv, - ), - ) - - if err := app.Run(); err != nil { - logger.Error(err) - } -} diff --git a/examples/tls/README.md b/examples/tls/README.md deleted file mode 100644 index be39d4fee..000000000 --- a/examples/tls/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Run the example - -1、Compile and execute the server code: -```shell -$ go run server/main.go -``` -2、From a different terminal, compile and execute the client code: -```shell -$ go run client/main.go -``` \ No newline at end of file diff --git a/examples/tls/cert/ca.crt b/examples/tls/cert/ca.crt deleted file mode 100644 index 55cdea0cb..000000000 --- a/examples/tls/cert/ca.crt +++ /dev/null @@ -1,32 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIFdDCCA1wCCQDHq+cGa349DzANBgkqhkiG9w0BAQsFADB8MQswCQYDVQQGEwJD -TjELMAkGA1UECAwCU0gxCzAJBgNVBAcMAlNIMQ8wDQYDVQQKDAZrcmF0b3MxCzAJ -BgNVBAsMAklUMRMwEQYDVQQDDAprcmF0b3MuY29tMSAwHgYJKoZIhvcNAQkBFhFr -cmF0b3NAa3JhdG9zLmNvbTAeFw0yMTA3MjcxNTMwMzlaFw0zMTA3MjUxNTMwMzla -MHwxCzAJBgNVBAYTAkNOMQswCQYDVQQIDAJTSDELMAkGA1UEBwwCU0gxDzANBgNV -BAoMBmtyYXRvczELMAkGA1UECwwCSVQxEzARBgNVBAMMCmtyYXRvcy5jb20xIDAe -BgkqhkiG9w0BCQEWEWtyYXRvc0BrcmF0b3MuY29tMIICIjANBgkqhkiG9w0BAQEF -AAOCAg8AMIICCgKCAgEApy2GV9MiECuelNk3fz1Qwh6+wj8Ip11NG+LxEGK4/MLD -JRJtbgAg/7s3vzrm4WDKATDO27W6wewNFOvEnGWyh9wyjAtSgnAcJreq7F2DMbpO -+E2guIQHSCCzfa10s4BgwXKdBRPPvwTADIHXPtlbq4BItJqzt/AhLQbdDAp93mHX -NCzFdlIr4wflT2OW7EO24K2LgMZLWCzaESei9fL6AYm7jEvfaFYZksI3rjJNAj1q -wccMu1o6TvdWRA5fvBi6h15Z0ekR8C2LbM1A54zziZwd+YjcwdQHJJgWJFH7yNSt -Oe/AJZzP1nRk/5H0EvxBnF7du6vfeSjZJytp8cXMlbYg4NGGkSy782tBaUaDIb43 -iLqSjfHVZDLzbDGNy/u/mzfo4xS8lxZ92zE7z21d0WyUAJ75Z72v4kaNTr2tnMuE -NTTG1787e3NB0CaV6gjeP8XbMV8gwNTrJmTW3dS+DT6sKtTIISOvsUCZ6h5qFvKU -RWqJ7MiaSxg31DPg51caYDjiVLkkES8GRpPM/Njsg9WpFTQeqcecKbbOdw0ihvoV -fq0FgHpp+jbjm0KkmcNdSX7Ld5XeHp2rBPkA283IdXIAvjjthlyWJTmSP6kDDdEI -km4Did1Bg0wcXNnFlbHHavCfeRTQbVoIYVkWH7I323Vp8itvKobz1GirSOK0Hr0C -AwEAATANBgkqhkiG9w0BAQsFAAOCAgEAFBYIOOyABIbUUOjjjvx2FSDRBNLpee5O -45KmznuCGerhR7ad3rUNhaakA9HJzmLMUXtmyzy6+ej0HzdqZE7RRzdDVftBGaOf -thwEzUAiHfqeX0o039sTQvJSqUY2sBko+tyDRmeNtmd3TPE5VZZSWG+TUtrOofr7 -K28UquMthJrmtSC8IJQOvA78Nc/FCPNaGZrcS8ZvrgbrkCLPN4dIJvY9I38xaWQ+ -G0gNQazxPzdp89/UMzkczyJAKjYj4JyLCbrjzTZXjtu+rYJezxyS+3QSf0F0xVBr -/8HCeXX6xG16WZY54Z6AijqI3sjiRBSQ25rLJJ00sWa9k1oH0Poyiv4pQG3RHgIs -jJEQh7RQE5zAsBx2NHZ8FcsUGX2oOjSS+vtX//Bg37kN7oYx5HEtK9c+a0wWUxo8 -8cqIzqrQSWOd1CipxbE5CUUNKdGQzNCLTfLO68KitLdaSOCGoU/PaoAncbr6EjdB -kzqJcHooqq8asl6fu1DVnYqCpEEp30ldU3p4MdclcMV0XZUq6bXFq1ylmfZXfC0t -zSGnBUjxB5lohn5fs1S/DxyoUR8LbIFVWCljEf4jJtMRnCQV3bR3xeVTbGh3ti81 -21uhQKjIP/X2BRNAvRo1qUbrzEeHAJG3EbIG78rRFvSz6MkWVTZzeH1SgCr9Onw7 -djovWE7E6ic= ------END CERTIFICATE----- diff --git a/examples/tls/cert/server.crt b/examples/tls/cert/server.crt deleted file mode 100644 index d4b1047d5..000000000 --- a/examples/tls/cert/server.crt +++ /dev/null @@ -1,64 +0,0 @@ - ------BEGIN CERTIFICATE----- -MIIFZTCCA02gAwIBAgIBATANBgkqhkiG9w0BAQUFADB8MQswCQYDVQQGEwJDTjEL -MAkGA1UECAwCU0gxCzAJBgNVBAcMAlNIMQ8wDQYDVQQKDAZrcmF0b3MxCzAJBgNV -BAsMAklUMRMwEQYDVQQDDAprcmF0b3MuY29tMSAwHgYJKoZIhvcNAQkBFhFrcmF0 -b3NAa3JhdG9zLmNvbTAeFw0yMTA3MjcxNTM1MjJaFw0yMjA3MjcxNTM1MjJaME0x -CzAJBgNVBAYTAkNOMQswCQYDVQQIDAJTSDELMAkGA1UEBwwCU0gxDzANBgNVBAoM -BmtyYXRvczETMBEGA1UEAwwKa3JhdG9zLmNvbTCCAiIwDQYJKoZIhvcNAQEBBQAD -ggIPADCCAgoCggIBALfEWAuPqUHTwTiOT8dtiCM3aEm1D7I6K/PY2mSDMMOI4f5z -TYi7LsKLLItMQR44cEDein/kl0U0QNYJRHqVCr/3IXA4ds0maiq+npY/S2KABDiI -Z38TZ1PZ2bcD3Jb0o1gw0GcSokOGzVtuNKSiASc3D711AepGerChD5UrbixrZdg2 -wAeWZj39Tl93+zCcldVrCHMSM7LmDluHJ5KZ8T6auuK6ypQPVhqLz8VseHhB/IRw -s9/o9OlJ3kv4wB/CWlFIvU6ZGVnshZAGOk3Brq25kw600RRDr2MpxNhFY1Xvrt7D -tAJ7fK3/3VaV+I2C4OzzmztK7T1WlL8XqZj6I3t1ZCZryMvDIUPzC4mgiRqEJiF7 -VzuVm1sjyTKkD4oX6ZjJYXJ/6pbvd8+AexuwVAsQJKqaF1iQC9jThg55RUTkGo8F -DFErW7XHKHe8vKXuRLG5k3xZBiHK7gsVyHzx0ouuSuZMFHg7L9ACeeqtqxqKNd+0 -fIo4N0vNb3GEj+YaTLoadhDSBEsynyQNTfrDf+oFRmQUg3q0W4VJHJFhkmTHRRcq -Qj6xEAJDHC1xr8yr3jif9BKWG2+zEbvpiTcRXKhycv2OUI11dK72aMnOycusJjRe -8pOqcYhSVQZnz31WWlkmX9TRiQtEeUUkFCYAnIArSKm5rNwOddLCzC8Z4js1AgMB -AAGjITAfMB0GA1UdEQQWMBSCDCoua3JhdG9zLmNvbYcEfwAAATANBgkqhkiG9w0B -AQUFAAOCAgEAjr3SXzNOcN8+JQuroS6hKHadrcp6djepd3r5YKSEjKBNxVAU0gj6 -QGl0zjSqhxSFwN4wCqXU/4JJVOyAJCV+t992j5wNdaGI+Tcu4whK2LtPi0O68ttq -Nn5H/8bmotW0IZ/YDcq1V8EVWiTZPECk4QLx26S2sjG4HOKNUAs8o+PoUmQE5bKJ -XBFWmjsOfPnI0WBGnuCvGUw5wP1ipLiuK+OhoTNKA6SXPopm5KMDv7gjYPlcmPyI -sJcpve75m9EXQxrDvJtvws8MIZnkWvWi7bW6uQ7274S7YjMZL09/sQTolQOtwl59 -pvEbkQNPzgdvQYAfrlJjSBtbq3OtHF+j+p2K+7R0TY2F1OW3LeV8vkcq7IOt38Er -FK5feNEL3t9GlrF8ASmJp/JvhWQiJo5tZJxWZ68CjKfLmVd406ehsK5XNlHJemnl -hNpuAegeV6WDglvMNavvQCJfK5mKokn73HujtQveZ8vwPKV4f6Wg3sHJ2yyP7ou2 -2UZ10Qbp6UvFYfYuMvLuq8kznapWqQ0dIJzPDs+CzVtjk1eINUF9UjsSvqX4oCvy -+ZvaM9k4kU/fJMRkLstc/Dx2G13T/moI/l5sw0qFtck12zs/SQ7xgcW3b0ruGX9S -11opfl5R86GpXXbz+vNL9fWP+8cIvoGZK8RAC872bcMPEoJPjPIwAbI= ------END CERTIFICATE----- ------BEGIN CERTIFICATE----- -MIIFdDCCA1wCCQDHq+cGa349DzANBgkqhkiG9w0BAQsFADB8MQswCQYDVQQGEwJD -TjELMAkGA1UECAwCU0gxCzAJBgNVBAcMAlNIMQ8wDQYDVQQKDAZrcmF0b3MxCzAJ -BgNVBAsMAklUMRMwEQYDVQQDDAprcmF0b3MuY29tMSAwHgYJKoZIhvcNAQkBFhFr -cmF0b3NAa3JhdG9zLmNvbTAeFw0yMTA3MjcxNTMwMzlaFw0zMTA3MjUxNTMwMzla -MHwxCzAJBgNVBAYTAkNOMQswCQYDVQQIDAJTSDELMAkGA1UEBwwCU0gxDzANBgNV -BAoMBmtyYXRvczELMAkGA1UECwwCSVQxEzARBgNVBAMMCmtyYXRvcy5jb20xIDAe -BgkqhkiG9w0BCQEWEWtyYXRvc0BrcmF0b3MuY29tMIICIjANBgkqhkiG9w0BAQEF -AAOCAg8AMIICCgKCAgEApy2GV9MiECuelNk3fz1Qwh6+wj8Ip11NG+LxEGK4/MLD -JRJtbgAg/7s3vzrm4WDKATDO27W6wewNFOvEnGWyh9wyjAtSgnAcJreq7F2DMbpO -+E2guIQHSCCzfa10s4BgwXKdBRPPvwTADIHXPtlbq4BItJqzt/AhLQbdDAp93mHX -NCzFdlIr4wflT2OW7EO24K2LgMZLWCzaESei9fL6AYm7jEvfaFYZksI3rjJNAj1q -wccMu1o6TvdWRA5fvBi6h15Z0ekR8C2LbM1A54zziZwd+YjcwdQHJJgWJFH7yNSt -Oe/AJZzP1nRk/5H0EvxBnF7du6vfeSjZJytp8cXMlbYg4NGGkSy782tBaUaDIb43 -iLqSjfHVZDLzbDGNy/u/mzfo4xS8lxZ92zE7z21d0WyUAJ75Z72v4kaNTr2tnMuE -NTTG1787e3NB0CaV6gjeP8XbMV8gwNTrJmTW3dS+DT6sKtTIISOvsUCZ6h5qFvKU -RWqJ7MiaSxg31DPg51caYDjiVLkkES8GRpPM/Njsg9WpFTQeqcecKbbOdw0ihvoV -fq0FgHpp+jbjm0KkmcNdSX7Ld5XeHp2rBPkA283IdXIAvjjthlyWJTmSP6kDDdEI -km4Did1Bg0wcXNnFlbHHavCfeRTQbVoIYVkWH7I323Vp8itvKobz1GirSOK0Hr0C -AwEAATANBgkqhkiG9w0BAQsFAAOCAgEAFBYIOOyABIbUUOjjjvx2FSDRBNLpee5O -45KmznuCGerhR7ad3rUNhaakA9HJzmLMUXtmyzy6+ej0HzdqZE7RRzdDVftBGaOf -thwEzUAiHfqeX0o039sTQvJSqUY2sBko+tyDRmeNtmd3TPE5VZZSWG+TUtrOofr7 -K28UquMthJrmtSC8IJQOvA78Nc/FCPNaGZrcS8ZvrgbrkCLPN4dIJvY9I38xaWQ+ -G0gNQazxPzdp89/UMzkczyJAKjYj4JyLCbrjzTZXjtu+rYJezxyS+3QSf0F0xVBr -/8HCeXX6xG16WZY54Z6AijqI3sjiRBSQ25rLJJ00sWa9k1oH0Poyiv4pQG3RHgIs -jJEQh7RQE5zAsBx2NHZ8FcsUGX2oOjSS+vtX//Bg37kN7oYx5HEtK9c+a0wWUxo8 -8cqIzqrQSWOd1CipxbE5CUUNKdGQzNCLTfLO68KitLdaSOCGoU/PaoAncbr6EjdB -kzqJcHooqq8asl6fu1DVnYqCpEEp30ldU3p4MdclcMV0XZUq6bXFq1ylmfZXfC0t -zSGnBUjxB5lohn5fs1S/DxyoUR8LbIFVWCljEf4jJtMRnCQV3bR3xeVTbGh3ti81 -21uhQKjIP/X2BRNAvRo1qUbrzEeHAJG3EbIG78rRFvSz6MkWVTZzeH1SgCr9Onw7 -djovWE7E6ic= ------END CERTIFICATE----- diff --git a/examples/tls/cert/server.key b/examples/tls/cert/server.key deleted file mode 100644 index cd1259397..000000000 --- a/examples/tls/cert/server.key +++ /dev/null @@ -1,51 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIJKwIBAAKCAgEAt8RYC4+pQdPBOI5Px22IIzdoSbUPsjor89jaZIMww4jh/nNN -iLsuwossi0xBHjhwQN6Kf+SXRTRA1glEepUKv/chcDh2zSZqKr6elj9LYoAEOIhn -fxNnU9nZtwPclvSjWDDQZxKiQ4bNW240pKIBJzcPvXUB6kZ6sKEPlStuLGtl2DbA -B5ZmPf1OX3f7MJyV1WsIcxIzsuYOW4cnkpnxPpq64rrKlA9WGovPxWx4eEH8hHCz -3+j06UneS/jAH8JaUUi9TpkZWeyFkAY6TcGurbmTDrTRFEOvYynE2EVjVe+u3sO0 -Ant8rf/dVpX4jYLg7PObO0rtPVaUvxepmPoje3VkJmvIy8MhQ/MLiaCJGoQmIXtX -O5WbWyPJMqQPihfpmMlhcn/qlu93z4B7G7BUCxAkqpoXWJAL2NOGDnlFROQajwUM -UStbtccod7y8pe5EsbmTfFkGIcruCxXIfPHSi65K5kwUeDsv0AJ56q2rGoo137R8 -ijg3S81vcYSP5hpMuhp2ENIESzKfJA1N+sN/6gVGZBSDerRbhUkckWGSZMdFFypC -PrEQAkMcLXGvzKveOJ/0EpYbb7MRu+mJNxFcqHJy/Y5QjXV0rvZoyc7Jy6wmNF7y -k6pxiFJVBmfPfVZaWSZf1NGJC0R5RSQUJgCcgCtIqbms3A510sLMLxniOzUCAwEA -AQKCAgEAhJuO3WjhvrrLp8AqGcMUhjUpcGbT2MzZgrFthzKUMcXJLxCNVqmcaI59 -qldwdhpMBsOQNhIChtHaJ5mwbLS4eSYgXxafxBKAci/zyIAMKhwu74yfArhBy+Rc -kxCaUeRfKviuqnJr3UadUekI2/R72IyHMzQIGcKaLnNLB127txoY+BkqIU+KoBj2 -QTYXcVDNXqBKDJ+J5wLUQYAaMlQcHg0R5yLbpFQc0jMpz1Ei7cTQL9IUOvOkJ+RC -IZhzK3fYLOfMk7cu8BEZoICd+hZVss9DK02XwoPFQE2X2mjX8d9v1RhsAY6Svgzw -79Zw8c0L+nEgB31eDPE5jVvJ6rY2e1riojtnwoU6d7mjjpznRxN83kRo1HP5ZeU8 -GB+HMaXzS2iRyNF01kqBgbFnlT5eJHU6XvxqXxuCtauf1xVMZ56TBvyEw1CaQ6aM -oYJl3bBxy2vdeH1+ah4wti8XkGCBJPVPehFrZ1Ohi1YFNXAcl0xAv9KbNtD+HCJB -CJITsXdEfqJT9ToPLDWJiGcb8c0AyVcrQGHdzGXJ/ySsRyPa0MNAKgD2ZIUtlE2+ -RqHK9vCCw3mr8KwBmPI4JCgCujse2aK44dxXEWouKCzF+cyDjTKR1Vf/sgrfKOPv -TCG6VmCW4m4X5RqRBvM1NzCCnS2YH0NR7n1aQBzm4kI0Hxt6qAECggEBAOczyO7J -ZCm2fI+N/PUGuY+RwJ5qcjRTR2jPd87AbsxiCKqh2xLAhO+i8xPr8H8ec50tDnzY -fBjBGuCo1fGIZVpn0fIXwCuO7GaAgrTI/nfn+T7gtDyIuVH8JgpIs6pKyUfWMI5l -+LASymApoa5I47lTnLK8pgobDbBoG50GNEkUYVhni+2rdHiKeUPe9HoheIipHVat -GnRCVTcLyRJjfSvvRYGhGtbF/sHpd2Nz3FSjd7KXalvpgWc+5t2ZDggKqxqvr8HY -2YHVjsnxcB5UeKFzaSobuN3XnD8+Xb7QIL5LIQgzAuzTs/euBAEZh8SRlQe5bpy+ -WQOOTQpP0HR7cbUCggEBAMt6G7fLsAWybCpJsJxoOO0cFotBfMSzZkGZ7k3ESOOz -HvEvRMg6B5wOkH5v/wKYKT19yl750DNK6KgndAwgDy3rcEY69dQYonwhwNpw767r -/1Fm3YgLeUABLfNeW3pn7AZsfDn7XH4uloPCOYI93MeHlGytBix7OhsNS+JRcX4g -xzyNwLqp1ExFOUIaNLn+CGJ/fBDtv6eKxdl9euZwP88JcW2PB8V9u+cgBdhwrk2F -FmNZyUqS6H6HQFtNJYTHNpsRSzclPWr+y9eY/BfBjedub8dbiAzhs8LBhR9cCOPy -A9fKiucJCsy3n8Vzfv0RzKen/eeY2Ig2zCap4Gm3k4ECggEBAIFXGAZ1xcIMI7zP -av7MZ0yo9j/pPsCFAkLhJZ4VSyathTmn2H2yE+xXlXLEoEMNDxKT3TH8jdfvV5Dt -AtrfOgwMXof3v3retuNU60ol0y3TKT2CyXG/7yStUb6ZE2Gl+tpkOb+/zhL6QBrx -z1BH2JWZ7+SR4rVukwboBuKeUOu9KgQh0UcBjuPMW7CbbttQFDUnnpEZv93gKfnk -bvUJkUHd1l2BehlCpJVofXC2pUD4PgM777VBeTIAH3lCoXXgOf5w4HsqS+v1Q683 -kUh2axGvFdsHrTD16KP8yMbxeg/aybzjhLRmbpyVzgmrdaeC5gNvOjEXz4ZMuk6V -fgFb+a0CggEBAK9vS6CvPMfcqwfW2zAvaA1/byyHvQR3TQ34ow9n0hSIZoA6agpc -hh0WLZzmAS+Cc+QxpZ83sjvXNTtuMM8XgR7tZLMYuMUyrD1seLOeNflSPqM3ln9q -rRLzMWQokaS7HzP2qzDuuTOOBXX6qszRe56JFf6RO8Z0RIf4cdnisIC30DA0Y9xM -+t77vD9zCszl6uLJ2fValyjkLGu1lZZDZ7ChCqwUavXqz2yaHpAbrxzlR4VHb5cd -jNky0dkmbdfKTxlp0rjsIcUzhBsSKyBsYGYOwM9Y6rd4jh237og4OO4Xxxpx5ksG -b8pL87QxPWcCxroyzGa3UNI4tNING5Dql4ECggEBAOFV45WtMi8LC66suRUnVWaG -CqO6x5kFYsQgK/bSrCRgRJUPBlVEMUJim5Ql8haVkoYU6n5j6FXSMKJkRVctDhXk -Cj/6GH2zEZ1xgZr6GxRPU4YbU6iRWHdZfGzWB6fqpfTsRFUHsJVCzB3aXffCmX0L -+yqEMoX3B+R+EdTv3SF79K5a3bAA6VQtpnwHQ83PTK7MTTDepSdM+ft+6D++iGYS -GU5+HGahjSg+iZti9feaOUIT5OfcXjoYUT3B6+rhgTQO2OMpq3QtSJhK7ZnP6HnZ -URRaawDhyJSqOO8Z5Z/bdaMSJHWcR1huaHF7yGoPHR06xBzaX82tsHiZbZx5pg8= ------END RSA PRIVATE KEY----- diff --git a/examples/tls/client/main.go b/examples/tls/client/main.go deleted file mode 100644 index 54331af15..000000000 --- a/examples/tls/client/main.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - "context" - "crypto/tls" - "crypto/x509" - "log" - "os" - - pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -func main() { - // Load CA certificate pem file. - b, err := os.ReadFile("../cert/ca.crt") - if err != nil { - panic(err) - } - cp := x509.NewCertPool() - if !cp.AppendCertsFromPEM(b) { - panic(err) - } - tlsConf := &tls.Config{ServerName: "www.kratos.com", RootCAs: cp} - callHTTP(tlsConf) - callGRPC(tlsConf) -} - -func callHTTP(tlsConf *tls.Config) { - conn, err := http.NewClient( - context.Background(), - http.WithEndpoint("https://127.0.0.1:8000"), - http.WithTLSConfig(tlsConf), - ) - if err != nil { - panic(err) - } - defer conn.Close() - client := pb.NewGreeterHTTPClient(conn) - reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[http] SayHello %s\n", reply.Message) -} - -func callGRPC(tlsConf *tls.Config) { - conn, err := grpc.Dial( - context.Background(), - grpc.WithEndpoint("127.0.0.1:9000"), - grpc.WithTLSConfig(tlsConf), - ) - if err != nil { - panic(err) - } - defer conn.Close() - client := pb.NewGreeterClient(conn) - reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "kratos"}) - if err != nil { - log.Fatal(err) - } - log.Printf("[grpc] SayHello %+v\n", reply) -} diff --git a/examples/tls/server/main.go b/examples/tls/server/main.go deleted file mode 100644 index b6e9cba53..000000000 --- a/examples/tls/server/main.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import ( - "context" - "crypto/tls" - "fmt" - "log" - - "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name = "helloworld" - // Version is the version of the compiled software. - // Version = "v1.0.0" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - helloworld.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { - return &helloworld.HelloReply{Message: fmt.Sprintf("Hello %+v", in.Name)}, nil -} - -func main() { - cert, err := tls.LoadX509KeyPair("../cert/server.crt", "../cert/server.key") - if err != nil { - panic(err) - } - tlsConf := &tls.Config{Certificates: []tls.Certificate{cert}} - - s := &server{} - httpSrv := http.NewServer( - http.Address(":8000"), - http.TLSConfig(tlsConf), - ) - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.TLSConfig(tlsConf), - ) - helloworld.RegisterGreeterServer(grpcSrv, s) - helloworld.RegisterGreeterHTTPServer(httpSrv, s) - - app := kratos.New( - kratos.Name(Name), - kratos.Server( - httpSrv, - grpcSrv, - ), - ) - - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/tls/tls_test.go b/examples/tls/tls_test.go deleted file mode 100644 index e7df3f45f..000000000 --- a/examples/tls/tls_test.go +++ /dev/null @@ -1,135 +0,0 @@ -package main - -import ( - "context" - "crypto/tls" - "crypto/x509" - "fmt" - "os" - "testing" - "time" - - etcdregistry "github.com/go-kratos/kratos/contrib/registry/etcd/v2" - pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/registry" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - etcd "go.etcd.io/etcd/client/v3" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - pb.UnimplementedGreeterServer -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { - return &pb.HelloReply{Message: fmt.Sprintf("Welcome %+v!", in.Name)}, nil -} - -func startServer(r registry.Registrar, c *tls.Config) (app *kratos.App, err error) { - httpSrv := http.NewServer(http.TLSConfig(c)) - grpcSrv := grpc.NewServer(grpc.TLSConfig(c)) - - s := &server{} - pb.RegisterGreeterServer(grpcSrv, s) - pb.RegisterGreeterHTTPServer(httpSrv, s) - - app = kratos.New( - kratos.Name("helloworld"), - kratos.Server( - httpSrv, - grpcSrv, - ), - kratos.Registrar(r), - kratos.RegistrarTimeout(5*time.Second), - ) - go func() { - err = app.Run() - }() - time.Sleep(time.Second) - return -} - -func callGRPC(t *testing.T, r registry.Discovery, c *tls.Config) { - conn, err := grpc.Dial( - context.Background(), - grpc.WithEndpoint("discovery:///helloworld"), - grpc.WithTLSConfig(c), - grpc.WithDiscovery(r), - ) - if err != nil { - t.Fatal(err) - } - defer conn.Close() - client := pb.NewGreeterClient(conn) - reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "kratos"}) - if err != nil { - t.Fatal(err) - } - t.Logf("[grpc] SayHello %+v\n", reply) -} - -func callHTTP(t *testing.T, r registry.Discovery, c *tls.Config) { - conn, err := http.NewClient( - context.Background(), - http.WithEndpoint("discovery:///helloworld"), - http.WithTLSConfig(c), - http.WithDiscovery(r), - http.WithBlock(), - ) - if err != nil { - t.Fatal(err) - } - defer conn.Close() - client := pb.NewGreeterHTTPClient(conn) - reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "kratos"}) - if err != nil { - t.Fatal(err) - } - t.Logf("[http] SayHello %+v\n", reply) -} - -func TestETCD(t *testing.T) { - client, err := etcd.New(etcd.Config{ - Endpoints: []string{"127.0.0.1:2379"}, - }) - if err != nil { - t.Fatal(err) - } - b, err := os.ReadFile("./cert/server.crt") - if err != nil { - t.Fatal(err) - } - cp := x509.NewCertPool() - if !cp.AppendCertsFromPEM(b) { - t.Fatal(err) - } - cert, err := tls.LoadX509KeyPair("./cert/server.crt", "./cert/server.key") - if err != nil { - t.Fatal(err) - } - tlsConf := &tls.Config{ - ServerName: "www.kratos.com", - RootCAs: cp, - Certificates: []tls.Certificate{cert}, - } - r := etcdregistry.New(client) - srv, err := startServer(r, nil) - if err != nil { - t.Fatal(err) - } - srvTLS, err := startServer(r, tlsConf) - if err != nil { - t.Fatal(err) - } - callHTTP(t, r, tlsConf) - callGRPC(t, r, tlsConf) - if srv.Stop() != nil { - t.Errorf("srv.Stop() got error: %v", err) - } - if srvTLS.Stop() != nil { - t.Errorf("srv.Stop() got error: %v", err) - } -} diff --git a/examples/traces/Dockerfile b/examples/traces/Dockerfile deleted file mode 100644 index f55c3a7b0..000000000 --- a/examples/traces/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM debian:stable-slim - -RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates \ - netbase \ - && rm -rf /var/lib/apt/lists/ \ - && apt-get autoremove -y && apt-get autoclean -y - -COPY ./app/message/bin /app -COPY ./app/user/bin /app -COPY ./service.sh /app - -EXPOSE 8000 -EXPOSE 9000 - -ENTRYPOINT ["sh","/app/service.sh"] \ No newline at end of file diff --git a/examples/traces/README.md b/examples/traces/README.md deleted file mode 100644 index 990accb13..000000000 --- a/examples/traces/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# traces example - -- There are two services in the example - -- After receiving the HTTP request, the user service calls the grpc server provided by the message service through the grpc client - -- The example shows how to use tracing middleware - -- You can experience the effect by following the command - -### run example -```shell -# Windows start-windows.bat -# mac/linux -sh start.sh -curl http://localhost:8000/v1/user/get/message/10 -# Open with browser http://localhost:16686 -# You can see the effect -``` - - diff --git a/examples/traces/api/message/message.pb.go b/examples/traces/api/message/message.pb.go deleted file mode 100644 index 6a053d0d2..000000000 --- a/examples/traces/api/message/message.pb.go +++ /dev/null @@ -1,300 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.15.7 -// source: traces/api/message/message.proto - -package v1 - -import ( - _ "google.golang.org/genproto/googleapis/api/annotations" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type GetUserMessageRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - Count int64 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"` -} - -func (x *GetUserMessageRequest) Reset() { - *x = GetUserMessageRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_traces_api_message_message_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetUserMessageRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetUserMessageRequest) ProtoMessage() {} - -func (x *GetUserMessageRequest) ProtoReflect() protoreflect.Message { - mi := &file_traces_api_message_message_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetUserMessageRequest.ProtoReflect.Descriptor instead. -func (*GetUserMessageRequest) Descriptor() ([]byte, []int) { - return file_traces_api_message_message_proto_rawDescGZIP(), []int{0} -} - -func (x *GetUserMessageRequest) GetId() int64 { - if x != nil { - return x.Id - } - return 0 -} - -func (x *GetUserMessageRequest) GetCount() int64 { - if x != nil { - return x.Count - } - return 0 -} - -type GetUserMessageReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Messages []*Message `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"` -} - -func (x *GetUserMessageReply) Reset() { - *x = GetUserMessageReply{} - if protoimpl.UnsafeEnabled { - mi := &file_traces_api_message_message_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetUserMessageReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetUserMessageReply) ProtoMessage() {} - -func (x *GetUserMessageReply) ProtoReflect() protoreflect.Message { - mi := &file_traces_api_message_message_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetUserMessageReply.ProtoReflect.Descriptor instead. -func (*GetUserMessageReply) Descriptor() ([]byte, []int) { - return file_traces_api_message_message_proto_rawDescGZIP(), []int{1} -} - -func (x *GetUserMessageReply) GetMessages() []*Message { - if x != nil { - return x.Messages - } - return nil -} - -type Message struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Content string `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"` -} - -func (x *Message) Reset() { - *x = Message{} - if protoimpl.UnsafeEnabled { - mi := &file_traces_api_message_message_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Message) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Message) ProtoMessage() {} - -func (x *Message) ProtoReflect() protoreflect.Message { - mi := &file_traces_api_message_message_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Message.ProtoReflect.Descriptor instead. -func (*Message) Descriptor() ([]byte, []int) { - return file_traces_api_message_message_proto_rawDescGZIP(), []int{2} -} - -func (x *Message) GetContent() string { - if x != nil { - return x.Content - } - return "" -} - -var File_traces_api_message_message_proto protoreflect.FileDescriptor - -var file_traces_api_message_message_proto_rawDesc = []byte{ - 0x0a, 0x20, 0x74, 0x72, 0x61, 0x63, 0x65, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x12, 0x0e, 0x61, 0x70, 0x69, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, - 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, - 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0x3d, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, - 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, - 0x4a, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x33, 0x0a, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x52, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x22, 0x23, 0x0a, 0x07, 0x4d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, - 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, - 0x32, 0x99, 0x01, 0x0a, 0x0e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x12, 0x86, 0x01, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x4d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x25, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x4d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, - 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, - 0x6c, 0x79, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x12, 0x1d, 0x2f, 0x76, 0x31, 0x2f, - 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x7b, 0x69, 0x64, - 0x7d, 0x2f, 0x7b, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x7d, 0x3a, 0x01, 0x2a, 0x42, 0x51, 0x0a, 0x0e, - 0x61, 0x70, 0x69, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x50, 0x01, - 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, - 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x73, 0x2f, 0x61, 0x70, - 0x69, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_traces_api_message_message_proto_rawDescOnce sync.Once - file_traces_api_message_message_proto_rawDescData = file_traces_api_message_message_proto_rawDesc -) - -func file_traces_api_message_message_proto_rawDescGZIP() []byte { - file_traces_api_message_message_proto_rawDescOnce.Do(func() { - file_traces_api_message_message_proto_rawDescData = protoimpl.X.CompressGZIP(file_traces_api_message_message_proto_rawDescData) - }) - return file_traces_api_message_message_proto_rawDescData -} - -var file_traces_api_message_message_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_traces_api_message_message_proto_goTypes = []interface{}{ - (*GetUserMessageRequest)(nil), // 0: api.message.v1.GetUserMessageRequest - (*GetUserMessageReply)(nil), // 1: api.message.v1.GetUserMessageReply - (*Message)(nil), // 2: api.message.v1.Message -} -var file_traces_api_message_message_proto_depIdxs = []int32{ - 2, // 0: api.message.v1.GetUserMessageReply.messages:type_name -> api.message.v1.Message - 0, // 1: api.message.v1.MessageService.GetUserMessage:input_type -> api.message.v1.GetUserMessageRequest - 1, // 2: api.message.v1.MessageService.GetUserMessage:output_type -> api.message.v1.GetUserMessageReply - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_traces_api_message_message_proto_init() } -func file_traces_api_message_message_proto_init() { - if File_traces_api_message_message_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_traces_api_message_message_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetUserMessageRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_traces_api_message_message_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetUserMessageReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_traces_api_message_message_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Message); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_traces_api_message_message_proto_rawDesc, - NumEnums: 0, - NumMessages: 3, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_traces_api_message_message_proto_goTypes, - DependencyIndexes: file_traces_api_message_message_proto_depIdxs, - MessageInfos: file_traces_api_message_message_proto_msgTypes, - }.Build() - File_traces_api_message_message_proto = out.File - file_traces_api_message_message_proto_rawDesc = nil - file_traces_api_message_message_proto_goTypes = nil - file_traces_api_message_message_proto_depIdxs = nil -} diff --git a/examples/traces/api/message/message.proto b/examples/traces/api/message/message.proto deleted file mode 100644 index 70837dbf9..000000000 --- a/examples/traces/api/message/message.proto +++ /dev/null @@ -1,32 +0,0 @@ -syntax = "proto3"; - -package api.message.v1; - -option go_package = "github.com/go-kratos/kratos/examples/traces/api/message/v1;v1"; -option java_multiple_files = true; -option java_package = "api.message.v1"; - -import "google/api/annotations.proto"; - -service MessageService { - rpc GetUserMessage (GetUserMessageRequest) returns (GetUserMessageReply){ - option (google.api.http) = { - get: "/v1/message/user/{id}/{count}" - body: "*" - }; - } -} - - -message GetUserMessageRequest { - int64 id = 1; - int64 count = 2; -} - -message GetUserMessageReply { - repeated Message messages = 1; -} - -message Message { - string content = 1; -} diff --git a/examples/traces/api/message/message_grpc.pb.go b/examples/traces/api/message/message_grpc.pb.go deleted file mode 100644 index fb7525030..000000000 --- a/examples/traces/api/message/message_grpc.pb.go +++ /dev/null @@ -1,101 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package v1 - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// MessageServiceClient is the client API for MessageService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type MessageServiceClient interface { - GetUserMessage(ctx context.Context, in *GetUserMessageRequest, opts ...grpc.CallOption) (*GetUserMessageReply, error) -} - -type messageServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewMessageServiceClient(cc grpc.ClientConnInterface) MessageServiceClient { - return &messageServiceClient{cc} -} - -func (c *messageServiceClient) GetUserMessage(ctx context.Context, in *GetUserMessageRequest, opts ...grpc.CallOption) (*GetUserMessageReply, error) { - out := new(GetUserMessageReply) - err := c.cc.Invoke(ctx, "/api.message.v1.MessageService/GetUserMessage", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// MessageServiceServer is the server API for MessageService service. -// All implementations must embed UnimplementedMessageServiceServer -// for forward compatibility -type MessageServiceServer interface { - GetUserMessage(context.Context, *GetUserMessageRequest) (*GetUserMessageReply, error) - mustEmbedUnimplementedMessageServiceServer() -} - -// UnimplementedMessageServiceServer must be embedded to have forward compatible implementations. -type UnimplementedMessageServiceServer struct { -} - -func (UnimplementedMessageServiceServer) GetUserMessage(context.Context, *GetUserMessageRequest) (*GetUserMessageReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetUserMessage not implemented") -} -func (UnimplementedMessageServiceServer) mustEmbedUnimplementedMessageServiceServer() {} - -// UnsafeMessageServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to MessageServiceServer will -// result in compilation errors. -type UnsafeMessageServiceServer interface { - mustEmbedUnimplementedMessageServiceServer() -} - -func RegisterMessageServiceServer(s grpc.ServiceRegistrar, srv MessageServiceServer) { - s.RegisterService(&MessageService_ServiceDesc, srv) -} - -func _MessageService_GetUserMessage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetUserMessageRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MessageServiceServer).GetUserMessage(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/api.message.v1.MessageService/GetUserMessage", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MessageServiceServer).GetUserMessage(ctx, req.(*GetUserMessageRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// MessageService_ServiceDesc is the grpc.ServiceDesc for MessageService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var MessageService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "api.message.v1.MessageService", - HandlerType: (*MessageServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "GetUserMessage", - Handler: _MessageService_GetUserMessage_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "traces/api/message/message.proto", -} diff --git a/examples/traces/api/message/message_http.pb.go b/examples/traces/api/message/message_http.pb.go deleted file mode 100644 index dbab58c83..000000000 --- a/examples/traces/api/message/message_http.pb.go +++ /dev/null @@ -1,74 +0,0 @@ -// Code generated by protoc-gen-go-http. DO NOT EDIT. -// versions: -// protoc-gen-go-http v2.0.0 - -package v1 - -import ( - context "context" - http "github.com/go-kratos/kratos/v2/transport/http" - binding "github.com/go-kratos/kratos/v2/transport/http/binding" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the kratos package it is being compiled against. -var _ = new(context.Context) -var _ = binding.EncodeURL - -const _ = http.SupportPackageIsVersion1 - -type MessageServiceHTTPServer interface { - GetUserMessage(context.Context, *GetUserMessageRequest) (*GetUserMessageReply, error) -} - -func RegisterMessageServiceHTTPServer(s *http.Server, srv MessageServiceHTTPServer) { - r := s.Route("/") - r.GET("/v1/message/user/{id}/{count}", _MessageService_GetUserMessage0_HTTP_Handler(srv)) -} - -func _MessageService_GetUserMessage0_HTTP_Handler(srv MessageServiceHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in GetUserMessageRequest - if err := ctx.BindQuery(&in); err != nil { - return err - } - if err := ctx.BindVars(&in); err != nil { - return err - } - http.SetOperation(ctx, "/api.message.v1.MessageService/GetUserMessage") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.GetUserMessage(ctx, req.(*GetUserMessageRequest)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*GetUserMessageReply) - return ctx.Result(200, reply) - } -} - -type MessageServiceHTTPClient interface { - GetUserMessage(ctx context.Context, req *GetUserMessageRequest, opts ...http.CallOption) (rsp *GetUserMessageReply, err error) -} - -type MessageServiceHTTPClientImpl struct { - cc *http.Client -} - -func NewMessageServiceHTTPClient(client *http.Client) MessageServiceHTTPClient { - return &MessageServiceHTTPClientImpl{client} -} - -func (c *MessageServiceHTTPClientImpl) GetUserMessage(ctx context.Context, in *GetUserMessageRequest, opts ...http.CallOption) (*GetUserMessageReply, error) { - var out GetUserMessageReply - pattern := "/v1/message/user/{id}/{count}" - path := binding.EncodeURL(pattern, in, true) - opts = append(opts, http.Operation("/api.message.v1.MessageService/GetUserMessage")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} diff --git a/examples/traces/api/user/user.pb.go b/examples/traces/api/user/user.pb.go deleted file mode 100644 index 570bbe71b..000000000 --- a/examples/traces/api/user/user.pb.go +++ /dev/null @@ -1,289 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.15.7 -// source: traces/api/user/user.proto - -package v1 - -import ( - _ "google.golang.org/genproto/googleapis/api/annotations" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type GetMyMessagesRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Count int64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` -} - -func (x *GetMyMessagesRequest) Reset() { - *x = GetMyMessagesRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_traces_api_user_user_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetMyMessagesRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetMyMessagesRequest) ProtoMessage() {} - -func (x *GetMyMessagesRequest) ProtoReflect() protoreflect.Message { - mi := &file_traces_api_user_user_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetMyMessagesRequest.ProtoReflect.Descriptor instead. -func (*GetMyMessagesRequest) Descriptor() ([]byte, []int) { - return file_traces_api_user_user_proto_rawDescGZIP(), []int{0} -} - -func (x *GetMyMessagesRequest) GetCount() int64 { - if x != nil { - return x.Count - } - return 0 -} - -type GetMyMessagesReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Messages []*Message `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"` -} - -func (x *GetMyMessagesReply) Reset() { - *x = GetMyMessagesReply{} - if protoimpl.UnsafeEnabled { - mi := &file_traces_api_user_user_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetMyMessagesReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetMyMessagesReply) ProtoMessage() {} - -func (x *GetMyMessagesReply) ProtoReflect() protoreflect.Message { - mi := &file_traces_api_user_user_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetMyMessagesReply.ProtoReflect.Descriptor instead. -func (*GetMyMessagesReply) Descriptor() ([]byte, []int) { - return file_traces_api_user_user_proto_rawDescGZIP(), []int{1} -} - -func (x *GetMyMessagesReply) GetMessages() []*Message { - if x != nil { - return x.Messages - } - return nil -} - -type Message struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Content string `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"` -} - -func (x *Message) Reset() { - *x = Message{} - if protoimpl.UnsafeEnabled { - mi := &file_traces_api_user_user_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Message) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Message) ProtoMessage() {} - -func (x *Message) ProtoReflect() protoreflect.Message { - mi := &file_traces_api_user_user_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Message.ProtoReflect.Descriptor instead. -func (*Message) Descriptor() ([]byte, []int) { - return file_traces_api_user_user_proto_rawDescGZIP(), []int{2} -} - -func (x *Message) GetContent() string { - if x != nil { - return x.Content - } - return "" -} - -var File_traces_api_user_user_proto protoreflect.FileDescriptor - -var file_traces_api_user_user_proto_rawDesc = []byte{ - 0x0a, 0x1a, 0x74, 0x72, 0x61, 0x63, 0x65, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x75, 0x73, 0x65, - 0x72, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x61, 0x70, - 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x2c, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x4d, 0x79, - 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x46, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x4d, 0x79, 0x4d, 0x65, - 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x30, 0x0a, 0x08, 0x6d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x73, 0x73, - 0x61, 0x67, 0x65, 0x52, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x22, 0x23, 0x0a, - 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, - 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, - 0x6e, 0x74, 0x32, 0x84, 0x01, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x7c, 0x0a, 0x0d, 0x47, - 0x65, 0x74, 0x4d, 0x79, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x12, 0x21, 0x2e, 0x61, - 0x70, 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x79, - 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, - 0x74, 0x4d, 0x79, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, - 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x12, 0x1c, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, - 0x65, 0x72, 0x2f, 0x67, 0x65, 0x74, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2f, 0x7b, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x7d, 0x3a, 0x01, 0x2a, 0x42, 0x55, 0x0a, 0x0b, 0x61, 0x70, 0x69, - 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x50, 0x01, 0x5a, 0x44, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, - 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, - 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2d, 0x68, 0x74, 0x74, 0x70, 0x2d, 0x67, 0x72, 0x70, - 0x63, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_traces_api_user_user_proto_rawDescOnce sync.Once - file_traces_api_user_user_proto_rawDescData = file_traces_api_user_user_proto_rawDesc -) - -func file_traces_api_user_user_proto_rawDescGZIP() []byte { - file_traces_api_user_user_proto_rawDescOnce.Do(func() { - file_traces_api_user_user_proto_rawDescData = protoimpl.X.CompressGZIP(file_traces_api_user_user_proto_rawDescData) - }) - return file_traces_api_user_user_proto_rawDescData -} - -var file_traces_api_user_user_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_traces_api_user_user_proto_goTypes = []interface{}{ - (*GetMyMessagesRequest)(nil), // 0: api.user.v1.GetMyMessagesRequest - (*GetMyMessagesReply)(nil), // 1: api.user.v1.GetMyMessagesReply - (*Message)(nil), // 2: api.user.v1.Message -} -var file_traces_api_user_user_proto_depIdxs = []int32{ - 2, // 0: api.user.v1.GetMyMessagesReply.messages:type_name -> api.user.v1.Message - 0, // 1: api.user.v1.User.GetMyMessages:input_type -> api.user.v1.GetMyMessagesRequest - 1, // 2: api.user.v1.User.GetMyMessages:output_type -> api.user.v1.GetMyMessagesReply - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_traces_api_user_user_proto_init() } -func file_traces_api_user_user_proto_init() { - if File_traces_api_user_user_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_traces_api_user_user_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetMyMessagesRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_traces_api_user_user_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetMyMessagesReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_traces_api_user_user_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Message); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_traces_api_user_user_proto_rawDesc, - NumEnums: 0, - NumMessages: 3, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_traces_api_user_user_proto_goTypes, - DependencyIndexes: file_traces_api_user_user_proto_depIdxs, - MessageInfos: file_traces_api_user_user_proto_msgTypes, - }.Build() - File_traces_api_user_user_proto = out.File - file_traces_api_user_user_proto_rawDesc = nil - file_traces_api_user_user_proto_goTypes = nil - file_traces_api_user_user_proto_depIdxs = nil -} diff --git a/examples/traces/api/user/user.proto b/examples/traces/api/user/user.proto deleted file mode 100644 index 01ccc4b29..000000000 --- a/examples/traces/api/user/user.proto +++ /dev/null @@ -1,30 +0,0 @@ -syntax = "proto3"; - -package api.user.v1; - -option go_package = "github.com/go-kratos/kratos/examples/kratos-http-grpc/api/user/v1;v1"; -option java_multiple_files = true; -option java_package = "api.user.v1"; - -import "google/api/annotations.proto"; - -service User { - rpc GetMyMessages (GetMyMessagesRequest) returns (GetMyMessagesReply){ - option (google.api.http) = { - get: "/v1/user/get/message/{count}" - body: "*" - }; - } -} - - -message GetMyMessagesRequest { - int64 count = 1; -} -message GetMyMessagesReply { - repeated Message messages = 1; -} - -message Message { - string content = 1; -} diff --git a/examples/traces/api/user/user_grpc.pb.go b/examples/traces/api/user/user_grpc.pb.go deleted file mode 100644 index 53af844bf..000000000 --- a/examples/traces/api/user/user_grpc.pb.go +++ /dev/null @@ -1,101 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package v1 - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// UserClient is the client API for User service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type UserClient interface { - GetMyMessages(ctx context.Context, in *GetMyMessagesRequest, opts ...grpc.CallOption) (*GetMyMessagesReply, error) -} - -type userClient struct { - cc grpc.ClientConnInterface -} - -func NewUserClient(cc grpc.ClientConnInterface) UserClient { - return &userClient{cc} -} - -func (c *userClient) GetMyMessages(ctx context.Context, in *GetMyMessagesRequest, opts ...grpc.CallOption) (*GetMyMessagesReply, error) { - out := new(GetMyMessagesReply) - err := c.cc.Invoke(ctx, "/api.user.v1.User/GetMyMessages", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// UserServer is the server API for User service. -// All implementations must embed UnimplementedUserServer -// for forward compatibility -type UserServer interface { - GetMyMessages(context.Context, *GetMyMessagesRequest) (*GetMyMessagesReply, error) - mustEmbedUnimplementedUserServer() -} - -// UnimplementedUserServer must be embedded to have forward compatible implementations. -type UnimplementedUserServer struct { -} - -func (UnimplementedUserServer) GetMyMessages(context.Context, *GetMyMessagesRequest) (*GetMyMessagesReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetMyMessages not implemented") -} -func (UnimplementedUserServer) mustEmbedUnimplementedUserServer() {} - -// UnsafeUserServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to UserServer will -// result in compilation errors. -type UnsafeUserServer interface { - mustEmbedUnimplementedUserServer() -} - -func RegisterUserServer(s grpc.ServiceRegistrar, srv UserServer) { - s.RegisterService(&User_ServiceDesc, srv) -} - -func _User_GetMyMessages_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetMyMessagesRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(UserServer).GetMyMessages(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/api.user.v1.User/GetMyMessages", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(UserServer).GetMyMessages(ctx, req.(*GetMyMessagesRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// User_ServiceDesc is the grpc.ServiceDesc for User service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var User_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "api.user.v1.User", - HandlerType: (*UserServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "GetMyMessages", - Handler: _User_GetMyMessages_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "traces/api/user/user.proto", -} diff --git a/examples/traces/api/user/user_http.pb.go b/examples/traces/api/user/user_http.pb.go deleted file mode 100644 index 2b670cf70..000000000 --- a/examples/traces/api/user/user_http.pb.go +++ /dev/null @@ -1,74 +0,0 @@ -// Code generated by protoc-gen-go-http. DO NOT EDIT. -// versions: -// protoc-gen-go-http v2.0.0 - -package v1 - -import ( - context "context" - http "github.com/go-kratos/kratos/v2/transport/http" - binding "github.com/go-kratos/kratos/v2/transport/http/binding" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the kratos package it is being compiled against. -var _ = new(context.Context) -var _ = binding.EncodeURL - -const _ = http.SupportPackageIsVersion1 - -type UserHTTPServer interface { - GetMyMessages(context.Context, *GetMyMessagesRequest) (*GetMyMessagesReply, error) -} - -func RegisterUserHTTPServer(s *http.Server, srv UserHTTPServer) { - r := s.Route("/") - r.GET("/v1/user/get/message/{count}", _User_GetMyMessages0_HTTP_Handler(srv)) -} - -func _User_GetMyMessages0_HTTP_Handler(srv UserHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in GetMyMessagesRequest - if err := ctx.BindQuery(&in); err != nil { - return err - } - if err := ctx.BindVars(&in); err != nil { - return err - } - http.SetOperation(ctx, "/api.user.v1.User/GetMyMessages") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.GetMyMessages(ctx, req.(*GetMyMessagesRequest)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*GetMyMessagesReply) - return ctx.Result(200, reply) - } -} - -type UserHTTPClient interface { - GetMyMessages(ctx context.Context, req *GetMyMessagesRequest, opts ...http.CallOption) (rsp *GetMyMessagesReply, err error) -} - -type UserHTTPClientImpl struct { - cc *http.Client -} - -func NewUserHTTPClient(client *http.Client) UserHTTPClient { - return &UserHTTPClientImpl{client} -} - -func (c *UserHTTPClientImpl) GetMyMessages(ctx context.Context, in *GetMyMessagesRequest, opts ...http.CallOption) (*GetMyMessagesReply, error) { - var out GetMyMessagesReply - pattern := "/v1/user/get/message/{count}" - path := binding.EncodeURL(pattern, in, true) - opts = append(opts, http.Operation("/api.user.v1.User/GetMyMessages")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} diff --git a/examples/traces/app/message/main.go b/examples/traces/app/message/main.go deleted file mode 100644 index 7eb888475..000000000 --- a/examples/traces/app/message/main.go +++ /dev/null @@ -1,104 +0,0 @@ -package main - -import ( - "context" - "os" - - v1 "github.com/go-kratos/kratos/examples/traces/api/message" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/middleware/tracing" - "github.com/go-kratos/kratos/v2/transport/grpc" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/exporters/jaeger" - "go.opentelemetry.io/otel/sdk/resource" - tracesdk "go.opentelemetry.io/otel/sdk/trace" - semconv "go.opentelemetry.io/otel/semconv/v1.4.0" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name = "message" - // Version is the version of the compiled software. - // Version = "v1.0.0" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - v1.UnimplementedMessageServiceServer -} - -// set trace provider -func setTracerProvider(url string) error { - // Create the Jaeger exporter - exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url))) - if err != nil { - return err - } - tp := tracesdk.NewTracerProvider( - // Set the sampling rate based on the parent span to 100% - tracesdk.WithSampler(tracesdk.ParentBased(tracesdk.TraceIDRatioBased(1.0))), - // Always be sure to batch in production. - tracesdk.WithBatcher(exp), - // Record information about this application in an Resource. - tracesdk.WithResource(resource.NewSchemaless( - semconv.ServiceNameKey.String(Name), - attribute.String("env", "dev"), - )), - ) - otel.SetTracerProvider(tp) - return nil -} - -func (s *server) GetUserMessage(ctx context.Context, request *v1.GetUserMessageRequest) (*v1.GetUserMessageReply, error) { - msgs := &v1.GetUserMessageReply{} - for i := 0; i < int(request.Count); i++ { - msgs.Messages = append(msgs.Messages, &v1.Message{Content: "Teletubbies say hello."}) - } - return msgs, nil -} - -func main() { - logger := log.NewStdLogger(os.Stdout) - logger = log.With(logger, "trace_id", tracing.TraceID()) - logger = log.With(logger, "span_id", tracing.SpanID()) - log := log.NewHelper(logger) - - url := "http://jaeger:14268/api/traces" - if os.Getenv("jaeger_url") != "" { - url = os.Getenv("jaeger_url") - } - err := setTracerProvider(url) - if err != nil { - log.Error(err) - } - - s := &server{} - // grpc server - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - middleware.Chain( - recovery.Recovery(), - tracing.Server(), - logging.Server(logger), - ), - )) - v1.RegisterMessageServiceServer(grpcSrv, s) - - app := kratos.New( - kratos.Name(Name), - kratos.Server( - grpcSrv, - ), - ) - - if err := app.Run(); err != nil { - log.Error(err) - } -} diff --git a/examples/traces/app/user/main.go b/examples/traces/app/user/main.go deleted file mode 100644 index b0ce5d8c0..000000000 --- a/examples/traces/app/user/main.go +++ /dev/null @@ -1,127 +0,0 @@ -package main - -import ( - "context" - "os" - "time" - - messagev1 "github.com/go-kratos/kratos/examples/traces/api/message" - v1 "github.com/go-kratos/kratos/examples/traces/api/user" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/middleware/tracing" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/exporters/jaeger" - "go.opentelemetry.io/otel/sdk/resource" - tracesdk "go.opentelemetry.io/otel/sdk/trace" - semconv "go.opentelemetry.io/otel/semconv/v1.4.0" - grpcx "google.golang.org/grpc" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name = "user" - // Version is the version of the compiled software. - // Version = "v1.0.0" -) - -// server is used to implement helloworld.GreeterServer. -type server struct { - v1.UnimplementedUserServer -} - -// Set global trace provider -func setTracerProvider(url string) error { - // Create the Jaeger exporter - exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url))) - if err != nil { - return err - } - tp := tracesdk.NewTracerProvider( - // Set the sampling rate based on the parent span to 100% - tracesdk.WithSampler(tracesdk.ParentBased(tracesdk.TraceIDRatioBased(1.0))), - // Always be sure to batch in production. - tracesdk.WithBatcher(exp), - // Record information about this application in an Resource. - tracesdk.WithResource(resource.NewSchemaless( - semconv.ServiceNameKey.String(Name), - attribute.String("env", "dev"), - )), - ) - otel.SetTracerProvider(tp) - return nil -} - -func (s *server) GetMyMessages(ctx context.Context, in *v1.GetMyMessagesRequest) (*v1.GetMyMessagesReply, error) { - // create grpc conn - // only for demo, use single instance in production env - conn, err := grpc.DialInsecure(ctx, - grpc.WithEndpoint("127.0.0.1:9000"), - grpc.WithMiddleware( - recovery.Recovery(), - tracing.Client(), - ), - grpc.WithTimeout(2*time.Second), - // for tracing remote ip recording - grpc.WithOptions(grpcx.WithStatsHandler(&tracing.ClientHandler{})), - ) - if err != nil { - return nil, err - } - msg := messagev1.NewMessageServiceClient(conn) - // Method of calling blog service - reply, err := msg.GetUserMessage(ctx, &messagev1.GetUserMessageRequest{Id: 123, Count: in.Count}) - if err != nil { - return nil, err - } - res := &v1.GetMyMessagesReply{} - for _, v := range reply.Messages { - res.Messages = append(res.Messages, &v1.Message{Content: v.Content}) - } - return res, nil -} - -func main() { - logger := log.NewStdLogger(os.Stdout) - logger = log.With(logger, "trace_id", tracing.TraceID()) - logger = log.With(logger, "span_id", tracing.SpanID()) - log := log.NewHelper(logger) - - url := "http://jaeger:14268/api/traces" - if os.Getenv("jaeger_url") != "" { - url = os.Getenv("jaeger_url") - } - err := setTracerProvider(url) - if err != nil { - log.Error(err) - } - - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - recovery.Recovery(), - tracing.Server(), - logging.Server(logger), - ), - ) - s := &server{} - v1.RegisterUserHTTPServer(httpSrv, s) - - app := kratos.New( - kratos.Name(Name), - kratos.Server( - httpSrv, - ), - ) - - if err := app.Run(); err != nil { - log.Error(err) - } -} diff --git a/examples/traces/docker-compose.yml b/examples/traces/docker-compose.yml deleted file mode 100644 index 74d020eae..000000000 --- a/examples/traces/docker-compose.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: '3' -services: - traces: - networks: - - traces - build: . - ports: - - "8000:8000" - - "9000:9000" - - jaeger: - image: jaegertracing/all-in-one:1.16 - ports: - - "16686:16686" - - "14268:14268" - networks: - - traces -networks: - traces: - driver: bridge \ No newline at end of file diff --git a/examples/traces/service.sh b/examples/traces/service.sh deleted file mode 100644 index 5ee064024..000000000 --- a/examples/traces/service.sh +++ /dev/null @@ -1,2 +0,0 @@ -/app/user & -nohup /app/message \ No newline at end of file diff --git a/examples/traces/start-windows.bat b/examples/traces/start-windows.bat deleted file mode 100644 index 3987632fb..000000000 --- a/examples/traces/start-windows.bat +++ /dev/null @@ -1,6 +0,0 @@ -cd ./app/message -CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/message ./... -cd ../../ -cd ./app/user -CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/user ./... -docker-compose up --build \ No newline at end of file diff --git a/examples/traces/start.sh b/examples/traces/start.sh deleted file mode 100644 index 95e85f207..000000000 --- a/examples/traces/start.sh +++ /dev/null @@ -1,6 +0,0 @@ -cd ./app/message || exit -CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/message ./... -cd ../../ -cd ./app/user || exit -CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/user ./... -docker-compose up --build \ No newline at end of file diff --git a/examples/transaction/api/transaction/v1/transaction.pb.go b/examples/transaction/api/transaction/v1/transaction.pb.go deleted file mode 100644 index f95a49202..000000000 --- a/examples/transaction/api/transaction/v1/transaction.pb.go +++ /dev/null @@ -1,233 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.1 -// protoc v3.17.3 -// source: api/transaction/v1/transaction.proto - -package v1 - -import ( - _ "google.golang.org/genproto/googleapis/api/annotations" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type CreateUserRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"` -} - -func (x *CreateUserRequest) Reset() { - *x = CreateUserRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_api_transaction_v1_transaction_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CreateUserRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CreateUserRequest) ProtoMessage() {} - -func (x *CreateUserRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_transaction_v1_transaction_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use CreateUserRequest.ProtoReflect.Descriptor instead. -func (*CreateUserRequest) Descriptor() ([]byte, []int) { - return file_api_transaction_v1_transaction_proto_rawDescGZIP(), []int{0} -} - -func (x *CreateUserRequest) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *CreateUserRequest) GetEmail() string { - if x != nil { - return x.Email - } - return "" -} - -type CreateUserReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (x *CreateUserReply) Reset() { - *x = CreateUserReply{} - if protoimpl.UnsafeEnabled { - mi := &file_api_transaction_v1_transaction_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CreateUserReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CreateUserReply) ProtoMessage() {} - -func (x *CreateUserReply) ProtoReflect() protoreflect.Message { - mi := &file_api_transaction_v1_transaction_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use CreateUserReply.ProtoReflect.Descriptor instead. -func (*CreateUserReply) Descriptor() ([]byte, []int) { - return file_api_transaction_v1_transaction_proto_rawDescGZIP(), []int{1} -} - -func (x *CreateUserReply) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -var File_api_transaction_v1_transaction_proto protoreflect.FileDescriptor - -var file_api_transaction_v1_transaction_proto_rawDesc = []byte{ - 0x0a, 0x24, 0x61, 0x70, 0x69, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0x3d, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, - 0x61, 0x69, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, - 0x22, 0x21, 0x0a, 0x0f, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, - 0x70, 0x6c, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x02, 0x69, 0x64, 0x32, 0x7c, 0x0a, 0x12, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x66, 0x0a, 0x0a, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, - 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, - 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, - 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x1a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x22, 0x0f, 0x2f, - 0x76, 0x31, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x01, - 0x2a, 0x42, 0x5e, 0x0a, 0x12, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x50, 0x01, 0x5a, 0x46, 0x67, 0x69, 0x74, 0x68, 0x75, - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, - 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, - 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x3b, 0x76, - 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_api_transaction_v1_transaction_proto_rawDescOnce sync.Once - file_api_transaction_v1_transaction_proto_rawDescData = file_api_transaction_v1_transaction_proto_rawDesc -) - -func file_api_transaction_v1_transaction_proto_rawDescGZIP() []byte { - file_api_transaction_v1_transaction_proto_rawDescOnce.Do(func() { - file_api_transaction_v1_transaction_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_transaction_v1_transaction_proto_rawDescData) - }) - return file_api_transaction_v1_transaction_proto_rawDescData -} - -var file_api_transaction_v1_transaction_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_api_transaction_v1_transaction_proto_goTypes = []interface{}{ - (*CreateUserRequest)(nil), // 0: blog.api.v1.CreateUserRequest - (*CreateUserReply)(nil), // 1: blog.api.v1.CreateUserReply -} -var file_api_transaction_v1_transaction_proto_depIdxs = []int32{ - 0, // 0: blog.api.v1.TransactionService.CreateUser:input_type -> blog.api.v1.CreateUserRequest - 1, // 1: blog.api.v1.TransactionService.CreateUser:output_type -> blog.api.v1.CreateUserReply - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_api_transaction_v1_transaction_proto_init() } -func file_api_transaction_v1_transaction_proto_init() { - if File_api_transaction_v1_transaction_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_api_transaction_v1_transaction_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateUserRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_api_transaction_v1_transaction_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateUserReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_api_transaction_v1_transaction_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_api_transaction_v1_transaction_proto_goTypes, - DependencyIndexes: file_api_transaction_v1_transaction_proto_depIdxs, - MessageInfos: file_api_transaction_v1_transaction_proto_msgTypes, - }.Build() - File_api_transaction_v1_transaction_proto = out.File - file_api_transaction_v1_transaction_proto_rawDesc = nil - file_api_transaction_v1_transaction_proto_goTypes = nil - file_api_transaction_v1_transaction_proto_depIdxs = nil -} diff --git a/examples/transaction/api/transaction/v1/transaction.proto b/examples/transaction/api/transaction/v1/transaction.proto deleted file mode 100644 index f667673fa..000000000 --- a/examples/transaction/api/transaction/v1/transaction.proto +++ /dev/null @@ -1,27 +0,0 @@ -syntax = "proto3"; - -package blog.api.v1; - -option go_package = "github.com/go-kratos/kratos/examples/transaction/api/transaction/v1;v1"; -option java_multiple_files = true; -option java_package = "transaction.api.v1"; - -import "google/api/annotations.proto"; - -service TransactionService { - rpc CreateUser(CreateUserRequest) returns (CreateUserReply) { - option (google.api.http) = { - post: "/v1/transaction" - body: "*" - }; - } -} - -message CreateUserRequest { - string name = 1; - string email = 2; -} - -message CreateUserReply { - string id = 1; -} diff --git a/examples/transaction/api/transaction/v1/transaction_grpc.pb.go b/examples/transaction/api/transaction/v1/transaction_grpc.pb.go deleted file mode 100644 index 663683f6c..000000000 --- a/examples/transaction/api/transaction/v1/transaction_grpc.pb.go +++ /dev/null @@ -1,105 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.2.0 -// - protoc v3.17.3 -// source: api/transaction/v1/transaction.proto - -package v1 - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// TransactionServiceClient is the client API for TransactionService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type TransactionServiceClient interface { - CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*CreateUserReply, error) -} - -type transactionServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewTransactionServiceClient(cc grpc.ClientConnInterface) TransactionServiceClient { - return &transactionServiceClient{cc} -} - -func (c *transactionServiceClient) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*CreateUserReply, error) { - out := new(CreateUserReply) - err := c.cc.Invoke(ctx, "/blog.api.v1.TransactionService/CreateUser", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// TransactionServiceServer is the server API for TransactionService service. -// All implementations must embed UnimplementedTransactionServiceServer -// for forward compatibility -type TransactionServiceServer interface { - CreateUser(context.Context, *CreateUserRequest) (*CreateUserReply, error) - mustEmbedUnimplementedTransactionServiceServer() -} - -// UnimplementedTransactionServiceServer must be embedded to have forward compatible implementations. -type UnimplementedTransactionServiceServer struct { -} - -func (UnimplementedTransactionServiceServer) CreateUser(context.Context, *CreateUserRequest) (*CreateUserReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method CreateUser not implemented") -} -func (UnimplementedTransactionServiceServer) mustEmbedUnimplementedTransactionServiceServer() {} - -// UnsafeTransactionServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to TransactionServiceServer will -// result in compilation errors. -type UnsafeTransactionServiceServer interface { - mustEmbedUnimplementedTransactionServiceServer() -} - -func RegisterTransactionServiceServer(s grpc.ServiceRegistrar, srv TransactionServiceServer) { - s.RegisterService(&TransactionService_ServiceDesc, srv) -} - -func _TransactionService_CreateUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CreateUserRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(TransactionServiceServer).CreateUser(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/blog.api.v1.TransactionService/CreateUser", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(TransactionServiceServer).CreateUser(ctx, req.(*CreateUserRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// TransactionService_ServiceDesc is the grpc.ServiceDesc for TransactionService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var TransactionService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "blog.api.v1.TransactionService", - HandlerType: (*TransactionServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "CreateUser", - Handler: _TransactionService_CreateUser_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "api/transaction/v1/transaction.proto", -} diff --git a/examples/transaction/api/transaction/v1/transaction_http.pb.go b/examples/transaction/api/transaction/v1/transaction_http.pb.go deleted file mode 100644 index cebe3d9d1..000000000 --- a/examples/transaction/api/transaction/v1/transaction_http.pb.go +++ /dev/null @@ -1,71 +0,0 @@ -// Code generated by protoc-gen-go-http. DO NOT EDIT. -// versions: -// protoc-gen-go-http v2.1.4 - -package v1 - -import ( - context "context" - http "github.com/go-kratos/kratos/v2/transport/http" - binding "github.com/go-kratos/kratos/v2/transport/http/binding" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the kratos package it is being compiled against. -var _ = new(context.Context) -var _ = binding.EncodeURL - -const _ = http.SupportPackageIsVersion1 - -type TransactionServiceHTTPServer interface { - CreateUser(context.Context, *CreateUserRequest) (*CreateUserReply, error) -} - -func RegisterTransactionServiceHTTPServer(s *http.Server, srv TransactionServiceHTTPServer) { - r := s.Route("/") - r.POST("/v1/transaction", _TransactionService_CreateUser0_HTTP_Handler(srv)) -} - -func _TransactionService_CreateUser0_HTTP_Handler(srv TransactionServiceHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in CreateUserRequest - if err := ctx.Bind(&in); err != nil { - return err - } - http.SetOperation(ctx, "/blog.api.v1.TransactionService/CreateUser") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.CreateUser(ctx, req.(*CreateUserRequest)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*CreateUserReply) - return ctx.Result(200, reply) - } -} - -type TransactionServiceHTTPClient interface { - CreateUser(ctx context.Context, req *CreateUserRequest, opts ...http.CallOption) (rsp *CreateUserReply, err error) -} - -type TransactionServiceHTTPClientImpl struct { - cc *http.Client -} - -func NewTransactionServiceHTTPClient(client *http.Client) TransactionServiceHTTPClient { - return &TransactionServiceHTTPClientImpl{client} -} - -func (c *TransactionServiceHTTPClientImpl) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...http.CallOption) (*CreateUserReply, error) { - var out CreateUserReply - pattern := "/v1/transaction" - path := binding.EncodeURL(pattern, in, false) - opts = append(opts, http.Operation("/blog.api.v1.TransactionService/CreateUser")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} diff --git a/examples/transaction/ent/Makefile b/examples/transaction/ent/Makefile deleted file mode 100644 index 4804d0dbe..000000000 --- a/examples/transaction/ent/Makefile +++ /dev/null @@ -1,80 +0,0 @@ -GOPATH:=$(shell go env GOPATH) -VERSION=$(shell git describe --tags --always) -INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) -API_PROTO_FILES=$(shell find api -name *.proto) - -.PHONY: init -# init env -init: - go install google.golang.org/protobuf/cmd/protoc-gen-go@latest - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest - go install github.com/go-kratos/kratos/cmd/kratos/v2@latest - go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest - go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest - go install github.com/google/gnostic/cmd/protoc-gen-openapi@v0.6.1 - go install entgo.io/ent/cmd/ent@latest - -.PHONY: errors -# generate errors code -errors: - protoc --proto_path=. \ - --proto_path=./third_party \ - --go_out=paths=source_relative:. \ - --go-errors_out=paths=source_relative:. \ - $(API_PROTO_FILES) - -.PHONY: config -# generate internal proto -config: - protoc --proto_path=. \ - --proto_path=./third_party \ - --go_out=paths=source_relative:. \ - $(INTERNAL_PROTO_FILES) - -.PHONY: api -# generate api proto -api: - protoc --proto_path=. \ - --proto_path=./third_party \ - --go_out=paths=source_relative:. \ - --go-http_out=paths=source_relative:. \ - --go-grpc_out=paths=source_relative:. \ - --openapi_out==paths=source_relative:. \ - $(API_PROTO_FILES) - -.PHONY: build -# build -build: - mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./... - -.PHONY: generate -# generate -generate: - go generate ./... - -.PHONY: all -# generate all -all: - make api; - make errors; - make config; - make generate; - -# show help -help: - @echo '' - @echo 'Usage:' - @echo ' make [target]' - @echo '' - @echo 'Targets:' - @awk '/^[a-zA-Z\-\_0-9]+:/ { \ - helpMessage = match(lastLine, /^# (.*)/); \ - if (helpMessage) { \ - helpCommand = substr($$1, 0, index($$1, ":")-1); \ - helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \ - printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \ - } \ - } \ - { lastLine = $$0 }' $(MAKEFILE_LIST) - -.DEFAULT_GOAL := help diff --git a/examples/transaction/ent/README.md b/examples/transaction/ent/README.md deleted file mode 100644 index 4c85ae7cb..000000000 --- a/examples/transaction/ent/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# How to run this blog example server -1. You should ensure that your mysql server is running. -2. Ensure that the database named `testdb` has been created, - otherwise you should execute the following database script: -```mysql -create database testdb; -``` -3. Modify the `configs/config.yaml` file and add your mysql information in the data source: -```yaml -data: - database: - driver: mysql - source: root:password@tcp(127.0.0.1:3306)/testdb?parseTime=True -``` -4. Run your blog server: -```bash -$ go generate ./... -$ kratos run -``` diff --git a/examples/transaction/ent/cmd/ent/main.go b/examples/transaction/ent/cmd/ent/main.go deleted file mode 100644 index 94158f6c1..000000000 --- a/examples/transaction/ent/cmd/ent/main.go +++ /dev/null @@ -1,103 +0,0 @@ -package main - -import ( - "flag" - "os" - - "github.com/go-kratos/kratos/examples/transaction/ent/internal/conf" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/config" - "github.com/go-kratos/kratos/v2/config/file" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/exporters/jaeger" - "go.opentelemetry.io/otel/sdk/resource" - tracesdk "go.opentelemetry.io/otel/sdk/trace" - semconv "go.opentelemetry.io/otel/semconv/v1.4.0" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name string - // Version is the version of the compiled software. - Version string - // flagconf is the config flag. - flagconf string -) - -func init() { - flag.StringVar(&flagconf, "conf", "../../configs", "config path, eg: -conf config.yaml") -} - -func newApp(logger log.Logger, hs *http.Server, gs *grpc.Server) *kratos.App { - return kratos.New( - kratos.Name(Name), - kratos.Version(Version), - kratos.Metadata(map[string]string{}), - kratos.Logger(logger), - kratos.Server( - hs, - gs, - ), - ) -} - -// Set global trace provider -func setTracerProvider(url string) error { - // Create the Jaeger exporter - exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url))) - if err != nil { - return err - } - tp := tracesdk.NewTracerProvider( - // Set the sampling rate based on the parent span to 100% - tracesdk.WithSampler(tracesdk.ParentBased(tracesdk.TraceIDRatioBased(1.0))), - // Always be sure to batch in production. - tracesdk.WithBatcher(exp), - // Record information about this application in an Resource. - tracesdk.WithResource(resource.NewSchemaless( - semconv.ServiceNameKey.String(Name), - attribute.String("env", "dev"), - )), - ) - otel.SetTracerProvider(tp) - return nil -} - -func main() { - flag.Parse() - logger := log.NewStdLogger(os.Stdout) - - cfg := config.New( - config.WithSource( - file.NewSource(flagconf), - ), - ) - if err := cfg.Load(); err != nil { - panic(err) - } - - var bc conf.Bootstrap - if err := cfg.Scan(&bc); err != nil { - panic(err) - } - - if err := setTracerProvider(bc.Trace.Endpoint); err != nil { - panic(err) - } - - app, cleanup, err := initApp(bc.Server, bc.Data, logger) - if err != nil { - panic(err) - } - defer cleanup() - - // start and wait for stop signal - if err := app.Run(); err != nil { - panic(err) - } -} diff --git a/examples/transaction/ent/cmd/ent/wire.go b/examples/transaction/ent/cmd/ent/wire.go deleted file mode 100644 index 6ee686bc1..000000000 --- a/examples/transaction/ent/cmd/ent/wire.go +++ /dev/null @@ -1,22 +0,0 @@ -//go:build wireinject -// +build wireinject - -// The build tag makes sure the stub is not built in the final build. - -package main - -import ( - "github.com/go-kratos/kratos/examples/transaction/ent/internal/biz" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/conf" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/server" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/service" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" - "github.com/google/wire" -) - -// initApp init kratos application. -func initApp(*conf.Server, *conf.Data, log.Logger) (*kratos.App, func(), error) { - panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) -} diff --git a/examples/transaction/ent/cmd/ent/wire_gen.go b/examples/transaction/ent/cmd/ent/wire_gen.go deleted file mode 100644 index 7016691b8..000000000 --- a/examples/transaction/ent/cmd/ent/wire_gen.go +++ /dev/null @@ -1,37 +0,0 @@ -// Code generated by Wire. DO NOT EDIT. - -//go:generate go run github.com/google/wire/cmd/wire -//+build !wireinject - -package main - -import ( - "github.com/go-kratos/kratos/examples/transaction/ent/internal/biz" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/conf" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/server" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/service" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" -) - -// Injectors from wire.go: - -// initApp init kratos application. -func initApp(confServer *conf.Server, confData *conf.Data, logger log.Logger) (*kratos.App, func(), error) { - dataData, cleanup, err := data.NewData(confData, logger) - if err != nil { - return nil, nil, err - } - userRepo := data.NewUserRepo(dataData, logger) - cardRepo := data.NewCardRepo(dataData, logger) - transaction := data.NewTransaction(dataData) - userUsecase := biz.NewUserUsecase(userRepo, cardRepo, transaction, logger) - transactionService := service.NewTransactionService(userUsecase, logger) - httpServer := server.NewHTTPServer(confServer, logger, transactionService) - grpcServer := server.NewGRPCServer(confServer, logger, transactionService) - app := newApp(logger, httpServer, grpcServer) - return app, func() { - cleanup() - }, nil -} diff --git a/examples/transaction/ent/configs/config.yaml b/examples/transaction/ent/configs/config.yaml deleted file mode 100644 index 3409aa489..000000000 --- a/examples/transaction/ent/configs/config.yaml +++ /dev/null @@ -1,18 +0,0 @@ -trace: - endpoint: http://127.0.0.1:14268/api/traces -server: - http: - addr: 0.0.0.0:8000 - timeout: 1s - grpc: - addr: 0.0.0.0:9000 - timeout: 1s -data: - database: - driver: mysql - source: root:123456@tcp(127.0.0.1:3306)/testdb?parseTime=True - redis: - addr: 127.0.0.1:6379 - dial_timeout: 1s - read_timeout: 0.4s - write_timeout: 0.6s \ No newline at end of file diff --git a/examples/transaction/ent/generate.go b/examples/transaction/ent/generate.go deleted file mode 100644 index 4aac2aa9f..000000000 --- a/examples/transaction/ent/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package generate - -//go:generate kratos proto client . diff --git a/examples/transaction/ent/internal/biz/README.md b/examples/transaction/ent/internal/biz/README.md deleted file mode 100644 index 26a66b630..000000000 --- a/examples/transaction/ent/internal/biz/README.md +++ /dev/null @@ -1 +0,0 @@ -# Biz diff --git a/examples/transaction/ent/internal/biz/biz.go b/examples/transaction/ent/internal/biz/biz.go deleted file mode 100644 index f2ca2350f..000000000 --- a/examples/transaction/ent/internal/biz/biz.go +++ /dev/null @@ -1,14 +0,0 @@ -package biz - -import ( - "context" - - "github.com/google/wire" -) - -// ProviderSet is biz providers. -var ProviderSet = wire.NewSet(NewUserUsecase) - -type Transaction interface { - ExecTx(context.Context, func(ctx context.Context) error) error -} diff --git a/examples/transaction/ent/internal/biz/transaction.go b/examples/transaction/ent/internal/biz/transaction.go deleted file mode 100644 index bfd9a2dff..000000000 --- a/examples/transaction/ent/internal/biz/transaction.go +++ /dev/null @@ -1,50 +0,0 @@ -package biz - -import ( - "context" - - "github.com/go-kratos/kratos/v2/log" -) - -type User struct { - Name string - Email string -} - -type UserRepo interface { - CreateUser(ctx context.Context, a *User) (int, error) -} - -type CardRepo interface { - CreateCard(ctx context.Context, id int) (int, error) -} - -type UserUsecase struct { - userRepo UserRepo - cardRepo CardRepo - tm Transaction -} - -func NewUserUsecase(user UserRepo, card CardRepo, tm Transaction, logger log.Logger) *UserUsecase { - return &UserUsecase{userRepo: user, cardRepo: card, tm: tm} -} - -func (u *UserUsecase) CreateUser(ctx context.Context, m *User) (int, error) { - var ( - err error - id int - ) - if e := u.tm.ExecTx(ctx, func(ctx context.Context) error { - id, err = u.userRepo.CreateUser(ctx, m) - if err != nil { - return err - } - if _, e := u.cardRepo.CreateCard(ctx, id); err != nil { - return e - } - return nil - }); e != nil { - return 0, err - } - return id, nil -} diff --git a/examples/transaction/ent/internal/conf/conf.pb.go b/examples/transaction/ent/internal/conf/conf.pb.go deleted file mode 100644 index 995d029ef..000000000 --- a/examples/transaction/ent/internal/conf/conf.pb.go +++ /dev/null @@ -1,763 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.17.0 -// source: conf.proto - -package conf - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - durationpb "google.golang.org/protobuf/types/known/durationpb" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Bootstrap struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Trace *Trace `protobuf:"bytes,1,opt,name=trace,proto3" json:"trace,omitempty"` - Server *Server `protobuf:"bytes,2,opt,name=server,proto3" json:"server,omitempty"` - Data *Data `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` -} - -func (x *Bootstrap) Reset() { - *x = Bootstrap{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Bootstrap) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Bootstrap) ProtoMessage() {} - -func (x *Bootstrap) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Bootstrap.ProtoReflect.Descriptor instead. -func (*Bootstrap) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{0} -} - -func (x *Bootstrap) GetTrace() *Trace { - if x != nil { - return x.Trace - } - return nil -} - -func (x *Bootstrap) GetServer() *Server { - if x != nil { - return x.Server - } - return nil -} - -func (x *Bootstrap) GetData() *Data { - if x != nil { - return x.Data - } - return nil -} - -type Server struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Http *Server_HTTP `protobuf:"bytes,1,opt,name=http,proto3" json:"http,omitempty"` - Grpc *Server_GRPC `protobuf:"bytes,2,opt,name=grpc,proto3" json:"grpc,omitempty"` -} - -func (x *Server) Reset() { - *x = Server{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server) ProtoMessage() {} - -func (x *Server) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server.ProtoReflect.Descriptor instead. -func (*Server) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{1} -} - -func (x *Server) GetHttp() *Server_HTTP { - if x != nil { - return x.Http - } - return nil -} - -func (x *Server) GetGrpc() *Server_GRPC { - if x != nil { - return x.Grpc - } - return nil -} - -type Data struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Database *Data_Database `protobuf:"bytes,1,opt,name=database,proto3" json:"database,omitempty"` - Redis *Data_Redis `protobuf:"bytes,2,opt,name=redis,proto3" json:"redis,omitempty"` -} - -func (x *Data) Reset() { - *x = Data{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data) ProtoMessage() {} - -func (x *Data) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data.ProtoReflect.Descriptor instead. -func (*Data) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{2} -} - -func (x *Data) GetDatabase() *Data_Database { - if x != nil { - return x.Database - } - return nil -} - -func (x *Data) GetRedis() *Data_Redis { - if x != nil { - return x.Redis - } - return nil -} - -type Trace struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Endpoint string `protobuf:"bytes,1,opt,name=endpoint,proto3" json:"endpoint,omitempty"` -} - -func (x *Trace) Reset() { - *x = Trace{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Trace) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Trace) ProtoMessage() {} - -func (x *Trace) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Trace.ProtoReflect.Descriptor instead. -func (*Trace) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{3} -} - -func (x *Trace) GetEndpoint() string { - if x != nil { - return x.Endpoint - } - return "" -} - -type Server_HTTP struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - Timeout *durationpb.Duration `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"` -} - -func (x *Server_HTTP) Reset() { - *x = Server_HTTP{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server_HTTP) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server_HTTP) ProtoMessage() {} - -func (x *Server_HTTP) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server_HTTP.ProtoReflect.Descriptor instead. -func (*Server_HTTP) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{1, 0} -} - -func (x *Server_HTTP) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Server_HTTP) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Server_HTTP) GetTimeout() *durationpb.Duration { - if x != nil { - return x.Timeout - } - return nil -} - -type Server_GRPC struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - Timeout *durationpb.Duration `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"` -} - -func (x *Server_GRPC) Reset() { - *x = Server_GRPC{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server_GRPC) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server_GRPC) ProtoMessage() {} - -func (x *Server_GRPC) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server_GRPC.ProtoReflect.Descriptor instead. -func (*Server_GRPC) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{1, 1} -} - -func (x *Server_GRPC) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Server_GRPC) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Server_GRPC) GetTimeout() *durationpb.Duration { - if x != nil { - return x.Timeout - } - return nil -} - -type Data_Database struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Driver string `protobuf:"bytes,1,opt,name=driver,proto3" json:"driver,omitempty"` - Source string `protobuf:"bytes,2,opt,name=source,proto3" json:"source,omitempty"` -} - -func (x *Data_Database) Reset() { - *x = Data_Database{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data_Database) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data_Database) ProtoMessage() {} - -func (x *Data_Database) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data_Database.ProtoReflect.Descriptor instead. -func (*Data_Database) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{2, 0} -} - -func (x *Data_Database) GetDriver() string { - if x != nil { - return x.Driver - } - return "" -} - -func (x *Data_Database) GetSource() string { - if x != nil { - return x.Source - } - return "" -} - -type Data_Redis struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - Password string `protobuf:"bytes,3,opt,name=password,proto3" json:"password,omitempty"` - Db int32 `protobuf:"varint,4,opt,name=db,proto3" json:"db,omitempty"` - DialTimeout *durationpb.Duration `protobuf:"bytes,5,opt,name=dial_timeout,json=dialTimeout,proto3" json:"dial_timeout,omitempty"` - ReadTimeout *durationpb.Duration `protobuf:"bytes,6,opt,name=read_timeout,json=readTimeout,proto3" json:"read_timeout,omitempty"` - WriteTimeout *durationpb.Duration `protobuf:"bytes,7,opt,name=write_timeout,json=writeTimeout,proto3" json:"write_timeout,omitempty"` -} - -func (x *Data_Redis) Reset() { - *x = Data_Redis{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data_Redis) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data_Redis) ProtoMessage() {} - -func (x *Data_Redis) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[7] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data_Redis.ProtoReflect.Descriptor instead. -func (*Data_Redis) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{2, 1} -} - -func (x *Data_Redis) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Data_Redis) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Data_Redis) GetPassword() string { - if x != nil { - return x.Password - } - return "" -} - -func (x *Data_Redis) GetDb() int32 { - if x != nil { - return x.Db - } - return 0 -} - -func (x *Data_Redis) GetDialTimeout() *durationpb.Duration { - if x != nil { - return x.DialTimeout - } - return nil -} - -func (x *Data_Redis) GetReadTimeout() *durationpb.Duration { - if x != nil { - return x.ReadTimeout - } - return nil -} - -func (x *Data_Redis) GetWriteTimeout() *durationpb.Duration { - if x != nil { - return x.WriteTimeout - } - return nil -} - -var File_conf_proto protoreflect.FileDescriptor - -var file_conf_proto_rawDesc = []byte{ - 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x6b, 0x72, - 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, - 0x6e, 0x66, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0xa4, 0x01, 0x0a, 0x09, 0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, - 0x12, 0x31, 0x0a, 0x05, 0x74, 0x72, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x1b, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x54, 0x72, 0x61, 0x63, 0x65, 0x52, 0x05, 0x74, 0x72, - 0x61, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, - 0x72, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x2e, 0x0a, 0x04, 0x64, 0x61, 0x74, - 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, - 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, - 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xcc, 0x02, 0x0a, 0x06, 0x53, 0x65, - 0x72, 0x76, 0x65, 0x72, 0x12, 0x35, 0x0a, 0x04, 0x68, 0x74, 0x74, 0x70, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, - 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x04, 0x68, 0x74, 0x74, 0x70, 0x12, 0x35, 0x0a, 0x04, 0x67, - 0x72, 0x70, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x6b, 0x72, 0x61, 0x74, - 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, - 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x47, 0x52, 0x50, 0x43, 0x52, 0x04, 0x67, 0x72, - 0x70, 0x63, 0x1a, 0x69, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, - 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, - 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x33, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, - 0x6f, 0x75, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x1a, 0x69, 0x0a, - 0x04, 0x47, 0x52, 0x50, 0x43, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, - 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, - 0x64, 0x64, 0x72, 0x12, 0x33, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, - 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x22, 0xdb, 0x03, 0x0a, 0x04, 0x44, 0x61, 0x74, - 0x61, 0x12, 0x3f, 0x0a, 0x08, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x2e, - 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, - 0x73, 0x65, 0x12, 0x36, 0x0a, 0x05, 0x72, 0x65, 0x64, 0x69, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x20, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, - 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x52, 0x65, - 0x64, 0x69, 0x73, 0x52, 0x05, 0x72, 0x65, 0x64, 0x69, 0x73, 0x1a, 0x3a, 0x0a, 0x08, 0x44, 0x61, - 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x12, 0x16, - 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, - 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0x9d, 0x02, 0x0a, 0x05, 0x52, 0x65, 0x64, 0x69, 0x73, - 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, - 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x1a, - 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x64, 0x62, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x64, 0x62, 0x12, 0x3c, 0x0a, 0x0c, 0x64, 0x69, - 0x61, 0x6c, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x64, 0x69, 0x61, - 0x6c, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3c, 0x0a, 0x0c, 0x72, 0x65, 0x61, 0x64, - 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x72, 0x65, 0x61, 0x64, 0x54, - 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3e, 0x0a, 0x0d, 0x77, 0x72, 0x69, 0x74, 0x65, 0x5f, - 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0c, 0x77, 0x72, 0x69, 0x74, 0x65, 0x54, - 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x22, 0x23, 0x0a, 0x05, 0x54, 0x72, 0x61, 0x63, 0x65, 0x12, - 0x1a, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x42, 0x3e, 0x5a, 0x3c, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, - 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x73, 0x2f, 0x62, 0x6c, 0x6f, 0x67, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, 0x63, 0x6f, 0x6e, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, -} - -var ( - file_conf_proto_rawDescOnce sync.Once - file_conf_proto_rawDescData = file_conf_proto_rawDesc -) - -func file_conf_proto_rawDescGZIP() []byte { - file_conf_proto_rawDescOnce.Do(func() { - file_conf_proto_rawDescData = protoimpl.X.CompressGZIP(file_conf_proto_rawDescData) - }) - return file_conf_proto_rawDescData -} - -var file_conf_proto_msgTypes = make([]protoimpl.MessageInfo, 8) -var file_conf_proto_goTypes = []interface{}{ - (*Bootstrap)(nil), // 0: kratos.internal.conf.Bootstrap - (*Server)(nil), // 1: kratos.internal.conf.Server - (*Data)(nil), // 2: kratos.internal.conf.Data - (*Trace)(nil), // 3: kratos.internal.conf.Trace - (*Server_HTTP)(nil), // 4: kratos.internal.conf.Server.HTTP - (*Server_GRPC)(nil), // 5: kratos.internal.conf.Server.GRPC - (*Data_Database)(nil), // 6: kratos.internal.conf.Data.Database - (*Data_Redis)(nil), // 7: kratos.internal.conf.Data.Redis - (*durationpb.Duration)(nil), // 8: google.protobuf.Duration -} -var file_conf_proto_depIdxs = []int32{ - 3, // 0: kratos.internal.conf.Bootstrap.trace:type_name -> kratos.internal.conf.Trace - 1, // 1: kratos.internal.conf.Bootstrap.server:type_name -> kratos.internal.conf.Server - 2, // 2: kratos.internal.conf.Bootstrap.data:type_name -> kratos.internal.conf.Data - 4, // 3: kratos.internal.conf.Server.http:type_name -> kratos.internal.conf.Server.HTTP - 5, // 4: kratos.internal.conf.Server.grpc:type_name -> kratos.internal.conf.Server.GRPC - 6, // 5: kratos.internal.conf.Data.database:type_name -> kratos.internal.conf.Data.Database - 7, // 6: kratos.internal.conf.Data.redis:type_name -> kratos.internal.conf.Data.Redis - 8, // 7: kratos.internal.conf.Server.HTTP.timeout:type_name -> google.protobuf.Duration - 8, // 8: kratos.internal.conf.Server.GRPC.timeout:type_name -> google.protobuf.Duration - 8, // 9: kratos.internal.conf.Data.Redis.dial_timeout:type_name -> google.protobuf.Duration - 8, // 10: kratos.internal.conf.Data.Redis.read_timeout:type_name -> google.protobuf.Duration - 8, // 11: kratos.internal.conf.Data.Redis.write_timeout:type_name -> google.protobuf.Duration - 12, // [12:12] is the sub-list for method output_type - 12, // [12:12] is the sub-list for method input_type - 12, // [12:12] is the sub-list for extension type_name - 12, // [12:12] is the sub-list for extension extendee - 0, // [0:12] is the sub-list for field type_name -} - -func init() { file_conf_proto_init() } -func file_conf_proto_init() { - if File_conf_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_conf_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Bootstrap); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Trace); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server_HTTP); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server_GRPC); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data_Database); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data_Redis); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_conf_proto_rawDesc, - NumEnums: 0, - NumMessages: 8, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_conf_proto_goTypes, - DependencyIndexes: file_conf_proto_depIdxs, - MessageInfos: file_conf_proto_msgTypes, - }.Build() - File_conf_proto = out.File - file_conf_proto_rawDesc = nil - file_conf_proto_goTypes = nil - file_conf_proto_depIdxs = nil -} diff --git a/examples/transaction/ent/internal/conf/conf.proto b/examples/transaction/ent/internal/conf/conf.proto deleted file mode 100644 index 491c21a13..000000000 --- a/examples/transaction/ent/internal/conf/conf.proto +++ /dev/null @@ -1,49 +0,0 @@ -syntax = "proto3"; -package kratos.internal.conf; - -option go_package = "github.com/go-kratos/kratos/examples/blog/internal/conf;conf"; - -import "google/protobuf/duration.proto"; - -message Bootstrap { - Trace trace = 1; - Server server = 2; - Data data = 3; -} - -message Server { - message HTTP { - string network = 1; - string addr = 2; - google.protobuf.Duration timeout = 3; - } - message GRPC { - string network = 1; - string addr = 2; - google.protobuf.Duration timeout = 3; - } - HTTP http = 1; - GRPC grpc = 2; -} - -message Data { - message Database { - string driver = 1; - string source = 2; - } - message Redis { - string network = 1; - string addr = 2; - string password = 3; - int32 db = 4; - google.protobuf.Duration dial_timeout = 5; - google.protobuf.Duration read_timeout = 6; - google.protobuf.Duration write_timeout = 7; - } - Database database = 1; - Redis redis = 2; -} - -message Trace { - string endpoint = 1; -} \ No newline at end of file diff --git a/examples/transaction/ent/internal/data/README.md b/examples/transaction/ent/internal/data/README.md deleted file mode 100644 index a9f7e8dad..000000000 --- a/examples/transaction/ent/internal/data/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Data - -``` -go generate ./ent -``` \ No newline at end of file diff --git a/examples/transaction/ent/internal/data/data.go b/examples/transaction/ent/internal/data/data.go deleted file mode 100644 index eec5937d6..000000000 --- a/examples/transaction/ent/internal/data/data.go +++ /dev/null @@ -1,88 +0,0 @@ -package data - -import ( - "context" - - "github.com/go-kratos/kratos/examples/transaction/ent/internal/biz" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/conf" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent" - - "entgo.io/ent/dialect/sql" - "github.com/go-kratos/kratos/v2/log" - "github.com/google/wire" - - // init mysql driver - _ "github.com/go-sql-driver/mysql" -) - -// ProviderSet is data providers. -var ProviderSet = wire.NewSet(NewData, NewTransaction, NewUserRepo, NewCardRepo) - -// Data . -type Data struct { - db *ent.Client -} - -type contextTxKey struct{} - -func (d *Data) ExecTx(ctx context.Context, f func(ctx context.Context) error) error { - tx, err := d.db.Tx(ctx) - if err != nil { - return err - } - ctx = context.WithValue(ctx, contextTxKey{}, tx) - if err := f(ctx); err != nil { - _ = tx.Rollback() - return err - } - return tx.Commit() -} - -func (d *Data) User(ctx context.Context) *ent.UserClient { - tx, ok := ctx.Value(contextTxKey{}).(*ent.Tx) - if ok { - return tx.User - } - return d.db.User -} - -func (d *Data) Card(ctx context.Context) *ent.CardClient { - tx, ok := ctx.Value(contextTxKey{}).(*ent.Tx) - if ok { - return tx.Card - } - return d.db.Card -} - -func NewTransaction(d *Data) biz.Transaction { - return d -} - -// NewData . -func NewData(conf *conf.Data, logger log.Logger) (*Data, func(), error) { - log := log.NewHelper(logger) - drv, err := sql.Open( - conf.Database.Driver, - conf.Database.Source, - ) - client := ent.NewClient(ent.Driver(drv)) - if err != nil { - log.Errorf("failed opening connection to sqlite: %v", err) - return nil, nil, err - } - // Run the auto migration tool. - if err := client.Schema.Create(context.Background()); err != nil { - log.Errorf("failed creating schema resources: %v", err) - return nil, nil, err - } - - d := &Data{ - db: client, - } - return d, func() { - log.Info("message", "closing the data resources") - if err := d.db.Close(); err != nil { - log.Error(err) - } - }, nil -} diff --git a/examples/transaction/ent/internal/data/ent/card.go b/examples/transaction/ent/internal/data/ent/card.go deleted file mode 100644 index ea9f6365d..000000000 --- a/examples/transaction/ent/internal/data/ent/card.go +++ /dev/null @@ -1,109 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - - "entgo.io/ent/dialect/sql" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/card" -) - -// Card is the model entity for the Card schema. -type Card struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // UserID holds the value of the "user_id" field. - UserID string `json:"user_id,omitempty"` - // Money holds the value of the "money" field. - Money string `json:"money,omitempty"` -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*Card) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) - for i := range columns { - switch columns[i] { - case card.FieldID: - values[i] = new(sql.NullInt64) - case card.FieldUserID, card.FieldMoney: - values[i] = new(sql.NullString) - default: - return nil, fmt.Errorf("unexpected column %q for type Card", columns[i]) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Card fields. -func (c *Card) assignValues(columns []string, values []interface{}) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case card.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - c.ID = int(value.Int64) - case card.FieldUserID: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field user_id", values[i]) - } else if value.Valid { - c.UserID = value.String - } - case card.FieldMoney: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field money", values[i]) - } else if value.Valid { - c.Money = value.String - } - } - } - return nil -} - -// Update returns a builder for updating this Card. -// Note that you need to call Card.Unwrap() before calling this method if this Card -// was returned from a transaction, and the transaction was committed or rolled back. -func (c *Card) Update() *CardUpdateOne { - return (&CardClient{config: c.config}).UpdateOne(c) -} - -// Unwrap unwraps the Card entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (c *Card) Unwrap() *Card { - tx, ok := c.config.driver.(*txDriver) - if !ok { - panic("ent: Card is not a transactional entity") - } - c.config.driver = tx.drv - return c -} - -// String implements the fmt.Stringer. -func (c *Card) String() string { - var builder strings.Builder - builder.WriteString("Card(") - builder.WriteString(fmt.Sprintf("id=%v", c.ID)) - builder.WriteString(", user_id=") - builder.WriteString(c.UserID) - builder.WriteString(", money=") - builder.WriteString(c.Money) - builder.WriteByte(')') - return builder.String() -} - -// Cards is a parsable slice of Card. -type Cards []*Card - -func (c Cards) config(cfg config) { - for _i := range c { - c[_i].config = cfg - } -} diff --git a/examples/transaction/ent/internal/data/ent/card/card.go b/examples/transaction/ent/internal/data/ent/card/card.go deleted file mode 100644 index d7c9e03e2..000000000 --- a/examples/transaction/ent/internal/data/ent/card/card.go +++ /dev/null @@ -1,33 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package card - -const ( - // Label holds the string label denoting the card type in the database. - Label = "card" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldUserID holds the string denoting the user_id field in the database. - FieldUserID = "user_id" - // FieldMoney holds the string denoting the money field in the database. - FieldMoney = "money" - // Table holds the table name of the card in the database. - Table = "cards" -) - -// Columns holds all SQL columns for card fields. -var Columns = []string{ - FieldID, - FieldUserID, - FieldMoney, -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} diff --git a/examples/transaction/ent/internal/data/ent/card/where.go b/examples/transaction/ent/internal/data/ent/card/where.go deleted file mode 100644 index cd047483d..000000000 --- a/examples/transaction/ent/internal/data/ent/card/where.go +++ /dev/null @@ -1,359 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package card - -import ( - "entgo.io/ent/dialect/sql" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) -} - -// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ. -func UserID(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUserID), v)) - }) -} - -// Money applies equality check predicate on the "money" field. It's identical to MoneyEQ. -func Money(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldMoney), v)) - }) -} - -// UserIDEQ applies the EQ predicate on the "user_id" field. -func UserIDEQ(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUserID), v)) - }) -} - -// UserIDNEQ applies the NEQ predicate on the "user_id" field. -func UserIDNEQ(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUserID), v)) - }) -} - -// UserIDIn applies the In predicate on the "user_id" field. -func UserIDIn(vs ...string) predicate.Card { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Card(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldUserID), v...)) - }) -} - -// UserIDNotIn applies the NotIn predicate on the "user_id" field. -func UserIDNotIn(vs ...string) predicate.Card { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Card(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldUserID), v...)) - }) -} - -// UserIDGT applies the GT predicate on the "user_id" field. -func UserIDGT(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUserID), v)) - }) -} - -// UserIDGTE applies the GTE predicate on the "user_id" field. -func UserIDGTE(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUserID), v)) - }) -} - -// UserIDLT applies the LT predicate on the "user_id" field. -func UserIDLT(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUserID), v)) - }) -} - -// UserIDLTE applies the LTE predicate on the "user_id" field. -func UserIDLTE(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUserID), v)) - }) -} - -// UserIDContains applies the Contains predicate on the "user_id" field. -func UserIDContains(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldUserID), v)) - }) -} - -// UserIDHasPrefix applies the HasPrefix predicate on the "user_id" field. -func UserIDHasPrefix(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldUserID), v)) - }) -} - -// UserIDHasSuffix applies the HasSuffix predicate on the "user_id" field. -func UserIDHasSuffix(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldUserID), v)) - }) -} - -// UserIDEqualFold applies the EqualFold predicate on the "user_id" field. -func UserIDEqualFold(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldUserID), v)) - }) -} - -// UserIDContainsFold applies the ContainsFold predicate on the "user_id" field. -func UserIDContainsFold(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldUserID), v)) - }) -} - -// MoneyEQ applies the EQ predicate on the "money" field. -func MoneyEQ(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldMoney), v)) - }) -} - -// MoneyNEQ applies the NEQ predicate on the "money" field. -func MoneyNEQ(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldMoney), v)) - }) -} - -// MoneyIn applies the In predicate on the "money" field. -func MoneyIn(vs ...string) predicate.Card { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Card(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldMoney), v...)) - }) -} - -// MoneyNotIn applies the NotIn predicate on the "money" field. -func MoneyNotIn(vs ...string) predicate.Card { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Card(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldMoney), v...)) - }) -} - -// MoneyGT applies the GT predicate on the "money" field. -func MoneyGT(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldMoney), v)) - }) -} - -// MoneyGTE applies the GTE predicate on the "money" field. -func MoneyGTE(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldMoney), v)) - }) -} - -// MoneyLT applies the LT predicate on the "money" field. -func MoneyLT(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldMoney), v)) - }) -} - -// MoneyLTE applies the LTE predicate on the "money" field. -func MoneyLTE(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldMoney), v)) - }) -} - -// MoneyContains applies the Contains predicate on the "money" field. -func MoneyContains(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldMoney), v)) - }) -} - -// MoneyHasPrefix applies the HasPrefix predicate on the "money" field. -func MoneyHasPrefix(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldMoney), v)) - }) -} - -// MoneyHasSuffix applies the HasSuffix predicate on the "money" field. -func MoneyHasSuffix(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldMoney), v)) - }) -} - -// MoneyEqualFold applies the EqualFold predicate on the "money" field. -func MoneyEqualFold(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldMoney), v)) - }) -} - -// MoneyContainsFold applies the ContainsFold predicate on the "money" field. -func MoneyContainsFold(v string) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldMoney), v)) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.Card) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.Card) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.Card) predicate.Card { - return predicate.Card(func(s *sql.Selector) { - p(s.Not()) - }) -} diff --git a/examples/transaction/ent/internal/data/ent/card_create.go b/examples/transaction/ent/internal/data/ent/card_create.go deleted file mode 100644 index 27be84538..000000000 --- a/examples/transaction/ent/internal/data/ent/card_create.go +++ /dev/null @@ -1,249 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/card" -) - -// CardCreate is the builder for creating a Card entity. -type CardCreate struct { - config - mutation *CardMutation - hooks []Hook -} - -// SetUserID sets the "user_id" field. -func (cc *CardCreate) SetUserID(s string) *CardCreate { - cc.mutation.SetUserID(s) - return cc -} - -// SetMoney sets the "money" field. -func (cc *CardCreate) SetMoney(s string) *CardCreate { - cc.mutation.SetMoney(s) - return cc -} - -// SetID sets the "id" field. -func (cc *CardCreate) SetID(i int) *CardCreate { - cc.mutation.SetID(i) - return cc -} - -// Mutation returns the CardMutation object of the builder. -func (cc *CardCreate) Mutation() *CardMutation { - return cc.mutation -} - -// Save creates the Card in the database. -func (cc *CardCreate) Save(ctx context.Context) (*Card, error) { - var ( - err error - node *Card - ) - if len(cc.hooks) == 0 { - if err = cc.check(); err != nil { - return nil, err - } - node, err = cc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CardMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = cc.check(); err != nil { - return nil, err - } - cc.mutation = mutation - if node, err = cc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(cc.hooks) - 1; i >= 0; i-- { - if cc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = cc.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cc.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX calls Save and panics if Save returns an error. -func (cc *CardCreate) SaveX(ctx context.Context) *Card { - v, err := cc.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (cc *CardCreate) Exec(ctx context.Context) error { - _, err := cc.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (cc *CardCreate) ExecX(ctx context.Context) { - if err := cc.Exec(ctx); err != nil { - panic(err) - } -} - -// check runs all checks and user-defined validators on the builder. -func (cc *CardCreate) check() error { - if _, ok := cc.mutation.UserID(); !ok { - return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "user_id"`)} - } - if _, ok := cc.mutation.Money(); !ok { - return &ValidationError{Name: "money", err: errors.New(`ent: missing required field "money"`)} - } - return nil -} - -func (cc *CardCreate) sqlSave(ctx context.Context) (*Card, error) { - _node, _spec := cc.createSpec() - if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - return nil, err - } - if _node.ID == 0 { - id := _spec.ID.Value.(int64) - _node.ID = int(id) - } - return _node, nil -} - -func (cc *CardCreate) createSpec() (*Card, *sqlgraph.CreateSpec) { - var ( - _node = &Card{config: cc.config} - _spec = &sqlgraph.CreateSpec{ - Table: card.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: card.FieldID, - }, - } - ) - if id, ok := cc.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = id - } - if value, ok := cc.mutation.UserID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: card.FieldUserID, - }) - _node.UserID = value - } - if value, ok := cc.mutation.Money(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: card.FieldMoney, - }) - _node.Money = value - } - return _node, _spec -} - -// CardCreateBulk is the builder for creating many Card entities in bulk. -type CardCreateBulk struct { - config - builders []*CardCreate -} - -// Save creates the Card entities in the database. -func (ccb *CardCreateBulk) Save(ctx context.Context) ([]*Card, error) { - specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) - nodes := make([]*Card, len(ccb.builders)) - mutators := make([]Mutator, len(ccb.builders)) - for i := range ccb.builders { - func(i int, root context.Context) { - builder := ccb.builders[i] - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CardMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() - var err error - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, ccb.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - mutation.done = true - if specs[i].ID.Value != nil && nodes[i].ID == 0 { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, ccb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (ccb *CardCreateBulk) SaveX(ctx context.Context) []*Card { - v, err := ccb.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (ccb *CardCreateBulk) Exec(ctx context.Context) error { - _, err := ccb.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (ccb *CardCreateBulk) ExecX(ctx context.Context) { - if err := ccb.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/examples/transaction/ent/internal/data/ent/card_delete.go b/examples/transaction/ent/internal/data/ent/card_delete.go deleted file mode 100644 index 5ac7767de..000000000 --- a/examples/transaction/ent/internal/data/ent/card_delete.go +++ /dev/null @@ -1,111 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/card" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/predicate" -) - -// CardDelete is the builder for deleting a Card entity. -type CardDelete struct { - config - hooks []Hook - mutation *CardMutation -} - -// Where appends a list predicates to the CardDelete builder. -func (cd *CardDelete) Where(ps ...predicate.Card) *CardDelete { - cd.mutation.Where(ps...) - return cd -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (cd *CardDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(cd.hooks) == 0 { - affected, err = cd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CardMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - cd.mutation = mutation - affected, err = cd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(cd.hooks) - 1; i >= 0; i-- { - if cd.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = cd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cd.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// ExecX is like Exec, but panics if an error occurs. -func (cd *CardDelete) ExecX(ctx context.Context) int { - n, err := cd.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (cd *CardDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: card.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: card.FieldID, - }, - }, - } - if ps := cd.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return sqlgraph.DeleteNodes(ctx, cd.driver, _spec) -} - -// CardDeleteOne is the builder for deleting a single Card entity. -type CardDeleteOne struct { - cd *CardDelete -} - -// Exec executes the deletion query. -func (cdo *CardDeleteOne) Exec(ctx context.Context) error { - n, err := cdo.cd.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{card.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (cdo *CardDeleteOne) ExecX(ctx context.Context) { - cdo.cd.ExecX(ctx) -} diff --git a/examples/transaction/ent/internal/data/ent/card_query.go b/examples/transaction/ent/internal/data/ent/card_query.go deleted file mode 100644 index fcdbe4ef6..000000000 --- a/examples/transaction/ent/internal/data/ent/card_query.go +++ /dev/null @@ -1,915 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "math" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/card" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/predicate" -) - -// CardQuery is the builder for querying Card entities. -type CardQuery struct { - config - limit *int - offset *int - unique *bool - order []OrderFunc - fields []string - predicates []predicate.Card - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the CardQuery builder. -func (cq *CardQuery) Where(ps ...predicate.Card) *CardQuery { - cq.predicates = append(cq.predicates, ps...) - return cq -} - -// Limit adds a limit step to the query. -func (cq *CardQuery) Limit(limit int) *CardQuery { - cq.limit = &limit - return cq -} - -// Offset adds an offset step to the query. -func (cq *CardQuery) Offset(offset int) *CardQuery { - cq.offset = &offset - return cq -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (cq *CardQuery) Unique(unique bool) *CardQuery { - cq.unique = &unique - return cq -} - -// Order adds an order step to the query. -func (cq *CardQuery) Order(o ...OrderFunc) *CardQuery { - cq.order = append(cq.order, o...) - return cq -} - -// First returns the first Card entity from the query. -// Returns a *NotFoundError when no Card was found. -func (cq *CardQuery) First(ctx context.Context) (*Card, error) { - nodes, err := cq.Limit(1).All(ctx) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{card.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (cq *CardQuery) FirstX(ctx context.Context) *Card { - node, err := cq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first Card ID from the query. -// Returns a *NotFoundError when no Card ID was found. -func (cq *CardQuery) FirstID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = cq.Limit(1).IDs(ctx); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{card.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (cq *CardQuery) FirstIDX(ctx context.Context) int { - id, err := cq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single Card entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one Card entity is not found. -// Returns a *NotFoundError when no Card entities are found. -func (cq *CardQuery) Only(ctx context.Context) (*Card, error) { - nodes, err := cq.Limit(2).All(ctx) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{card.Label} - default: - return nil, &NotSingularError{card.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (cq *CardQuery) OnlyX(ctx context.Context) *Card { - node, err := cq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only Card ID in the query. -// Returns a *NotSingularError when exactly one Card ID is not found. -// Returns a *NotFoundError when no entities are found. -func (cq *CardQuery) OnlyID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = cq.Limit(2).IDs(ctx); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{card.Label} - default: - err = &NotSingularError{card.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (cq *CardQuery) OnlyIDX(ctx context.Context) int { - id, err := cq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of Cards. -func (cq *CardQuery) All(ctx context.Context) ([]*Card, error) { - if err := cq.prepareQuery(ctx); err != nil { - return nil, err - } - return cq.sqlAll(ctx) -} - -// AllX is like All, but panics if an error occurs. -func (cq *CardQuery) AllX(ctx context.Context) []*Card { - nodes, err := cq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of Card IDs. -func (cq *CardQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := cq.Select(card.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (cq *CardQuery) IDsX(ctx context.Context) []int { - ids, err := cq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (cq *CardQuery) Count(ctx context.Context) (int, error) { - if err := cq.prepareQuery(ctx); err != nil { - return 0, err - } - return cq.sqlCount(ctx) -} - -// CountX is like Count, but panics if an error occurs. -func (cq *CardQuery) CountX(ctx context.Context) int { - count, err := cq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (cq *CardQuery) Exist(ctx context.Context) (bool, error) { - if err := cq.prepareQuery(ctx); err != nil { - return false, err - } - return cq.sqlExist(ctx) -} - -// ExistX is like Exist, but panics if an error occurs. -func (cq *CardQuery) ExistX(ctx context.Context) bool { - exist, err := cq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the CardQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (cq *CardQuery) Clone() *CardQuery { - if cq == nil { - return nil - } - return &CardQuery{ - config: cq.config, - limit: cq.limit, - offset: cq.offset, - order: append([]OrderFunc{}, cq.order...), - predicates: append([]predicate.Card{}, cq.predicates...), - // clone intermediate query. - sql: cq.sql.Clone(), - path: cq.path, - } -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// UserID string `json:"user_id,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.Card.Query(). -// GroupBy(card.FieldUserID). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -// -func (cq *CardQuery) GroupBy(field string, fields ...string) *CardGroupBy { - group := &CardGroupBy{config: cq.config} - group.fields = append([]string{field}, fields...) - group.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := cq.prepareQuery(ctx); err != nil { - return nil, err - } - return cq.sqlQuery(ctx), nil - } - return group -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// UserID string `json:"user_id,omitempty"` -// } -// -// client.Card.Query(). -// Select(card.FieldUserID). -// Scan(ctx, &v) -// -func (cq *CardQuery) Select(fields ...string) *CardSelect { - cq.fields = append(cq.fields, fields...) - return &CardSelect{CardQuery: cq} -} - -func (cq *CardQuery) prepareQuery(ctx context.Context) error { - for _, f := range cq.fields { - if !card.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if cq.path != nil { - prev, err := cq.path(ctx) - if err != nil { - return err - } - cq.sql = prev - } - return nil -} - -func (cq *CardQuery) sqlAll(ctx context.Context) ([]*Card, error) { - var ( - nodes = []*Card{} - _spec = cq.querySpec() - ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { - node := &Card{config: cq.config} - nodes = append(nodes, node) - return node.scanValues(columns) - } - _spec.Assign = func(columns []string, values []interface{}) error { - if len(nodes) == 0 { - return fmt.Errorf("ent: Assign called without calling ScanValues") - } - node := nodes[len(nodes)-1] - return node.assignValues(columns, values) - } - if err := sqlgraph.QueryNodes(ctx, cq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - return nodes, nil -} - -func (cq *CardQuery) sqlCount(ctx context.Context) (int, error) { - _spec := cq.querySpec() - return sqlgraph.CountNodes(ctx, cq.driver, _spec) -} - -func (cq *CardQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := cq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("ent: check existence: %w", err) - } - return n > 0, nil -} - -func (cq *CardQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: card.Table, - Columns: card.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: card.FieldID, - }, - }, - From: cq.sql, - Unique: true, - } - if unique := cq.unique; unique != nil { - _spec.Unique = *unique - } - if fields := cq.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, card.FieldID) - for i := range fields { - if fields[i] != card.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := cq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := cq.limit; limit != nil { - _spec.Limit = *limit - } - if offset := cq.offset; offset != nil { - _spec.Offset = *offset - } - if ps := cq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (cq *CardQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(cq.driver.Dialect()) - t1 := builder.Table(card.Table) - columns := cq.fields - if len(columns) == 0 { - columns = card.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if cq.sql != nil { - selector = cq.sql - selector.Select(selector.Columns(columns...)...) - } - for _, p := range cq.predicates { - p(selector) - } - for _, p := range cq.order { - p(selector) - } - if offset := cq.offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := cq.limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// CardGroupBy is the group-by builder for Card entities. -type CardGroupBy struct { - config - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (cgb *CardGroupBy) Aggregate(fns ...AggregateFunc) *CardGroupBy { - cgb.fns = append(cgb.fns, fns...) - return cgb -} - -// Scan applies the group-by query and scans the result into the given value. -func (cgb *CardGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := cgb.path(ctx) - if err != nil { - return err - } - cgb.sql = query - return cgb.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (cgb *CardGroupBy) ScanX(ctx context.Context, v interface{}) { - if err := cgb.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CardGroupBy) Strings(ctx context.Context) ([]string, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CardGroupBy.Strings is not achievable when grouping more than 1 field") - } - var v []string - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (cgb *CardGroupBy) StringsX(ctx context.Context) []string { - v, err := cgb.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CardGroupBy) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = cgb.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{card.Label} - default: - err = fmt.Errorf("ent: CardGroupBy.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (cgb *CardGroupBy) StringX(ctx context.Context) string { - v, err := cgb.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CardGroupBy) Ints(ctx context.Context) ([]int, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CardGroupBy.Ints is not achievable when grouping more than 1 field") - } - var v []int - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (cgb *CardGroupBy) IntsX(ctx context.Context) []int { - v, err := cgb.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CardGroupBy) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = cgb.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{card.Label} - default: - err = fmt.Errorf("ent: CardGroupBy.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (cgb *CardGroupBy) IntX(ctx context.Context) int { - v, err := cgb.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CardGroupBy) Float64s(ctx context.Context) ([]float64, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CardGroupBy.Float64s is not achievable when grouping more than 1 field") - } - var v []float64 - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (cgb *CardGroupBy) Float64sX(ctx context.Context) []float64 { - v, err := cgb.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CardGroupBy) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = cgb.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{card.Label} - default: - err = fmt.Errorf("ent: CardGroupBy.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (cgb *CardGroupBy) Float64X(ctx context.Context) float64 { - v, err := cgb.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CardGroupBy) Bools(ctx context.Context) ([]bool, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CardGroupBy.Bools is not achievable when grouping more than 1 field") - } - var v []bool - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (cgb *CardGroupBy) BoolsX(ctx context.Context) []bool { - v, err := cgb.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CardGroupBy) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = cgb.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{card.Label} - default: - err = fmt.Errorf("ent: CardGroupBy.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (cgb *CardGroupBy) BoolX(ctx context.Context) bool { - v, err := cgb.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (cgb *CardGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range cgb.fields { - if !card.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := cgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := cgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (cgb *CardGroupBy) sqlQuery() *sql.Selector { - selector := cgb.sql.Select() - aggregation := make([]string, 0, len(cgb.fns)) - for _, fn := range cgb.fns { - aggregation = append(aggregation, fn(selector)) - } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(cgb.fields)+len(cgb.fns)) - for _, f := range cgb.fields { - columns = append(columns, selector.C(f)) - } - for _, c := range aggregation { - columns = append(columns, c) - } - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(cgb.fields...)...) -} - -// CardSelect is the builder for selecting fields of Card entities. -type CardSelect struct { - *CardQuery - // intermediate query (i.e. traversal path). - sql *sql.Selector -} - -// Scan applies the selector query and scans the result into the given value. -func (cs *CardSelect) Scan(ctx context.Context, v interface{}) error { - if err := cs.prepareQuery(ctx); err != nil { - return err - } - cs.sql = cs.CardQuery.sqlQuery(ctx) - return cs.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (cs *CardSelect) ScanX(ctx context.Context, v interface{}) { - if err := cs.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from a selector. It is only allowed when selecting one field. -func (cs *CardSelect) Strings(ctx context.Context) ([]string, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CardSelect.Strings is not achievable when selecting more than 1 field") - } - var v []string - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (cs *CardSelect) StringsX(ctx context.Context) []string { - v, err := cs.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a selector. It is only allowed when selecting one field. -func (cs *CardSelect) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = cs.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{card.Label} - default: - err = fmt.Errorf("ent: CardSelect.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (cs *CardSelect) StringX(ctx context.Context) string { - v, err := cs.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from a selector. It is only allowed when selecting one field. -func (cs *CardSelect) Ints(ctx context.Context) ([]int, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CardSelect.Ints is not achievable when selecting more than 1 field") - } - var v []int - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (cs *CardSelect) IntsX(ctx context.Context) []int { - v, err := cs.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a selector. It is only allowed when selecting one field. -func (cs *CardSelect) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = cs.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{card.Label} - default: - err = fmt.Errorf("ent: CardSelect.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (cs *CardSelect) IntX(ctx context.Context) int { - v, err := cs.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. -func (cs *CardSelect) Float64s(ctx context.Context) ([]float64, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CardSelect.Float64s is not achievable when selecting more than 1 field") - } - var v []float64 - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (cs *CardSelect) Float64sX(ctx context.Context) []float64 { - v, err := cs.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. -func (cs *CardSelect) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = cs.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{card.Label} - default: - err = fmt.Errorf("ent: CardSelect.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (cs *CardSelect) Float64X(ctx context.Context) float64 { - v, err := cs.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from a selector. It is only allowed when selecting one field. -func (cs *CardSelect) Bools(ctx context.Context) ([]bool, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CardSelect.Bools is not achievable when selecting more than 1 field") - } - var v []bool - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (cs *CardSelect) BoolsX(ctx context.Context) []bool { - v, err := cs.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a selector. It is only allowed when selecting one field. -func (cs *CardSelect) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = cs.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{card.Label} - default: - err = fmt.Errorf("ent: CardSelect.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (cs *CardSelect) BoolX(ctx context.Context) bool { - v, err := cs.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (cs *CardSelect) sqlScan(ctx context.Context, v interface{}) error { - rows := &sql.Rows{} - query, args := cs.sql.Query() - if err := cs.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/examples/transaction/ent/internal/data/ent/card_update.go b/examples/transaction/ent/internal/data/ent/card_update.go deleted file mode 100644 index 05b7dcb91..000000000 --- a/examples/transaction/ent/internal/data/ent/card_update.go +++ /dev/null @@ -1,290 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/card" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/predicate" -) - -// CardUpdate is the builder for updating Card entities. -type CardUpdate struct { - config - hooks []Hook - mutation *CardMutation -} - -// Where appends a list predicates to the CardUpdate builder. -func (cu *CardUpdate) Where(ps ...predicate.Card) *CardUpdate { - cu.mutation.Where(ps...) - return cu -} - -// SetUserID sets the "user_id" field. -func (cu *CardUpdate) SetUserID(s string) *CardUpdate { - cu.mutation.SetUserID(s) - return cu -} - -// SetMoney sets the "money" field. -func (cu *CardUpdate) SetMoney(s string) *CardUpdate { - cu.mutation.SetMoney(s) - return cu -} - -// Mutation returns the CardMutation object of the builder. -func (cu *CardUpdate) Mutation() *CardMutation { - return cu.mutation -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (cu *CardUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(cu.hooks) == 0 { - affected, err = cu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CardMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - cu.mutation = mutation - affected, err = cu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(cu.hooks) - 1; i >= 0; i-- { - if cu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = cu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cu.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// SaveX is like Save, but panics if an error occurs. -func (cu *CardUpdate) SaveX(ctx context.Context) int { - affected, err := cu.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (cu *CardUpdate) Exec(ctx context.Context) error { - _, err := cu.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (cu *CardUpdate) ExecX(ctx context.Context) { - if err := cu.Exec(ctx); err != nil { - panic(err) - } -} - -func (cu *CardUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: card.Table, - Columns: card.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: card.FieldID, - }, - }, - } - if ps := cu.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := cu.mutation.UserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: card.FieldUserID, - }) - } - if value, ok := cu.mutation.Money(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: card.FieldMoney, - }) - } - if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{card.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - return 0, err - } - return n, nil -} - -// CardUpdateOne is the builder for updating a single Card entity. -type CardUpdateOne struct { - config - fields []string - hooks []Hook - mutation *CardMutation -} - -// SetUserID sets the "user_id" field. -func (cuo *CardUpdateOne) SetUserID(s string) *CardUpdateOne { - cuo.mutation.SetUserID(s) - return cuo -} - -// SetMoney sets the "money" field. -func (cuo *CardUpdateOne) SetMoney(s string) *CardUpdateOne { - cuo.mutation.SetMoney(s) - return cuo -} - -// Mutation returns the CardMutation object of the builder. -func (cuo *CardUpdateOne) Mutation() *CardMutation { - return cuo.mutation -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (cuo *CardUpdateOne) Select(field string, fields ...string) *CardUpdateOne { - cuo.fields = append([]string{field}, fields...) - return cuo -} - -// Save executes the query and returns the updated Card entity. -func (cuo *CardUpdateOne) Save(ctx context.Context) (*Card, error) { - var ( - err error - node *Card - ) - if len(cuo.hooks) == 0 { - node, err = cuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CardMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - cuo.mutation = mutation - node, err = cuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(cuo.hooks) - 1; i >= 0; i-- { - if cuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = cuo.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cuo.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX is like Save, but panics if an error occurs. -func (cuo *CardUpdateOne) SaveX(ctx context.Context) *Card { - node, err := cuo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (cuo *CardUpdateOne) Exec(ctx context.Context) error { - _, err := cuo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (cuo *CardUpdateOne) ExecX(ctx context.Context) { - if err := cuo.Exec(ctx); err != nil { - panic(err) - } -} - -func (cuo *CardUpdateOne) sqlSave(ctx context.Context) (_node *Card, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: card.Table, - Columns: card.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: card.FieldID, - }, - }, - } - id, ok := cuo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Card.ID for update")} - } - _spec.Node.ID.Value = id - if fields := cuo.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, card.FieldID) - for _, f := range fields { - if !card.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != card.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := cuo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := cuo.mutation.UserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: card.FieldUserID, - }) - } - if value, ok := cuo.mutation.Money(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: card.FieldMoney, - }) - } - _node = &Card{config: cuo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{card.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - return nil, err - } - return _node, nil -} diff --git a/examples/transaction/ent/internal/data/ent/client.go b/examples/transaction/ent/internal/data/ent/client.go deleted file mode 100644 index 8aa250505..000000000 --- a/examples/transaction/ent/internal/data/ent/client.go +++ /dev/null @@ -1,309 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "log" - - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/migrate" - - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/card" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/user" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" -) - -// Client is the client that holds all ent builders. -type Client struct { - config - // Schema is the client for creating, migrating and dropping schema. - Schema *migrate.Schema - // Card is the client for interacting with the Card builders. - Card *CardClient - // User is the client for interacting with the User builders. - User *UserClient -} - -// NewClient creates a new client configured with the given options. -func NewClient(opts ...Option) *Client { - cfg := config{log: log.Println, hooks: &hooks{}} - cfg.options(opts...) - client := &Client{config: cfg} - client.init() - return client -} - -func (c *Client) init() { - c.Schema = migrate.NewSchema(c.driver) - c.Card = NewCardClient(c.config) - c.User = NewUserClient(c.config) -} - -// Open opens a database/sql.DB specified by the driver name and -// the data source name, and returns a new client attached to it. -// Optional parameters can be added for configuring the client. -func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { - switch driverName { - case dialect.MySQL, dialect.Postgres, dialect.SQLite: - drv, err := sql.Open(driverName, dataSourceName) - if err != nil { - return nil, err - } - return NewClient(append(options, Driver(drv))...), nil - default: - return nil, fmt.Errorf("unsupported driver: %q", driverName) - } -} - -// Tx returns a new transactional client. The provided context -// is used until the transaction is committed or rolled back. -func (c *Client) Tx(ctx context.Context) (*Tx, error) { - if _, ok := c.driver.(*txDriver); ok { - return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") - } - tx, err := newTx(ctx, c.driver) - if err != nil { - return nil, fmt.Errorf("ent: starting a transaction: %w", err) - } - cfg := c.config - cfg.driver = tx - return &Tx{ - ctx: ctx, - config: cfg, - Card: NewCardClient(cfg), - User: NewUserClient(cfg), - }, nil -} - -// BeginTx returns a transactional client with specified options. -func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { - if _, ok := c.driver.(*txDriver); ok { - return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") - } - tx, err := c.driver.(interface { - BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) - }).BeginTx(ctx, opts) - if err != nil { - return nil, fmt.Errorf("ent: starting a transaction: %w", err) - } - cfg := c.config - cfg.driver = &txDriver{tx: tx, drv: c.driver} - return &Tx{ - config: cfg, - Card: NewCardClient(cfg), - User: NewUserClient(cfg), - }, nil -} - -// Debug returns a new debug-client. It's used to get verbose logging on specific operations. -// -// client.Debug(). -// Card. -// Query(). -// Count(ctx) -// -func (c *Client) Debug() *Client { - if c.debug { - return c - } - cfg := c.config - cfg.driver = dialect.Debug(c.driver, c.log) - client := &Client{config: cfg} - client.init() - return client -} - -// Close closes the database connection and prevents new queries from starting. -func (c *Client) Close() error { - return c.driver.Close() -} - -// Use adds the mutation hooks to all the entity clients. -// In order to add hooks to a specific client, call: `client.Node.Use(...)`. -func (c *Client) Use(hooks ...Hook) { - c.Card.Use(hooks...) - c.User.Use(hooks...) -} - -// CardClient is a client for the Card schema. -type CardClient struct { - config -} - -// NewCardClient returns a client for the Card from the given config. -func NewCardClient(c config) *CardClient { - return &CardClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `card.Hooks(f(g(h())))`. -func (c *CardClient) Use(hooks ...Hook) { - c.hooks.Card = append(c.hooks.Card, hooks...) -} - -// Create returns a create builder for Card. -func (c *CardClient) Create() *CardCreate { - mutation := newCardMutation(c.config, OpCreate) - return &CardCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of Card entities. -func (c *CardClient) CreateBulk(builders ...*CardCreate) *CardCreateBulk { - return &CardCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for Card. -func (c *CardClient) Update() *CardUpdate { - mutation := newCardMutation(c.config, OpUpdate) - return &CardUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *CardClient) UpdateOne(ca *Card) *CardUpdateOne { - mutation := newCardMutation(c.config, OpUpdateOne, withCard(ca)) - return &CardUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *CardClient) UpdateOneID(id int) *CardUpdateOne { - mutation := newCardMutation(c.config, OpUpdateOne, withCardID(id)) - return &CardUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for Card. -func (c *CardClient) Delete() *CardDelete { - mutation := newCardMutation(c.config, OpDelete) - return &CardDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a delete builder for the given entity. -func (c *CardClient) DeleteOne(ca *Card) *CardDeleteOne { - return c.DeleteOneID(ca.ID) -} - -// DeleteOneID returns a delete builder for the given id. -func (c *CardClient) DeleteOneID(id int) *CardDeleteOne { - builder := c.Delete().Where(card.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &CardDeleteOne{builder} -} - -// Query returns a query builder for Card. -func (c *CardClient) Query() *CardQuery { - return &CardQuery{ - config: c.config, - } -} - -// Get returns a Card entity by its id. -func (c *CardClient) Get(ctx context.Context, id int) (*Card, error) { - return c.Query().Where(card.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *CardClient) GetX(ctx context.Context, id int) *Card { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// Hooks returns the client hooks. -func (c *CardClient) Hooks() []Hook { - return c.hooks.Card -} - -// UserClient is a client for the User schema. -type UserClient struct { - config -} - -// NewUserClient returns a client for the User from the given config. -func NewUserClient(c config) *UserClient { - return &UserClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`. -func (c *UserClient) Use(hooks ...Hook) { - c.hooks.User = append(c.hooks.User, hooks...) -} - -// Create returns a create builder for User. -func (c *UserClient) Create() *UserCreate { - mutation := newUserMutation(c.config, OpCreate) - return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of User entities. -func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { - return &UserCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for User. -func (c *UserClient) Update() *UserUpdate { - mutation := newUserMutation(c.config, OpUpdate) - return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *UserClient) UpdateOne(u *User) *UserUpdateOne { - mutation := newUserMutation(c.config, OpUpdateOne, withUser(u)) - return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *UserClient) UpdateOneID(id int) *UserUpdateOne { - mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id)) - return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for User. -func (c *UserClient) Delete() *UserDelete { - mutation := newUserMutation(c.config, OpDelete) - return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a delete builder for the given entity. -func (c *UserClient) DeleteOne(u *User) *UserDeleteOne { - return c.DeleteOneID(u.ID) -} - -// DeleteOneID returns a delete builder for the given id. -func (c *UserClient) DeleteOneID(id int) *UserDeleteOne { - builder := c.Delete().Where(user.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &UserDeleteOne{builder} -} - -// Query returns a query builder for User. -func (c *UserClient) Query() *UserQuery { - return &UserQuery{ - config: c.config, - } -} - -// Get returns a User entity by its id. -func (c *UserClient) Get(ctx context.Context, id int) (*User, error) { - return c.Query().Where(user.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *UserClient) GetX(ctx context.Context, id int) *User { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// Hooks returns the client hooks. -func (c *UserClient) Hooks() []Hook { - return c.hooks.User -} diff --git a/examples/transaction/ent/internal/data/ent/config.go b/examples/transaction/ent/internal/data/ent/config.go deleted file mode 100644 index d563b1964..000000000 --- a/examples/transaction/ent/internal/data/ent/config.go +++ /dev/null @@ -1,60 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...interface{}) - // hooks to execute on mutations. - hooks *hooks -} - -// hooks per client, for fast access. -type hooks struct { - Card []ent.Hook - User []ent.Hook -} - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...interface{})) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/examples/transaction/ent/internal/data/ent/context.go b/examples/transaction/ent/internal/data/ent/context.go deleted file mode 100644 index 08407261b..000000000 --- a/examples/transaction/ent/internal/data/ent/context.go +++ /dev/null @@ -1,33 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" -) - -type clientCtxKey struct{} - -// FromContext returns a Client stored inside a context, or nil if there isn't one. -func FromContext(ctx context.Context) *Client { - c, _ := ctx.Value(clientCtxKey{}).(*Client) - return c -} - -// NewContext returns a new context with the given Client attached. -func NewContext(parent context.Context, c *Client) context.Context { - return context.WithValue(parent, clientCtxKey{}, c) -} - -type txCtxKey struct{} - -// TxFromContext returns a Tx stored inside a context, or nil if there isn't one. -func TxFromContext(ctx context.Context) *Tx { - tx, _ := ctx.Value(txCtxKey{}).(*Tx) - return tx -} - -// NewTxContext returns a new context with the given Tx attached. -func NewTxContext(parent context.Context, tx *Tx) context.Context { - return context.WithValue(parent, txCtxKey{}, tx) -} diff --git a/examples/transaction/ent/internal/data/ent/ent.go b/examples/transaction/ent/internal/data/ent/ent.go deleted file mode 100644 index f74a90774..000000000 --- a/examples/transaction/ent/internal/data/ent/ent.go +++ /dev/null @@ -1,261 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "errors" - "fmt" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/card" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/user" -) - -// ent aliases to avoid import conflicts in user's code. -type ( - Op = ent.Op - Hook = ent.Hook - Value = ent.Value - Query = ent.Query - Policy = ent.Policy - Mutator = ent.Mutator - Mutation = ent.Mutation - MutateFunc = ent.MutateFunc -) - -// OrderFunc applies an ordering on the sql selector. -type OrderFunc func(*sql.Selector) - -// columnChecker returns a function indicates if the column exists in the given column. -func columnChecker(table string) func(string) error { - checks := map[string]func(string) bool{ - card.Table: card.ValidColumn, - user.Table: user.ValidColumn, - } - check, ok := checks[table] - if !ok { - return func(string) error { - return fmt.Errorf("unknown table %q", table) - } - } - return func(column string) error { - if !check(column) { - return fmt.Errorf("unknown column %q for table %q", column, table) - } - return nil - } -} - -// Asc applies the given fields in ASC order. -func Asc(fields ...string) OrderFunc { - return func(s *sql.Selector) { - check := columnChecker(s.TableName()) - for _, f := range fields { - if err := check(f); err != nil { - s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) - } - s.OrderBy(sql.Asc(s.C(f))) - } - } -} - -// Desc applies the given fields in DESC order. -func Desc(fields ...string) OrderFunc { - return func(s *sql.Selector) { - check := columnChecker(s.TableName()) - for _, f := range fields { - if err := check(f); err != nil { - s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) - } - s.OrderBy(sql.Desc(s.C(f))) - } - } -} - -// AggregateFunc applies an aggregation step on the group-by traversal/selector. -type AggregateFunc func(*sql.Selector) string - -// As is a pseudo aggregation function for renaming another other functions with custom names. For example: -// -// GroupBy(field1, field2). -// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")). -// Scan(ctx, &v) -// -func As(fn AggregateFunc, end string) AggregateFunc { - return func(s *sql.Selector) string { - return sql.As(fn(s), end) - } -} - -// Count applies the "count" aggregation function on each group. -func Count() AggregateFunc { - return func(s *sql.Selector) string { - return sql.Count("*") - } -} - -// Max applies the "max" aggregation function on the given field of each group. -func Max(field string) AggregateFunc { - return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Max(s.C(field)) - } -} - -// Mean applies the "mean" aggregation function on the given field of each group. -func Mean(field string) AggregateFunc { - return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Avg(s.C(field)) - } -} - -// Min applies the "min" aggregation function on the given field of each group. -func Min(field string) AggregateFunc { - return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Min(s.C(field)) - } -} - -// Sum applies the "sum" aggregation function on the given field of each group. -func Sum(field string) AggregateFunc { - return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Sum(s.C(field)) - } -} - -// ValidationError returns when validating a field fails. -type ValidationError struct { - Name string // Field or edge name. - err error -} - -// Error implements the error interface. -func (e *ValidationError) Error() string { - return e.err.Error() -} - -// Unwrap implements the errors.Wrapper interface. -func (e *ValidationError) Unwrap() error { - return e.err -} - -// IsValidationError returns a boolean indicating whether the error is a validation error. -func IsValidationError(err error) bool { - if err == nil { - return false - } - var e *ValidationError - return errors.As(err, &e) -} - -// NotFoundError returns when trying to fetch a specific entity and it was not found in the database. -type NotFoundError struct { - label string -} - -// Error implements the error interface. -func (e *NotFoundError) Error() string { - return "ent: " + e.label + " not found" -} - -// IsNotFound returns a boolean indicating whether the error is a not found error. -func IsNotFound(err error) bool { - if err == nil { - return false - } - var e *NotFoundError - return errors.As(err, &e) -} - -// MaskNotFound masks not found error. -func MaskNotFound(err error) error { - if IsNotFound(err) { - return nil - } - return err -} - -// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database. -type NotSingularError struct { - label string -} - -// Error implements the error interface. -func (e *NotSingularError) Error() string { - return "ent: " + e.label + " not singular" -} - -// IsNotSingular returns a boolean indicating whether the error is a not singular error. -func IsNotSingular(err error) bool { - if err == nil { - return false - } - var e *NotSingularError - return errors.As(err, &e) -} - -// NotLoadedError returns when trying to get a node that was not loaded by the query. -type NotLoadedError struct { - edge string -} - -// Error implements the error interface. -func (e *NotLoadedError) Error() string { - return "ent: " + e.edge + " edge was not loaded" -} - -// IsNotLoaded returns a boolean indicating whether the error is a not loaded error. -func IsNotLoaded(err error) bool { - if err == nil { - return false - } - var e *NotLoadedError - return errors.As(err, &e) -} - -// ConstraintError returns when trying to create/update one or more entities and -// one or more of their constraints failed. For example, violation of edge or -// field uniqueness. -type ConstraintError struct { - msg string - wrap error -} - -// Error implements the error interface. -func (e ConstraintError) Error() string { - return "ent: constraint failed: " + e.msg -} - -// Unwrap implements the errors.Wrapper interface. -func (e *ConstraintError) Unwrap() error { - return e.wrap -} - -// IsConstraintError returns a boolean indicating whether the error is a constraint failure. -func IsConstraintError(err error) bool { - if err == nil { - return false - } - var e *ConstraintError - return errors.As(err, &e) -} diff --git a/examples/transaction/ent/internal/data/ent/enttest/enttest.go b/examples/transaction/ent/internal/data/ent/enttest/enttest.go deleted file mode 100644 index 6c444ad9c..000000000 --- a/examples/transaction/ent/internal/data/ent/enttest/enttest.go +++ /dev/null @@ -1,78 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package enttest - -import ( - "context" - - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent" - // required by schema hooks. - _ "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/runtime" - - "entgo.io/ent/dialect/sql/schema" -) - -type ( - // TestingT is the interface that is shared between - // testing.T and testing.B and used by enttest. - TestingT interface { - FailNow() - Error(...interface{}) - } - - // Option configures client creation. - Option func(*options) - - options struct { - opts []ent.Option - migrateOpts []schema.MigrateOption - } -) - -// WithOptions forwards options to client creation. -func WithOptions(opts ...ent.Option) Option { - return func(o *options) { - o.opts = append(o.opts, opts...) - } -} - -// WithMigrateOptions forwards options to auto migration. -func WithMigrateOptions(opts ...schema.MigrateOption) Option { - return func(o *options) { - o.migrateOpts = append(o.migrateOpts, opts...) - } -} - -func newOptions(opts []Option) *options { - o := &options{} - for _, opt := range opts { - opt(o) - } - return o -} - -// Open calls ent.Open and auto-run migration. -func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client { - o := newOptions(opts) - c, err := ent.Open(driverName, dataSourceName, o.opts...) - if err != nil { - t.Error(err) - t.FailNow() - } - if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { - t.Error(err) - t.FailNow() - } - return c -} - -// NewClient calls ent.NewClient and auto-run migration. -func NewClient(t TestingT, opts ...Option) *ent.Client { - o := newOptions(opts) - c := ent.NewClient(o.opts...) - if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { - t.Error(err) - t.FailNow() - } - return c -} diff --git a/examples/transaction/ent/internal/data/ent/generate.go b/examples/transaction/ent/internal/data/ent/generate.go deleted file mode 100644 index 8d3fdfdc1..000000000 --- a/examples/transaction/ent/internal/data/ent/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package ent - -//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate ./schema diff --git a/examples/transaction/ent/internal/data/ent/hook/hook.go b/examples/transaction/ent/internal/data/ent/hook/hook.go deleted file mode 100644 index 36899e228..000000000 --- a/examples/transaction/ent/internal/data/ent/hook/hook.go +++ /dev/null @@ -1,217 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package hook - -import ( - "context" - "fmt" - - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent" -) - -// The CardFunc type is an adapter to allow the use of ordinary -// function as Card mutator. -type CardFunc func(context.Context, *ent.CardMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f CardFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.CardMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CardMutation", m) - } - return f(ctx, mv) -} - -// The UserFunc type is an adapter to allow the use of ordinary -// function as User mutator. -type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m) - } - return f(ctx, mv) -} - -// Condition is a hook condition function. -type Condition func(context.Context, ent.Mutation) bool - -// And groups conditions with the AND operator. -func And(first, second Condition, rest ...Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - if !first(ctx, m) || !second(ctx, m) { - return false - } - for _, cond := range rest { - if !cond(ctx, m) { - return false - } - } - return true - } -} - -// Or groups conditions with the OR operator. -func Or(first, second Condition, rest ...Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - if first(ctx, m) || second(ctx, m) { - return true - } - for _, cond := range rest { - if cond(ctx, m) { - return true - } - } - return false - } -} - -// Not negates a given condition. -func Not(cond Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - return !cond(ctx, m) - } -} - -// HasOp is a condition testing mutation operation. -func HasOp(op ent.Op) Condition { - return func(_ context.Context, m ent.Mutation) bool { - return m.Op().Is(op) - } -} - -// HasAddedFields is a condition validating `.AddedField` on fields. -func HasAddedFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if _, exists := m.AddedField(field); !exists { - return false - } - for _, field := range fields { - if _, exists := m.AddedField(field); !exists { - return false - } - } - return true - } -} - -// HasClearedFields is a condition validating `.FieldCleared` on fields. -func HasClearedFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if exists := m.FieldCleared(field); !exists { - return false - } - for _, field := range fields { - if exists := m.FieldCleared(field); !exists { - return false - } - } - return true - } -} - -// HasFields is a condition validating `.Field` on fields. -func HasFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if _, exists := m.Field(field); !exists { - return false - } - for _, field := range fields { - if _, exists := m.Field(field); !exists { - return false - } - } - return true - } -} - -// If executes the given hook under condition. -// -// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...))) -// -func If(hk ent.Hook, cond Condition) ent.Hook { - return func(next ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if cond(ctx, m) { - return hk(next).Mutate(ctx, m) - } - return next.Mutate(ctx, m) - }) - } -} - -// On executes the given hook only for the given operation. -// -// hook.On(Log, ent.Delete|ent.Create) -// -func On(hk ent.Hook, op ent.Op) ent.Hook { - return If(hk, HasOp(op)) -} - -// Unless skips the given hook only for the given operation. -// -// hook.Unless(Log, ent.Update|ent.UpdateOne) -// -func Unless(hk ent.Hook, op ent.Op) ent.Hook { - return If(hk, Not(HasOp(op))) -} - -// FixedError is a hook returning a fixed error. -func FixedError(err error) ent.Hook { - return func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { - return nil, err - }) - } -} - -// Reject returns a hook that rejects all operations that match op. -// -// func (T) Hooks() []ent.Hook { -// return []ent.Hook{ -// Reject(ent.Delete|ent.Update), -// } -// } -// -func Reject(op ent.Op) ent.Hook { - hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) - return On(hk, op) -} - -// Chain acts as a list of hooks and is effectively immutable. -// Once created, it will always hold the same set of hooks in the same order. -type Chain struct { - hooks []ent.Hook -} - -// NewChain creates a new chain of hooks. -func NewChain(hooks ...ent.Hook) Chain { - return Chain{append([]ent.Hook(nil), hooks...)} -} - -// Hook chains the list of hooks and returns the final hook. -func (c Chain) Hook() ent.Hook { - return func(mutator ent.Mutator) ent.Mutator { - for i := len(c.hooks) - 1; i >= 0; i-- { - mutator = c.hooks[i](mutator) - } - return mutator - } -} - -// Append extends a chain, adding the specified hook -// as the last ones in the mutation flow. -func (c Chain) Append(hooks ...ent.Hook) Chain { - newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks)) - newHooks = append(newHooks, c.hooks...) - newHooks = append(newHooks, hooks...) - return Chain{newHooks} -} - -// Extend extends a chain, adding the specified chain -// as the last ones in the mutation flow. -func (c Chain) Extend(chain Chain) Chain { - return c.Append(chain.hooks...) -} diff --git a/examples/transaction/ent/internal/data/ent/migrate/migrate.go b/examples/transaction/ent/internal/data/ent/migrate/migrate.go deleted file mode 100644 index e4a9a2218..000000000 --- a/examples/transaction/ent/internal/data/ent/migrate/migrate.go +++ /dev/null @@ -1,72 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package migrate - -import ( - "context" - "fmt" - "io" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql/schema" -) - -var ( - // WithGlobalUniqueID sets the universal ids options to the migration. - // If this option is enabled, ent migration will allocate a 1<<32 range - // for the ids of each entity (table). - // Note that this option cannot be applied on tables that already exist. - WithGlobalUniqueID = schema.WithGlobalUniqueID - // WithDropColumn sets the drop column option to the migration. - // If this option is enabled, ent migration will drop old columns - // that were used for both fields and edges. This defaults to false. - WithDropColumn = schema.WithDropColumn - // WithDropIndex sets the drop index option to the migration. - // If this option is enabled, ent migration will drop old indexes - // that were defined in the schema. This defaults to false. - // Note that unique constraints are defined using `UNIQUE INDEX`, - // and therefore, it's recommended to enable this option to get more - // flexibility in the schema changes. - WithDropIndex = schema.WithDropIndex - // WithFixture sets the foreign-key renaming option to the migration when upgrading - // ent from v0.1.0 (issue-#285). Defaults to false. - WithFixture = schema.WithFixture - // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. - WithForeignKeys = schema.WithForeignKeys -) - -// Schema is the API for creating, migrating and dropping a schema. -type Schema struct { - drv dialect.Driver - universalID bool -} - -// NewSchema creates a new schema client. -func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } - -// Create creates all schema resources. -func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { - migrate, err := schema.NewMigrate(s.drv, opts...) - if err != nil { - return fmt.Errorf("ent/migrate: %w", err) - } - return migrate.Create(ctx, Tables...) -} - -// WriteTo writes the schema changes to w instead of running them against the database. -// -// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil { -// log.Fatal(err) -// } -// -func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { - drv := &schema.WriteDriver{ - Writer: w, - Driver: s.drv, - } - migrate, err := schema.NewMigrate(drv, opts...) - if err != nil { - return fmt.Errorf("ent/migrate: %w", err) - } - return migrate.Create(ctx, Tables...) -} diff --git a/examples/transaction/ent/internal/data/ent/migrate/schema.go b/examples/transaction/ent/internal/data/ent/migrate/schema.go deleted file mode 100644 index f03a4ece0..000000000 --- a/examples/transaction/ent/internal/data/ent/migrate/schema.go +++ /dev/null @@ -1,43 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package migrate - -import ( - "entgo.io/ent/dialect/sql/schema" - "entgo.io/ent/schema/field" -) - -var ( - // CardsColumns holds the columns for the "cards" table. - CardsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "user_id", Type: field.TypeString}, - {Name: "money", Type: field.TypeString}, - } - // CardsTable holds the schema information for the "cards" table. - CardsTable = &schema.Table{ - Name: "cards", - Columns: CardsColumns, - PrimaryKey: []*schema.Column{CardsColumns[0]}, - } - // UsersColumns holds the columns for the "users" table. - UsersColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "name", Type: field.TypeString, Default: ""}, - {Name: "email", Type: field.TypeString, Default: ""}, - } - // UsersTable holds the schema information for the "users" table. - UsersTable = &schema.Table{ - Name: "users", - Columns: UsersColumns, - PrimaryKey: []*schema.Column{UsersColumns[0]}, - } - // Tables holds all the tables in the schema. - Tables = []*schema.Table{ - CardsTable, - UsersTable, - } -) - -func init() { -} diff --git a/examples/transaction/ent/internal/data/ent/mutation.go b/examples/transaction/ent/internal/data/ent/mutation.go deleted file mode 100644 index 1b10a752b..000000000 --- a/examples/transaction/ent/internal/data/ent/mutation.go +++ /dev/null @@ -1,732 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "sync" - - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/card" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/predicate" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/user" - - "entgo.io/ent" -) - -const ( - // Operation types. - OpCreate = ent.OpCreate - OpDelete = ent.OpDelete - OpDeleteOne = ent.OpDeleteOne - OpUpdate = ent.OpUpdate - OpUpdateOne = ent.OpUpdateOne - - // Node types. - TypeCard = "Card" - TypeUser = "User" -) - -// CardMutation represents an operation that mutates the Card nodes in the graph. -type CardMutation struct { - config - op Op - typ string - id *int - user_id *string - money *string - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*Card, error) - predicates []predicate.Card -} - -var _ ent.Mutation = (*CardMutation)(nil) - -// cardOption allows management of the mutation configuration using functional options. -type cardOption func(*CardMutation) - -// newCardMutation creates new mutation for the Card entity. -func newCardMutation(c config, op Op, opts ...cardOption) *CardMutation { - m := &CardMutation{ - config: c, - op: op, - typ: TypeCard, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withCardID sets the ID field of the mutation. -func withCardID(id int) cardOption { - return func(m *CardMutation) { - var ( - err error - once sync.Once - value *Card - ) - m.oldValue = func(ctx context.Context) (*Card, error) { - once.Do(func() { - if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") - } else { - value, err = m.Client().Card.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withCard sets the old Card of the mutation. -func withCard(node *Card) cardOption { - return func(m *CardMutation) { - m.oldValue = func(context.Context) (*Card, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m CardMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m CardMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of Card entities. -func (m *CardMutation) SetID(id int) { - m.id = &id -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *CardMutation) ID() (id int, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// SetUserID sets the "user_id" field. -func (m *CardMutation) SetUserID(s string) { - m.user_id = &s -} - -// UserID returns the value of the "user_id" field in the mutation. -func (m *CardMutation) UserID() (r string, exists bool) { - v := m.user_id - if v == nil { - return - } - return *v, true -} - -// OldUserID returns the old "user_id" field's value of the Card entity. -// If the Card object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *CardMutation) OldUserID(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUserID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUserID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUserID: %w", err) - } - return oldValue.UserID, nil -} - -// ResetUserID resets all changes to the "user_id" field. -func (m *CardMutation) ResetUserID() { - m.user_id = nil -} - -// SetMoney sets the "money" field. -func (m *CardMutation) SetMoney(s string) { - m.money = &s -} - -// Money returns the value of the "money" field in the mutation. -func (m *CardMutation) Money() (r string, exists bool) { - v := m.money - if v == nil { - return - } - return *v, true -} - -// OldMoney returns the old "money" field's value of the Card entity. -// If the Card object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *CardMutation) OldMoney(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMoney is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldMoney requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldMoney: %w", err) - } - return oldValue.Money, nil -} - -// ResetMoney resets all changes to the "money" field. -func (m *CardMutation) ResetMoney() { - m.money = nil -} - -// Where appends a list predicates to the CardMutation builder. -func (m *CardMutation) Where(ps ...predicate.Card) { - m.predicates = append(m.predicates, ps...) -} - -// Op returns the operation name. -func (m *CardMutation) Op() Op { - return m.op -} - -// Type returns the node type of this mutation (Card). -func (m *CardMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *CardMutation) Fields() []string { - fields := make([]string, 0, 2) - if m.user_id != nil { - fields = append(fields, card.FieldUserID) - } - if m.money != nil { - fields = append(fields, card.FieldMoney) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *CardMutation) Field(name string) (ent.Value, bool) { - switch name { - case card.FieldUserID: - return m.UserID() - case card.FieldMoney: - return m.Money() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *CardMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case card.FieldUserID: - return m.OldUserID(ctx) - case card.FieldMoney: - return m.OldMoney(ctx) - } - return nil, fmt.Errorf("unknown Card field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *CardMutation) SetField(name string, value ent.Value) error { - switch name { - case card.FieldUserID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUserID(v) - return nil - case card.FieldMoney: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetMoney(v) - return nil - } - return fmt.Errorf("unknown Card field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *CardMutation) AddedFields() []string { - return nil -} - -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *CardMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *CardMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown Card numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *CardMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *CardMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *CardMutation) ClearField(name string) error { - return fmt.Errorf("unknown Card nullable field %s", name) -} - -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *CardMutation) ResetField(name string) error { - switch name { - case card.FieldUserID: - m.ResetUserID() - return nil - case card.FieldMoney: - m.ResetMoney() - return nil - } - return fmt.Errorf("unknown Card field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *CardMutation) AddedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *CardMutation) AddedIDs(name string) []ent.Value { - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *CardMutation) RemovedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *CardMutation) RemovedIDs(name string) []ent.Value { - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *CardMutation) ClearedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *CardMutation) EdgeCleared(name string) bool { - return false -} - -// ClearEdge clears the value of the edge with the given name. It returns an error -// if that edge is not defined in the schema. -func (m *CardMutation) ClearEdge(name string) error { - return fmt.Errorf("unknown Card unique edge %s", name) -} - -// ResetEdge resets all changes to the edge with the given name in this mutation. -// It returns an error if the edge is not defined in the schema. -func (m *CardMutation) ResetEdge(name string) error { - return fmt.Errorf("unknown Card edge %s", name) -} - -// UserMutation represents an operation that mutates the User nodes in the graph. -type UserMutation struct { - config - op Op - typ string - id *int - name *string - email *string - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*User, error) - predicates []predicate.User -} - -var _ ent.Mutation = (*UserMutation)(nil) - -// userOption allows management of the mutation configuration using functional options. -type userOption func(*UserMutation) - -// newUserMutation creates new mutation for the User entity. -func newUserMutation(c config, op Op, opts ...userOption) *UserMutation { - m := &UserMutation{ - config: c, - op: op, - typ: TypeUser, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withUserID sets the ID field of the mutation. -func withUserID(id int) userOption { - return func(m *UserMutation) { - var ( - err error - once sync.Once - value *User - ) - m.oldValue = func(ctx context.Context) (*User, error) { - once.Do(func() { - if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") - } else { - value, err = m.Client().User.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withUser sets the old User of the mutation. -func withUser(node *User) userOption { - return func(m *UserMutation) { - m.oldValue = func(context.Context) (*User, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m UserMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m UserMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of User entities. -func (m *UserMutation) SetID(id int) { - m.id = &id -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *UserMutation) ID() (id int, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// SetName sets the "name" field. -func (m *UserMutation) SetName(s string) { - m.name = &s -} - -// Name returns the value of the "name" field in the mutation. -func (m *UserMutation) Name() (r string, exists bool) { - v := m.name - if v == nil { - return - } - return *v, true -} - -// OldName returns the old "name" field's value of the User entity. -// If the User object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *UserMutation) OldName(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldName is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldName requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldName: %w", err) - } - return oldValue.Name, nil -} - -// ResetName resets all changes to the "name" field. -func (m *UserMutation) ResetName() { - m.name = nil -} - -// SetEmail sets the "email" field. -func (m *UserMutation) SetEmail(s string) { - m.email = &s -} - -// Email returns the value of the "email" field in the mutation. -func (m *UserMutation) Email() (r string, exists bool) { - v := m.email - if v == nil { - return - } - return *v, true -} - -// OldEmail returns the old "email" field's value of the User entity. -// If the User object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *UserMutation) OldEmail(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldEmail is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldEmail requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldEmail: %w", err) - } - return oldValue.Email, nil -} - -// ResetEmail resets all changes to the "email" field. -func (m *UserMutation) ResetEmail() { - m.email = nil -} - -// Where appends a list predicates to the UserMutation builder. -func (m *UserMutation) Where(ps ...predicate.User) { - m.predicates = append(m.predicates, ps...) -} - -// Op returns the operation name. -func (m *UserMutation) Op() Op { - return m.op -} - -// Type returns the node type of this mutation (User). -func (m *UserMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *UserMutation) Fields() []string { - fields := make([]string, 0, 2) - if m.name != nil { - fields = append(fields, user.FieldName) - } - if m.email != nil { - fields = append(fields, user.FieldEmail) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *UserMutation) Field(name string) (ent.Value, bool) { - switch name { - case user.FieldName: - return m.Name() - case user.FieldEmail: - return m.Email() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case user.FieldName: - return m.OldName(ctx) - case user.FieldEmail: - return m.OldEmail(ctx) - } - return nil, fmt.Errorf("unknown User field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *UserMutation) SetField(name string, value ent.Value) error { - switch name { - case user.FieldName: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetName(v) - return nil - case user.FieldEmail: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetEmail(v) - return nil - } - return fmt.Errorf("unknown User field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *UserMutation) AddedFields() []string { - return nil -} - -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *UserMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *UserMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown User numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *UserMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *UserMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *UserMutation) ClearField(name string) error { - return fmt.Errorf("unknown User nullable field %s", name) -} - -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *UserMutation) ResetField(name string) error { - switch name { - case user.FieldName: - m.ResetName() - return nil - case user.FieldEmail: - m.ResetEmail() - return nil - } - return fmt.Errorf("unknown User field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *UserMutation) AddedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *UserMutation) AddedIDs(name string) []ent.Value { - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *UserMutation) RemovedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *UserMutation) RemovedIDs(name string) []ent.Value { - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *UserMutation) ClearedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *UserMutation) EdgeCleared(name string) bool { - return false -} - -// ClearEdge clears the value of the edge with the given name. It returns an error -// if that edge is not defined in the schema. -func (m *UserMutation) ClearEdge(name string) error { - return fmt.Errorf("unknown User unique edge %s", name) -} - -// ResetEdge resets all changes to the edge with the given name in this mutation. -// It returns an error if the edge is not defined in the schema. -func (m *UserMutation) ResetEdge(name string) error { - return fmt.Errorf("unknown User edge %s", name) -} diff --git a/examples/transaction/ent/internal/data/ent/predicate/predicate.go b/examples/transaction/ent/internal/data/ent/predicate/predicate.go deleted file mode 100644 index c6c7f7b41..000000000 --- a/examples/transaction/ent/internal/data/ent/predicate/predicate.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package predicate - -import ( - "entgo.io/ent/dialect/sql" -) - -// Card is the predicate function for card builders. -type Card func(*sql.Selector) - -// User is the predicate function for user builders. -type User func(*sql.Selector) diff --git a/examples/transaction/ent/internal/data/ent/runtime.go b/examples/transaction/ent/internal/data/ent/runtime.go deleted file mode 100644 index e6633e8e8..000000000 --- a/examples/transaction/ent/internal/data/ent/runtime.go +++ /dev/null @@ -1,24 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/schema" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/user" -) - -// The init function reads all schema descriptors with runtime code -// (default values, validators, hooks and policies) and stitches it -// to their package variables. -func init() { - userFields := schema.User{}.Fields() - _ = userFields - // userDescName is the schema descriptor for name field. - userDescName := userFields[1].Descriptor() - // user.DefaultName holds the default value on creation for the name field. - user.DefaultName = userDescName.Default.(string) - // userDescEmail is the schema descriptor for email field. - userDescEmail := userFields[2].Descriptor() - // user.DefaultEmail holds the default value on creation for the email field. - user.DefaultEmail = userDescEmail.Default.(string) -} diff --git a/examples/transaction/ent/internal/data/ent/runtime/runtime.go b/examples/transaction/ent/internal/data/ent/runtime/runtime.go deleted file mode 100644 index ae00b63c6..000000000 --- a/examples/transaction/ent/internal/data/ent/runtime/runtime.go +++ /dev/null @@ -1,10 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package runtime - -// The schema-stitching logic is generated in github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/runtime.go - -const ( - Version = "v0.9.0" // Version of ent codegen. - Sum = "h1:2S1zfpMMW6p+wctj6kcYUprNPNjLWFW06T5MdyAfmWc=" // Sum of ent codegen. -) diff --git a/examples/transaction/ent/internal/data/ent/schema/card.go b/examples/transaction/ent/internal/data/ent/schema/card.go deleted file mode 100644 index e85d79435..000000000 --- a/examples/transaction/ent/internal/data/ent/schema/card.go +++ /dev/null @@ -1,25 +0,0 @@ -package schema - -import ( - "entgo.io/ent" - "entgo.io/ent/schema/field" -) - -// Card holds the schema definition for the Card entity. -type Card struct { - ent.Schema -} - -// Fields of the Card. -func (Card) Fields() []ent.Field { - return []ent.Field{ - field.Int("id"), - field.String("user_id"), - field.String("money"), - } -} - -// Edges of the Card. -func (Card) Edges() []ent.Edge { - return nil -} diff --git a/examples/transaction/ent/internal/data/ent/schema/user.go b/examples/transaction/ent/internal/data/ent/schema/user.go deleted file mode 100644 index 0c1a832fc..000000000 --- a/examples/transaction/ent/internal/data/ent/schema/user.go +++ /dev/null @@ -1,25 +0,0 @@ -package schema - -import ( - "entgo.io/ent" - "entgo.io/ent/schema/field" -) - -// User holds the schema definition for the User entity. -type User struct { - ent.Schema -} - -// Fields of the User. -func (User) Fields() []ent.Field { - return []ent.Field{ - field.Int("id"), - field.String("name").Default(""), - field.String("email").Default(""), - } -} - -// Edges of the User. -func (User) Edges() []ent.Edge { - return nil -} diff --git a/examples/transaction/ent/internal/data/ent/tx.go b/examples/transaction/ent/internal/data/ent/tx.go deleted file mode 100644 index b132443ea..000000000 --- a/examples/transaction/ent/internal/data/ent/tx.go +++ /dev/null @@ -1,213 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "sync" - - "entgo.io/ent/dialect" -) - -// Tx is a transactional client that is created by calling Client.Tx(). -type Tx struct { - config - // Card is the client for interacting with the Card builders. - Card *CardClient - // User is the client for interacting with the User builders. - User *UserClient - - // lazily loaded. - client *Client - clientOnce sync.Once - - // completion callbacks. - mu sync.Mutex - onCommit []CommitHook - onRollback []RollbackHook - - // ctx lives for the life of the transaction. It is - // the same context used by the underlying connection. - ctx context.Context -} - -type ( - // Committer is the interface that wraps the Committer method. - Committer interface { - Commit(context.Context, *Tx) error - } - - // The CommitFunc type is an adapter to allow the use of ordinary - // function as a Committer. If f is a function with the appropriate - // signature, CommitFunc(f) is a Committer that calls f. - CommitFunc func(context.Context, *Tx) error - - // CommitHook defines the "commit middleware". A function that gets a Committer - // and returns a Committer. For example: - // - // hook := func(next ent.Committer) ent.Committer { - // return ent.CommitFunc(func(context.Context, tx *ent.Tx) error { - // // Do some stuff before. - // if err := next.Commit(ctx, tx); err != nil { - // return err - // } - // // Do some stuff after. - // return nil - // }) - // } - // - CommitHook func(Committer) Committer -) - -// Commit calls f(ctx, m). -func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error { - return f(ctx, tx) -} - -// Commit commits the transaction. -func (tx *Tx) Commit() error { - txDriver := tx.config.driver.(*txDriver) - var fn Committer = CommitFunc(func(context.Context, *Tx) error { - return txDriver.tx.Commit() - }) - tx.mu.Lock() - hooks := append([]CommitHook(nil), tx.onCommit...) - tx.mu.Unlock() - for i := len(hooks) - 1; i >= 0; i-- { - fn = hooks[i](fn) - } - return fn.Commit(tx.ctx, tx) -} - -// OnCommit adds a hook to call on commit. -func (tx *Tx) OnCommit(f CommitHook) { - tx.mu.Lock() - defer tx.mu.Unlock() - tx.onCommit = append(tx.onCommit, f) -} - -type ( - // Rollbacker is the interface that wraps the Rollbacker method. - Rollbacker interface { - Rollback(context.Context, *Tx) error - } - - // The RollbackFunc type is an adapter to allow the use of ordinary - // function as a Rollbacker. If f is a function with the appropriate - // signature, RollbackFunc(f) is a Rollbacker that calls f. - RollbackFunc func(context.Context, *Tx) error - - // RollbackHook defines the "rollback middleware". A function that gets a Rollbacker - // and returns a Rollbacker. For example: - // - // hook := func(next ent.Rollbacker) ent.Rollbacker { - // return ent.RollbackFunc(func(context.Context, tx *ent.Tx) error { - // // Do some stuff before. - // if err := next.Rollback(ctx, tx); err != nil { - // return err - // } - // // Do some stuff after. - // return nil - // }) - // } - // - RollbackHook func(Rollbacker) Rollbacker -) - -// Rollback calls f(ctx, m). -func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error { - return f(ctx, tx) -} - -// Rollback rollbacks the transaction. -func (tx *Tx) Rollback() error { - txDriver := tx.config.driver.(*txDriver) - var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { - return txDriver.tx.Rollback() - }) - tx.mu.Lock() - hooks := append([]RollbackHook(nil), tx.onRollback...) - tx.mu.Unlock() - for i := len(hooks) - 1; i >= 0; i-- { - fn = hooks[i](fn) - } - return fn.Rollback(tx.ctx, tx) -} - -// OnRollback adds a hook to call on rollback. -func (tx *Tx) OnRollback(f RollbackHook) { - tx.mu.Lock() - defer tx.mu.Unlock() - tx.onRollback = append(tx.onRollback, f) -} - -// Client returns a Client that binds to current transaction. -func (tx *Tx) Client() *Client { - tx.clientOnce.Do(func() { - tx.client = &Client{config: tx.config} - tx.client.init() - }) - return tx.client -} - -func (tx *Tx) init() { - tx.Card = NewCardClient(tx.config) - tx.User = NewUserClient(tx.config) -} - -// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. -// The idea is to support transactions without adding any extra code to the builders. -// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. -// Commit and Rollback are nop for the internal builders and the user must call one -// of them in order to commit or rollback the transaction. -// -// If a closed transaction is embedded in one of the generated entities, and the entity -// applies a query, for example: Card.QueryXXX(), the query will be executed -// through the driver which created this transaction. -// -// Note that txDriver is not goroutine safe. -type txDriver struct { - // the driver we started the transaction from. - drv dialect.Driver - // tx is the underlying transaction. - tx dialect.Tx -} - -// newTx creates a new transactional driver. -func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { - tx, err := drv.Tx(ctx) - if err != nil { - return nil, err - } - return &txDriver{tx: tx, drv: drv}, nil -} - -// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls -// from the internal builders. Should be called only by the internal builders. -func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } - -// Dialect returns the dialect of the driver we started the transaction from. -func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } - -// Close is a nop close. -func (*txDriver) Close() error { return nil } - -// Commit is a nop commit for the internal builders. -// User must call `Tx.Commit` in order to commit the transaction. -func (*txDriver) Commit() error { return nil } - -// Rollback is a nop rollback for the internal builders. -// User must call `Tx.Rollback` in order to rollback the transaction. -func (*txDriver) Rollback() error { return nil } - -// Exec calls tx.Exec. -func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error { - return tx.tx.Exec(ctx, query, args, v) -} - -// Query calls tx.Query. -func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error { - return tx.tx.Query(ctx, query, args, v) -} - -var _ dialect.Driver = (*txDriver)(nil) diff --git a/examples/transaction/ent/internal/data/ent/user.go b/examples/transaction/ent/internal/data/ent/user.go deleted file mode 100644 index 94b3439d6..000000000 --- a/examples/transaction/ent/internal/data/ent/user.go +++ /dev/null @@ -1,109 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - - "entgo.io/ent/dialect/sql" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/user" -) - -// User is the model entity for the User schema. -type User struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // Name holds the value of the "name" field. - Name string `json:"name,omitempty"` - // Email holds the value of the "email" field. - Email string `json:"email,omitempty"` -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*User) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) - for i := range columns { - switch columns[i] { - case user.FieldID: - values[i] = new(sql.NullInt64) - case user.FieldName, user.FieldEmail: - values[i] = new(sql.NullString) - default: - return nil, fmt.Errorf("unexpected column %q for type User", columns[i]) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the User fields. -func (u *User) assignValues(columns []string, values []interface{}) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case user.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - u.ID = int(value.Int64) - case user.FieldName: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field name", values[i]) - } else if value.Valid { - u.Name = value.String - } - case user.FieldEmail: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field email", values[i]) - } else if value.Valid { - u.Email = value.String - } - } - } - return nil -} - -// Update returns a builder for updating this User. -// Note that you need to call User.Unwrap() before calling this method if this User -// was returned from a transaction, and the transaction was committed or rolled back. -func (u *User) Update() *UserUpdateOne { - return (&UserClient{config: u.config}).UpdateOne(u) -} - -// Unwrap unwraps the User entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (u *User) Unwrap() *User { - tx, ok := u.config.driver.(*txDriver) - if !ok { - panic("ent: User is not a transactional entity") - } - u.config.driver = tx.drv - return u -} - -// String implements the fmt.Stringer. -func (u *User) String() string { - var builder strings.Builder - builder.WriteString("User(") - builder.WriteString(fmt.Sprintf("id=%v", u.ID)) - builder.WriteString(", name=") - builder.WriteString(u.Name) - builder.WriteString(", email=") - builder.WriteString(u.Email) - builder.WriteByte(')') - return builder.String() -} - -// Users is a parsable slice of User. -type Users []*User - -func (u Users) config(cfg config) { - for _i := range u { - u[_i].config = cfg - } -} diff --git a/examples/transaction/ent/internal/data/ent/user/user.go b/examples/transaction/ent/internal/data/ent/user/user.go deleted file mode 100644 index 0ed69a384..000000000 --- a/examples/transaction/ent/internal/data/ent/user/user.go +++ /dev/null @@ -1,40 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package user - -const ( - // Label holds the string label denoting the user type in the database. - Label = "user" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldName holds the string denoting the name field in the database. - FieldName = "name" - // FieldEmail holds the string denoting the email field in the database. - FieldEmail = "email" - // Table holds the table name of the user in the database. - Table = "users" -) - -// Columns holds all SQL columns for user fields. -var Columns = []string{ - FieldID, - FieldName, - FieldEmail, -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultName holds the default value on creation for the "name" field. - DefaultName string - // DefaultEmail holds the default value on creation for the "email" field. - DefaultEmail string -) diff --git a/examples/transaction/ent/internal/data/ent/user/where.go b/examples/transaction/ent/internal/data/ent/user/where.go deleted file mode 100644 index 59821eda8..000000000 --- a/examples/transaction/ent/internal/data/ent/user/where.go +++ /dev/null @@ -1,359 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package user - -import ( - "entgo.io/ent/dialect/sql" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.User { - return predicate.User(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.User { - return predicate.User(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) -} - -// Name applies equality check predicate on the "name" field. It's identical to NameEQ. -func Name(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) -} - -// Email applies equality check predicate on the "email" field. It's identical to EmailEQ. -func Email(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldEmail), v)) - }) -} - -// NameEQ applies the EQ predicate on the "name" field. -func NameEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) -} - -// NameNEQ applies the NEQ predicate on the "name" field. -func NameNEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) -} - -// NameIn applies the In predicate on the "name" field. -func NameIn(vs ...string) predicate.User { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldName), v...)) - }) -} - -// NameNotIn applies the NotIn predicate on the "name" field. -func NameNotIn(vs ...string) predicate.User { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) -} - -// NameGT applies the GT predicate on the "name" field. -func NameGT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) -} - -// NameGTE applies the GTE predicate on the "name" field. -func NameGTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) -} - -// NameLT applies the LT predicate on the "name" field. -func NameLT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) -} - -// NameLTE applies the LTE predicate on the "name" field. -func NameLTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) -} - -// NameContains applies the Contains predicate on the "name" field. -func NameContains(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) -} - -// NameHasPrefix applies the HasPrefix predicate on the "name" field. -func NameHasPrefix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) -} - -// NameHasSuffix applies the HasSuffix predicate on the "name" field. -func NameHasSuffix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) -} - -// NameEqualFold applies the EqualFold predicate on the "name" field. -func NameEqualFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) -} - -// NameContainsFold applies the ContainsFold predicate on the "name" field. -func NameContainsFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) -} - -// EmailEQ applies the EQ predicate on the "email" field. -func EmailEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldEmail), v)) - }) -} - -// EmailNEQ applies the NEQ predicate on the "email" field. -func EmailNEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldEmail), v)) - }) -} - -// EmailIn applies the In predicate on the "email" field. -func EmailIn(vs ...string) predicate.User { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldEmail), v...)) - }) -} - -// EmailNotIn applies the NotIn predicate on the "email" field. -func EmailNotIn(vs ...string) predicate.User { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldEmail), v...)) - }) -} - -// EmailGT applies the GT predicate on the "email" field. -func EmailGT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldEmail), v)) - }) -} - -// EmailGTE applies the GTE predicate on the "email" field. -func EmailGTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldEmail), v)) - }) -} - -// EmailLT applies the LT predicate on the "email" field. -func EmailLT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldEmail), v)) - }) -} - -// EmailLTE applies the LTE predicate on the "email" field. -func EmailLTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldEmail), v)) - }) -} - -// EmailContains applies the Contains predicate on the "email" field. -func EmailContains(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldEmail), v)) - }) -} - -// EmailHasPrefix applies the HasPrefix predicate on the "email" field. -func EmailHasPrefix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldEmail), v)) - }) -} - -// EmailHasSuffix applies the HasSuffix predicate on the "email" field. -func EmailHasSuffix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldEmail), v)) - }) -} - -// EmailEqualFold applies the EqualFold predicate on the "email" field. -func EmailEqualFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldEmail), v)) - }) -} - -// EmailContainsFold applies the ContainsFold predicate on the "email" field. -func EmailContainsFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldEmail), v)) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) -} diff --git a/examples/transaction/ent/internal/data/ent/user_create.go b/examples/transaction/ent/internal/data/ent/user_create.go deleted file mode 100644 index 39810c403..000000000 --- a/examples/transaction/ent/internal/data/ent/user_create.go +++ /dev/null @@ -1,279 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/user" -) - -// UserCreate is the builder for creating a User entity. -type UserCreate struct { - config - mutation *UserMutation - hooks []Hook -} - -// SetName sets the "name" field. -func (uc *UserCreate) SetName(s string) *UserCreate { - uc.mutation.SetName(s) - return uc -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (uc *UserCreate) SetNillableName(s *string) *UserCreate { - if s != nil { - uc.SetName(*s) - } - return uc -} - -// SetEmail sets the "email" field. -func (uc *UserCreate) SetEmail(s string) *UserCreate { - uc.mutation.SetEmail(s) - return uc -} - -// SetNillableEmail sets the "email" field if the given value is not nil. -func (uc *UserCreate) SetNillableEmail(s *string) *UserCreate { - if s != nil { - uc.SetEmail(*s) - } - return uc -} - -// SetID sets the "id" field. -func (uc *UserCreate) SetID(i int) *UserCreate { - uc.mutation.SetID(i) - return uc -} - -// Mutation returns the UserMutation object of the builder. -func (uc *UserCreate) Mutation() *UserMutation { - return uc.mutation -} - -// Save creates the User in the database. -func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - var ( - err error - node *User - ) - uc.defaults() - if len(uc.hooks) == 0 { - if err = uc.check(); err != nil { - return nil, err - } - node, err = uc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = uc.check(); err != nil { - return nil, err - } - uc.mutation = mutation - if node, err = uc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(uc.hooks) - 1; i >= 0; i-- { - if uc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = uc.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, uc.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX calls Save and panics if Save returns an error. -func (uc *UserCreate) SaveX(ctx context.Context) *User { - v, err := uc.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (uc *UserCreate) Exec(ctx context.Context) error { - _, err := uc.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (uc *UserCreate) ExecX(ctx context.Context) { - if err := uc.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (uc *UserCreate) defaults() { - if _, ok := uc.mutation.Name(); !ok { - v := user.DefaultName - uc.mutation.SetName(v) - } - if _, ok := uc.mutation.Email(); !ok { - v := user.DefaultEmail - uc.mutation.SetEmail(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (uc *UserCreate) check() error { - if _, ok := uc.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "name"`)} - } - if _, ok := uc.mutation.Email(); !ok { - return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "email"`)} - } - return nil -} - -func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { - _node, _spec := uc.createSpec() - if err := sqlgraph.CreateNode(ctx, uc.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - return nil, err - } - if _node.ID == 0 { - id := _spec.ID.Value.(int64) - _node.ID = int(id) - } - return _node, nil -} - -func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { - var ( - _node = &User{config: uc.config} - _spec = &sqlgraph.CreateSpec{ - Table: user.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: user.FieldID, - }, - } - ) - if id, ok := uc.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = id - } - if value, ok := uc.mutation.Name(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: user.FieldName, - }) - _node.Name = value - } - if value, ok := uc.mutation.Email(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: user.FieldEmail, - }) - _node.Email = value - } - return _node, _spec -} - -// UserCreateBulk is the builder for creating many User entities in bulk. -type UserCreateBulk struct { - config - builders []*UserCreate -} - -// Save creates the User entities in the database. -func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { - specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) - nodes := make([]*User, len(ucb.builders)) - mutators := make([]Mutator, len(ucb.builders)) - for i := range ucb.builders { - func(i int, root context.Context) { - builder := ucb.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() - var err error - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, ucb.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, ucb.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - mutation.done = true - if specs[i].ID.Value != nil && nodes[i].ID == 0 { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, ucb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (ucb *UserCreateBulk) SaveX(ctx context.Context) []*User { - v, err := ucb.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (ucb *UserCreateBulk) Exec(ctx context.Context) error { - _, err := ucb.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (ucb *UserCreateBulk) ExecX(ctx context.Context) { - if err := ucb.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/examples/transaction/ent/internal/data/ent/user_delete.go b/examples/transaction/ent/internal/data/ent/user_delete.go deleted file mode 100644 index 6378c9323..000000000 --- a/examples/transaction/ent/internal/data/ent/user_delete.go +++ /dev/null @@ -1,111 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/predicate" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/user" -) - -// UserDelete is the builder for deleting a User entity. -type UserDelete struct { - config - hooks []Hook - mutation *UserMutation -} - -// Where appends a list predicates to the UserDelete builder. -func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { - ud.mutation.Where(ps...) - return ud -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ud.hooks) == 0 { - affected, err = ud.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ud.mutation = mutation - affected, err = ud.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(ud.hooks) - 1; i >= 0; i-- { - if ud.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ud.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ud.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// ExecX is like Exec, but panics if an error occurs. -func (ud *UserDelete) ExecX(ctx context.Context) int { - n, err := ud.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: user.FieldID, - }, - }, - } - if ps := ud.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return sqlgraph.DeleteNodes(ctx, ud.driver, _spec) -} - -// UserDeleteOne is the builder for deleting a single User entity. -type UserDeleteOne struct { - ud *UserDelete -} - -// Exec executes the deletion query. -func (udo *UserDeleteOne) Exec(ctx context.Context) error { - n, err := udo.ud.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{user.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (udo *UserDeleteOne) ExecX(ctx context.Context) { - udo.ud.ExecX(ctx) -} diff --git a/examples/transaction/ent/internal/data/ent/user_query.go b/examples/transaction/ent/internal/data/ent/user_query.go deleted file mode 100644 index 8f0bc63dc..000000000 --- a/examples/transaction/ent/internal/data/ent/user_query.go +++ /dev/null @@ -1,915 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "math" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/predicate" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/user" -) - -// UserQuery is the builder for querying User entities. -type UserQuery struct { - config - limit *int - offset *int - unique *bool - order []OrderFunc - fields []string - predicates []predicate.User - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the UserQuery builder. -func (uq *UserQuery) Where(ps ...predicate.User) *UserQuery { - uq.predicates = append(uq.predicates, ps...) - return uq -} - -// Limit adds a limit step to the query. -func (uq *UserQuery) Limit(limit int) *UserQuery { - uq.limit = &limit - return uq -} - -// Offset adds an offset step to the query. -func (uq *UserQuery) Offset(offset int) *UserQuery { - uq.offset = &offset - return uq -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (uq *UserQuery) Unique(unique bool) *UserQuery { - uq.unique = &unique - return uq -} - -// Order adds an order step to the query. -func (uq *UserQuery) Order(o ...OrderFunc) *UserQuery { - uq.order = append(uq.order, o...) - return uq -} - -// First returns the first User entity from the query. -// Returns a *NotFoundError when no User was found. -func (uq *UserQuery) First(ctx context.Context) (*User, error) { - nodes, err := uq.Limit(1).All(ctx) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{user.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (uq *UserQuery) FirstX(ctx context.Context) *User { - node, err := uq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first User ID from the query. -// Returns a *NotFoundError when no User ID was found. -func (uq *UserQuery) FirstID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = uq.Limit(1).IDs(ctx); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{user.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (uq *UserQuery) FirstIDX(ctx context.Context) int { - id, err := uq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single User entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one User entity is not found. -// Returns a *NotFoundError when no User entities are found. -func (uq *UserQuery) Only(ctx context.Context) (*User, error) { - nodes, err := uq.Limit(2).All(ctx) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{user.Label} - default: - return nil, &NotSingularError{user.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (uq *UserQuery) OnlyX(ctx context.Context) *User { - node, err := uq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only User ID in the query. -// Returns a *NotSingularError when exactly one User ID is not found. -// Returns a *NotFoundError when no entities are found. -func (uq *UserQuery) OnlyID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = uq.Limit(2).IDs(ctx); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{user.Label} - default: - err = &NotSingularError{user.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (uq *UserQuery) OnlyIDX(ctx context.Context) int { - id, err := uq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of Users. -func (uq *UserQuery) All(ctx context.Context) ([]*User, error) { - if err := uq.prepareQuery(ctx); err != nil { - return nil, err - } - return uq.sqlAll(ctx) -} - -// AllX is like All, but panics if an error occurs. -func (uq *UserQuery) AllX(ctx context.Context) []*User { - nodes, err := uq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of User IDs. -func (uq *UserQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := uq.Select(user.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (uq *UserQuery) IDsX(ctx context.Context) []int { - ids, err := uq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (uq *UserQuery) Count(ctx context.Context) (int, error) { - if err := uq.prepareQuery(ctx); err != nil { - return 0, err - } - return uq.sqlCount(ctx) -} - -// CountX is like Count, but panics if an error occurs. -func (uq *UserQuery) CountX(ctx context.Context) int { - count, err := uq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (uq *UserQuery) Exist(ctx context.Context) (bool, error) { - if err := uq.prepareQuery(ctx); err != nil { - return false, err - } - return uq.sqlExist(ctx) -} - -// ExistX is like Exist, but panics if an error occurs. -func (uq *UserQuery) ExistX(ctx context.Context) bool { - exist, err := uq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the UserQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (uq *UserQuery) Clone() *UserQuery { - if uq == nil { - return nil - } - return &UserQuery{ - config: uq.config, - limit: uq.limit, - offset: uq.offset, - order: append([]OrderFunc{}, uq.order...), - predicates: append([]predicate.User{}, uq.predicates...), - // clone intermediate query. - sql: uq.sql.Clone(), - path: uq.path, - } -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// Name string `json:"name,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.User.Query(). -// GroupBy(user.FieldName). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -// -func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { - group := &UserGroupBy{config: uq.config} - group.fields = append([]string{field}, fields...) - group.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := uq.prepareQuery(ctx); err != nil { - return nil, err - } - return uq.sqlQuery(ctx), nil - } - return group -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// Name string `json:"name,omitempty"` -// } -// -// client.User.Query(). -// Select(user.FieldName). -// Scan(ctx, &v) -// -func (uq *UserQuery) Select(fields ...string) *UserSelect { - uq.fields = append(uq.fields, fields...) - return &UserSelect{UserQuery: uq} -} - -func (uq *UserQuery) prepareQuery(ctx context.Context) error { - for _, f := range uq.fields { - if !user.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if uq.path != nil { - prev, err := uq.path(ctx) - if err != nil { - return err - } - uq.sql = prev - } - return nil -} - -func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) { - var ( - nodes = []*User{} - _spec = uq.querySpec() - ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { - node := &User{config: uq.config} - nodes = append(nodes, node) - return node.scanValues(columns) - } - _spec.Assign = func(columns []string, values []interface{}) error { - if len(nodes) == 0 { - return fmt.Errorf("ent: Assign called without calling ScanValues") - } - node := nodes[len(nodes)-1] - return node.assignValues(columns, values) - } - if err := sqlgraph.QueryNodes(ctx, uq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - return nodes, nil -} - -func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) { - _spec := uq.querySpec() - return sqlgraph.CountNodes(ctx, uq.driver, _spec) -} - -func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := uq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("ent: check existence: %w", err) - } - return n > 0, nil -} - -func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - Columns: user.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: user.FieldID, - }, - }, - From: uq.sql, - Unique: true, - } - if unique := uq.unique; unique != nil { - _spec.Unique = *unique - } - if fields := uq.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, user.FieldID) - for i := range fields { - if fields[i] != user.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := uq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := uq.limit; limit != nil { - _spec.Limit = *limit - } - if offset := uq.offset; offset != nil { - _spec.Offset = *offset - } - if ps := uq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(uq.driver.Dialect()) - t1 := builder.Table(user.Table) - columns := uq.fields - if len(columns) == 0 { - columns = user.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if uq.sql != nil { - selector = uq.sql - selector.Select(selector.Columns(columns...)...) - } - for _, p := range uq.predicates { - p(selector) - } - for _, p := range uq.order { - p(selector) - } - if offset := uq.offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := uq.limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// UserGroupBy is the group-by builder for User entities. -type UserGroupBy struct { - config - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (ugb *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy { - ugb.fns = append(ugb.fns, fns...) - return ugb -} - -// Scan applies the group-by query and scans the result into the given value. -func (ugb *UserGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := ugb.path(ctx) - if err != nil { - return err - } - ugb.sql = query - return ugb.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (ugb *UserGroupBy) ScanX(ctx context.Context, v interface{}) { - if err := ugb.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from group-by. -// It is only allowed when executing a group-by query with one field. -func (ugb *UserGroupBy) Strings(ctx context.Context) ([]string, error) { - if len(ugb.fields) > 1 { - return nil, errors.New("ent: UserGroupBy.Strings is not achievable when grouping more than 1 field") - } - var v []string - if err := ugb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (ugb *UserGroupBy) StringsX(ctx context.Context) []string { - v, err := ugb.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (ugb *UserGroupBy) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = ugb.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{user.Label} - default: - err = fmt.Errorf("ent: UserGroupBy.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (ugb *UserGroupBy) StringX(ctx context.Context) string { - v, err := ugb.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from group-by. -// It is only allowed when executing a group-by query with one field. -func (ugb *UserGroupBy) Ints(ctx context.Context) ([]int, error) { - if len(ugb.fields) > 1 { - return nil, errors.New("ent: UserGroupBy.Ints is not achievable when grouping more than 1 field") - } - var v []int - if err := ugb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (ugb *UserGroupBy) IntsX(ctx context.Context) []int { - v, err := ugb.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (ugb *UserGroupBy) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = ugb.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{user.Label} - default: - err = fmt.Errorf("ent: UserGroupBy.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (ugb *UserGroupBy) IntX(ctx context.Context) int { - v, err := ugb.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from group-by. -// It is only allowed when executing a group-by query with one field. -func (ugb *UserGroupBy) Float64s(ctx context.Context) ([]float64, error) { - if len(ugb.fields) > 1 { - return nil, errors.New("ent: UserGroupBy.Float64s is not achievable when grouping more than 1 field") - } - var v []float64 - if err := ugb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (ugb *UserGroupBy) Float64sX(ctx context.Context) []float64 { - v, err := ugb.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (ugb *UserGroupBy) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = ugb.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{user.Label} - default: - err = fmt.Errorf("ent: UserGroupBy.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (ugb *UserGroupBy) Float64X(ctx context.Context) float64 { - v, err := ugb.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from group-by. -// It is only allowed when executing a group-by query with one field. -func (ugb *UserGroupBy) Bools(ctx context.Context) ([]bool, error) { - if len(ugb.fields) > 1 { - return nil, errors.New("ent: UserGroupBy.Bools is not achievable when grouping more than 1 field") - } - var v []bool - if err := ugb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (ugb *UserGroupBy) BoolsX(ctx context.Context) []bool { - v, err := ugb.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (ugb *UserGroupBy) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = ugb.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{user.Label} - default: - err = fmt.Errorf("ent: UserGroupBy.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (ugb *UserGroupBy) BoolX(ctx context.Context) bool { - v, err := ugb.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (ugb *UserGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range ugb.fields { - if !user.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := ugb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := ugb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (ugb *UserGroupBy) sqlQuery() *sql.Selector { - selector := ugb.sql.Select() - aggregation := make([]string, 0, len(ugb.fns)) - for _, fn := range ugb.fns { - aggregation = append(aggregation, fn(selector)) - } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(ugb.fields)+len(ugb.fns)) - for _, f := range ugb.fields { - columns = append(columns, selector.C(f)) - } - for _, c := range aggregation { - columns = append(columns, c) - } - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(ugb.fields...)...) -} - -// UserSelect is the builder for selecting fields of User entities. -type UserSelect struct { - *UserQuery - // intermediate query (i.e. traversal path). - sql *sql.Selector -} - -// Scan applies the selector query and scans the result into the given value. -func (us *UserSelect) Scan(ctx context.Context, v interface{}) error { - if err := us.prepareQuery(ctx); err != nil { - return err - } - us.sql = us.UserQuery.sqlQuery(ctx) - return us.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (us *UserSelect) ScanX(ctx context.Context, v interface{}) { - if err := us.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from a selector. It is only allowed when selecting one field. -func (us *UserSelect) Strings(ctx context.Context) ([]string, error) { - if len(us.fields) > 1 { - return nil, errors.New("ent: UserSelect.Strings is not achievable when selecting more than 1 field") - } - var v []string - if err := us.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (us *UserSelect) StringsX(ctx context.Context) []string { - v, err := us.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a selector. It is only allowed when selecting one field. -func (us *UserSelect) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = us.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{user.Label} - default: - err = fmt.Errorf("ent: UserSelect.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (us *UserSelect) StringX(ctx context.Context) string { - v, err := us.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from a selector. It is only allowed when selecting one field. -func (us *UserSelect) Ints(ctx context.Context) ([]int, error) { - if len(us.fields) > 1 { - return nil, errors.New("ent: UserSelect.Ints is not achievable when selecting more than 1 field") - } - var v []int - if err := us.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (us *UserSelect) IntsX(ctx context.Context) []int { - v, err := us.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a selector. It is only allowed when selecting one field. -func (us *UserSelect) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = us.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{user.Label} - default: - err = fmt.Errorf("ent: UserSelect.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (us *UserSelect) IntX(ctx context.Context) int { - v, err := us.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. -func (us *UserSelect) Float64s(ctx context.Context) ([]float64, error) { - if len(us.fields) > 1 { - return nil, errors.New("ent: UserSelect.Float64s is not achievable when selecting more than 1 field") - } - var v []float64 - if err := us.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (us *UserSelect) Float64sX(ctx context.Context) []float64 { - v, err := us.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. -func (us *UserSelect) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = us.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{user.Label} - default: - err = fmt.Errorf("ent: UserSelect.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (us *UserSelect) Float64X(ctx context.Context) float64 { - v, err := us.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from a selector. It is only allowed when selecting one field. -func (us *UserSelect) Bools(ctx context.Context) ([]bool, error) { - if len(us.fields) > 1 { - return nil, errors.New("ent: UserSelect.Bools is not achievable when selecting more than 1 field") - } - var v []bool - if err := us.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (us *UserSelect) BoolsX(ctx context.Context) []bool { - v, err := us.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a selector. It is only allowed when selecting one field. -func (us *UserSelect) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = us.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{user.Label} - default: - err = fmt.Errorf("ent: UserSelect.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (us *UserSelect) BoolX(ctx context.Context) bool { - v, err := us.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (us *UserSelect) sqlScan(ctx context.Context, v interface{}) error { - rows := &sql.Rows{} - query, args := us.sql.Query() - if err := us.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/examples/transaction/ent/internal/data/ent/user_update.go b/examples/transaction/ent/internal/data/ent/user_update.go deleted file mode 100644 index 6f0a4912a..000000000 --- a/examples/transaction/ent/internal/data/ent/user_update.go +++ /dev/null @@ -1,322 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/predicate" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/data/ent/user" -) - -// UserUpdate is the builder for updating User entities. -type UserUpdate struct { - config - hooks []Hook - mutation *UserMutation -} - -// Where appends a list predicates to the UserUpdate builder. -func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate { - uu.mutation.Where(ps...) - return uu -} - -// SetName sets the "name" field. -func (uu *UserUpdate) SetName(s string) *UserUpdate { - uu.mutation.SetName(s) - return uu -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { - if s != nil { - uu.SetName(*s) - } - return uu -} - -// SetEmail sets the "email" field. -func (uu *UserUpdate) SetEmail(s string) *UserUpdate { - uu.mutation.SetEmail(s) - return uu -} - -// SetNillableEmail sets the "email" field if the given value is not nil. -func (uu *UserUpdate) SetNillableEmail(s *string) *UserUpdate { - if s != nil { - uu.SetEmail(*s) - } - return uu -} - -// Mutation returns the UserMutation object of the builder. -func (uu *UserUpdate) Mutation() *UserMutation { - return uu.mutation -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(uu.hooks) == 0 { - affected, err = uu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - uu.mutation = mutation - affected, err = uu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(uu.hooks) - 1; i >= 0; i-- { - if uu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = uu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, uu.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// SaveX is like Save, but panics if an error occurs. -func (uu *UserUpdate) SaveX(ctx context.Context) int { - affected, err := uu.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (uu *UserUpdate) Exec(ctx context.Context) error { - _, err := uu.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (uu *UserUpdate) ExecX(ctx context.Context) { - if err := uu.Exec(ctx); err != nil { - panic(err) - } -} - -func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - Columns: user.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: user.FieldID, - }, - }, - } - if ps := uu.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := uu.mutation.Name(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: user.FieldName, - }) - } - if value, ok := uu.mutation.Email(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: user.FieldEmail, - }) - } - if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{user.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - return 0, err - } - return n, nil -} - -// UserUpdateOne is the builder for updating a single User entity. -type UserUpdateOne struct { - config - fields []string - hooks []Hook - mutation *UserMutation -} - -// SetName sets the "name" field. -func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { - uuo.mutation.SetName(s) - return uuo -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { - if s != nil { - uuo.SetName(*s) - } - return uuo -} - -// SetEmail sets the "email" field. -func (uuo *UserUpdateOne) SetEmail(s string) *UserUpdateOne { - uuo.mutation.SetEmail(s) - return uuo -} - -// SetNillableEmail sets the "email" field if the given value is not nil. -func (uuo *UserUpdateOne) SetNillableEmail(s *string) *UserUpdateOne { - if s != nil { - uuo.SetEmail(*s) - } - return uuo -} - -// Mutation returns the UserMutation object of the builder. -func (uuo *UserUpdateOne) Mutation() *UserMutation { - return uuo.mutation -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne { - uuo.fields = append([]string{field}, fields...) - return uuo -} - -// Save executes the query and returns the updated User entity. -func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - var ( - err error - node *User - ) - if len(uuo.hooks) == 0 { - node, err = uuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - uuo.mutation = mutation - node, err = uuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(uuo.hooks) - 1; i >= 0; i-- { - if uuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = uuo.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, uuo.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX is like Save, but panics if an error occurs. -func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User { - node, err := uuo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (uuo *UserUpdateOne) Exec(ctx context.Context) error { - _, err := uuo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (uuo *UserUpdateOne) ExecX(ctx context.Context) { - if err := uuo.Exec(ctx); err != nil { - panic(err) - } -} - -func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - Columns: user.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: user.FieldID, - }, - }, - } - id, ok := uuo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing User.ID for update")} - } - _spec.Node.ID.Value = id - if fields := uuo.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, user.FieldID) - for _, f := range fields { - if !user.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != user.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := uuo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := uuo.mutation.Name(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: user.FieldName, - }) - } - if value, ok := uuo.mutation.Email(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: user.FieldEmail, - }) - } - _node = &User{config: uuo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{user.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - return nil, err - } - return _node, nil -} diff --git a/examples/transaction/ent/internal/data/transaction.go b/examples/transaction/ent/internal/data/transaction.go deleted file mode 100644 index 1fc82dec4..000000000 --- a/examples/transaction/ent/internal/data/transaction.go +++ /dev/null @@ -1,58 +0,0 @@ -package data - -import ( - "context" - "strconv" - - "github.com/go-kratos/kratos/examples/transaction/ent/internal/biz" - "github.com/go-kratos/kratos/v2/log" -) - -type userRepo struct { - data *Data - log *log.Helper -} - -type cardRepo struct { - data *Data - log *log.Helper -} - -func (u *userRepo) CreateUser(ctx context.Context, m *biz.User) (int, error) { - user, err := u.data.User(ctx). - Create(). - SetName(m.Name). - SetEmail(m.Email). - Save(ctx) - if err != nil { - return 0, err - } - return user.ID, nil -} - -// NewUserRepo . -func NewUserRepo(data *Data, logger log.Logger) biz.UserRepo { - return &userRepo{ - data: data, - log: log.NewHelper(logger), - } -} - -func (c *cardRepo) CreateCard(ctx context.Context, id int) (int, error) { - card, err := c.data.Card(ctx). - Create(). - SetMoney("1000"). - SetUserID(strconv.Itoa(id)). - Save(ctx) - if err != nil { - return 0, err - } - return card.ID, nil -} - -func NewCardRepo(data *Data, logger log.Logger) biz.CardRepo { - return &cardRepo{ - data: data, - log: log.NewHelper(logger), - } -} diff --git a/examples/transaction/ent/internal/server/grpc.go b/examples/transaction/ent/internal/server/grpc.go deleted file mode 100644 index 97198335f..000000000 --- a/examples/transaction/ent/internal/server/grpc.go +++ /dev/null @@ -1,37 +0,0 @@ -package server - -import ( - v1 "github.com/go-kratos/kratos/examples/transaction/api/transaction/v1" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/conf" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/service" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/middleware/tracing" - "github.com/go-kratos/kratos/v2/middleware/validate" - "github.com/go-kratos/kratos/v2/transport/grpc" -) - -// NewGRPCServer new a gRPC server. -func NewGRPCServer(c *conf.Server, logger log.Logger, transaction *service.TransactionService) *grpc.Server { - opts := []grpc.ServerOption{ - grpc.Middleware( - recovery.Recovery(), - tracing.Server(), - logging.Server(logger), - validate.Validator(), - ), - } - if c.Grpc.Network != "" { - opts = append(opts, grpc.Network(c.Grpc.Network)) - } - if c.Grpc.Addr != "" { - opts = append(opts, grpc.Address(c.Grpc.Addr)) - } - if c.Grpc.Timeout != nil { - opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) - } - srv := grpc.NewServer(opts...) - v1.RegisterTransactionServiceServer(srv, transaction) - return srv -} diff --git a/examples/transaction/ent/internal/server/http.go b/examples/transaction/ent/internal/server/http.go deleted file mode 100644 index 8de929bb5..000000000 --- a/examples/transaction/ent/internal/server/http.go +++ /dev/null @@ -1,37 +0,0 @@ -package server - -import ( - v1 "github.com/go-kratos/kratos/examples/transaction/api/transaction/v1" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/conf" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/service" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/middleware/tracing" - "github.com/go-kratos/kratos/v2/middleware/validate" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// NewHTTPServer new a HTTP server. -func NewHTTPServer(c *conf.Server, logger log.Logger, transaction *service.TransactionService) *http.Server { - opts := []http.ServerOption{ - http.Middleware( - recovery.Recovery(), - tracing.Server(), - logging.Server(logger), - validate.Validator(), - ), - } - if c.Http.Network != "" { - opts = append(opts, http.Network(c.Http.Network)) - } - if c.Http.Addr != "" { - opts = append(opts, http.Address(c.Http.Addr)) - } - if c.Http.Timeout != nil { - opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration())) - } - srv := http.NewServer(opts...) - v1.RegisterTransactionServiceHTTPServer(srv, transaction) - return srv -} diff --git a/examples/transaction/ent/internal/server/server.go b/examples/transaction/ent/internal/server/server.go deleted file mode 100644 index 4d267a7a3..000000000 --- a/examples/transaction/ent/internal/server/server.go +++ /dev/null @@ -1,8 +0,0 @@ -package server - -import ( - "github.com/google/wire" -) - -// ProviderSet is server providers. -var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer) diff --git a/examples/transaction/ent/internal/service/README.md b/examples/transaction/ent/internal/service/README.md deleted file mode 100644 index 42321b7b1..000000000 --- a/examples/transaction/ent/internal/service/README.md +++ /dev/null @@ -1 +0,0 @@ -# Service diff --git a/examples/transaction/ent/internal/service/service.go b/examples/transaction/ent/internal/service/service.go deleted file mode 100644 index 44341851e..000000000 --- a/examples/transaction/ent/internal/service/service.go +++ /dev/null @@ -1,20 +0,0 @@ -package service - -import ( - pb "github.com/go-kratos/kratos/examples/transaction/api/transaction/v1" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/biz" - - "github.com/go-kratos/kratos/v2/log" - "github.com/google/wire" -) - -// ProviderSet is service providers. -var ProviderSet = wire.NewSet(NewTransactionService) - -type TransactionService struct { - pb.UnimplementedTransactionServiceServer - - log *log.Helper - - user *biz.UserUsecase -} diff --git a/examples/transaction/ent/internal/service/transaction.go b/examples/transaction/ent/internal/service/transaction.go deleted file mode 100644 index 15479df69..000000000 --- a/examples/transaction/ent/internal/service/transaction.go +++ /dev/null @@ -1,31 +0,0 @@ -package service - -import ( - "context" - "strconv" - - pb "github.com/go-kratos/kratos/examples/transaction/api/transaction/v1" - "github.com/go-kratos/kratos/examples/transaction/ent/internal/biz" - - "github.com/go-kratos/kratos/v2/log" -) - -func NewTransactionService(user *biz.UserUsecase, logger log.Logger) *TransactionService { - return &TransactionService{ - user: user, - log: log.NewHelper(logger), - } -} - -func (b *TransactionService) CreateUser(ctx context.Context, in *pb.CreateUserRequest) (*pb.CreateUserReply, error) { - id, err := b.user.CreateUser(ctx, &biz.User{ - Name: in.Name, - Email: in.Email, - }) - if err != nil { - return nil, err - } - return &pb.CreateUserReply{ - Id: strconv.Itoa(id), - }, nil -} diff --git a/examples/transaction/ent/openapi.yaml b/examples/transaction/ent/openapi.yaml deleted file mode 100644 index c4afd3ba2..000000000 --- a/examples/transaction/ent/openapi.yaml +++ /dev/null @@ -1,126 +0,0 @@ -# Generated with protoc-gen-openapi -# https://github.com/google/gnostic/tree/master/apps/protoc-gen-openapi - -openapi: 3.0.3 -info: - title: BlogService - version: 0.0.1 -paths: - /v1/article/: - get: - operationId: BlogService_ListArticle - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ListArticleReply' - post: - operationId: BlogService_CreateArticle - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CreateArticleRequest' - required: true - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateArticleReply' - /v1/article/{id}: - get: - operationId: BlogService_GetArticle - parameters: - - name: id - in: query - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/GetArticleReply' - put: - operationId: BlogService_UpdateArticle - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/UpdateArticleRequest' - required: true - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/UpdateArticleReply' - delete: - operationId: BlogService_DeleteArticle - parameters: - - name: id - in: query - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/DeleteArticleReply' -components: - schemas: - Article: - properties: - id: - type: integer - format: int64 - title: - type: string - content: - type: string - like: - type: integer - format: int64 - CreateArticleReply: - properties: - Article: - $ref: '#/components/schemas/Article' - CreateArticleRequest: - properties: - title: - type: string - content: - type: string - DeleteArticleReply: - properties: {} - GetArticleReply: - properties: - Article: - $ref: '#/components/schemas/Article' - ListArticleReply: - properties: - results: - type: array - items: - $ref: '#/components/schemas/Article' - UpdateArticleReply: - properties: - Article: - $ref: '#/components/schemas/Article' - UpdateArticleRequest: - properties: - id: - type: integer - format: int64 - title: - type: string - content: - type: string diff --git a/examples/transaction/gorm/Makefile b/examples/transaction/gorm/Makefile deleted file mode 100644 index 99f8034de..000000000 --- a/examples/transaction/gorm/Makefile +++ /dev/null @@ -1,79 +0,0 @@ -GOPATH:=$(shell go env GOPATH) -VERSION=$(shell git describe --tags --always) -INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) -API_PROTO_FILES=$(shell find api -name *.proto) - -.PHONY: init -# init env -init: - go install google.golang.org/protobuf/cmd/protoc-gen-go@latest - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest - go install github.com/go-kratos/kratos/cmd/kratos/v2@latest - go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest - go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest - go install github.com/google/gnostic/cmd/protoc-gen-openapi@v0.6.1 - -.PHONY: errors -# generate errors code -errors: - protoc --proto_path=. \ - --proto_path=./third_party \ - --go_out=paths=source_relative:. \ - --go-errors_out=paths=source_relative:. \ - $(API_PROTO_FILES) - -.PHONY: config -# generate internal proto -config: - protoc --proto_path=. \ - --proto_path=./third_party \ - --go_out=paths=source_relative:. \ - $(INTERNAL_PROTO_FILES) - -.PHONY: api -# generate api proto -api: - protoc --proto_path=. \ - --proto_path=./third_party \ - --go_out=paths=source_relative:. \ - --go-http_out=paths=source_relative:. \ - --go-grpc_out=paths=source_relative:. \ - --openapi_out==paths=source_relative:. \ - $(API_PROTO_FILES) - -.PHONY: build -# build -build: - mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./... - -.PHONY: generate -# generate -generate: - go generate ./... - -.PHONY: all -# generate all -all: - make api; - make errors; - make config; - make generate; - -# show help -help: - @echo '' - @echo 'Usage:' - @echo ' make [target]' - @echo '' - @echo 'Targets:' - @awk '/^[a-zA-Z\-\_0-9]+:/ { \ - helpMessage = match(lastLine, /^# (.*)/); \ - if (helpMessage) { \ - helpCommand = substr($$1, 0, index($$1, ":")-1); \ - helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \ - printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \ - } \ - } \ - { lastLine = $$0 }' $(MAKEFILE_LIST) - -.DEFAULT_GOAL := help diff --git a/examples/transaction/gorm/README.md b/examples/transaction/gorm/README.md deleted file mode 100644 index 4c85ae7cb..000000000 --- a/examples/transaction/gorm/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# How to run this blog example server -1. You should ensure that your mysql server is running. -2. Ensure that the database named `testdb` has been created, - otherwise you should execute the following database script: -```mysql -create database testdb; -``` -3. Modify the `configs/config.yaml` file and add your mysql information in the data source: -```yaml -data: - database: - driver: mysql - source: root:password@tcp(127.0.0.1:3306)/testdb?parseTime=True -``` -4. Run your blog server: -```bash -$ go generate ./... -$ kratos run -``` diff --git a/examples/transaction/gorm/cmd/gorm/main.go b/examples/transaction/gorm/cmd/gorm/main.go deleted file mode 100644 index 2b5ad97d1..000000000 --- a/examples/transaction/gorm/cmd/gorm/main.go +++ /dev/null @@ -1,103 +0,0 @@ -package main - -import ( - "flag" - "os" - - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/conf" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/config" - "github.com/go-kratos/kratos/v2/config/file" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/exporters/jaeger" - "go.opentelemetry.io/otel/sdk/resource" - tracesdk "go.opentelemetry.io/otel/sdk/trace" - semconv "go.opentelemetry.io/otel/semconv/v1.4.0" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name string - // Version is the version of the compiled software. - Version string - // flagconf is the config flag. - flagconf string -) - -func init() { - flag.StringVar(&flagconf, "conf", "../../configs", "config path, eg: -conf config.yaml") -} - -func newApp(logger log.Logger, hs *http.Server, gs *grpc.Server) *kratos.App { - return kratos.New( - kratos.Name(Name), - kratos.Version(Version), - kratos.Metadata(map[string]string{}), - kratos.Logger(logger), - kratos.Server( - hs, - gs, - ), - ) -} - -// Set global trace provider -func setTracerProvider(url string) error { - // Create the Jaeger exporter - exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url))) - if err != nil { - return err - } - tp := tracesdk.NewTracerProvider( - // Set the sampling rate based on the parent span to 100% - tracesdk.WithSampler(tracesdk.ParentBased(tracesdk.TraceIDRatioBased(1.0))), - // Always be sure to batch in production. - tracesdk.WithBatcher(exp), - // Record information about this application in an Resource. - tracesdk.WithResource(resource.NewSchemaless( - semconv.ServiceNameKey.String(Name), - attribute.String("env", "dev"), - )), - ) - otel.SetTracerProvider(tp) - return nil -} - -func main() { - flag.Parse() - logger := log.NewStdLogger(os.Stdout) - - cfg := config.New( - config.WithSource( - file.NewSource(flagconf), - ), - ) - if err := cfg.Load(); err != nil { - panic(err) - } - - var bc conf.Bootstrap - if err := cfg.Scan(&bc); err != nil { - panic(err) - } - - if err := setTracerProvider(bc.Trace.Endpoint); err != nil { - panic(err) - } - - app, cleanup, err := initApp(bc.Server, bc.Data, logger) - if err != nil { - panic(err) - } - defer cleanup() - - // start and wait for stop signal - if err := app.Run(); err != nil { - panic(err) - } -} diff --git a/examples/transaction/gorm/cmd/gorm/wire.go b/examples/transaction/gorm/cmd/gorm/wire.go deleted file mode 100644 index 1c2baa371..000000000 --- a/examples/transaction/gorm/cmd/gorm/wire.go +++ /dev/null @@ -1,22 +0,0 @@ -//go:build wireinject -// +build wireinject - -// The build tag makes sure the stub is not built in the final build. - -package main - -import ( - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/biz" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/conf" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/data" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/server" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/service" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" - "github.com/google/wire" -) - -// initApp init kratos application. -func initApp(*conf.Server, *conf.Data, log.Logger) (*kratos.App, func(), error) { - panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) -} diff --git a/examples/transaction/gorm/cmd/gorm/wire_gen.go b/examples/transaction/gorm/cmd/gorm/wire_gen.go deleted file mode 100644 index bd0cefe78..000000000 --- a/examples/transaction/gorm/cmd/gorm/wire_gen.go +++ /dev/null @@ -1,39 +0,0 @@ -// Code generated by Wire. DO NOT EDIT. - -//go:generate go run github.com/google/wire/cmd/wire -//go:build !wireinject -// +build !wireinject - -package main - -import ( - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/biz" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/conf" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/data" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/server" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/service" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/log" -) - -// Injectors from wire.go: - -// initApp init kratos application. -func initApp(confServer *conf.Server, confData *conf.Data, logger log.Logger) (*kratos.App, func(), error) { - db := data.NewDB(confData, logger) - dataData, cleanup, err := data.NewData(db, logger) - if err != nil { - return nil, nil, err - } - userRepo := data.NewUserRepo(dataData, logger) - cardRepo := data.NewCardRepo(dataData, logger) - transaction := data.NewTransaction(dataData) - userUsecase := biz.NewUserUsecase(userRepo, cardRepo, transaction, logger) - transactionService := service.NewTransactionService(userUsecase, logger) - httpServer := server.NewHTTPServer(confServer, logger, transactionService) - grpcServer := server.NewGRPCServer(confServer, logger, transactionService) - app := newApp(logger, httpServer, grpcServer) - return app, func() { - cleanup() - }, nil -} diff --git a/examples/transaction/gorm/configs/config.yaml b/examples/transaction/gorm/configs/config.yaml deleted file mode 100644 index 971033aa3..000000000 --- a/examples/transaction/gorm/configs/config.yaml +++ /dev/null @@ -1,18 +0,0 @@ -trace: - endpoint: http://127.0.0.1:14268/api/traces -server: - http: - addr: 0.0.0.0:8000 - timeout: 1s - grpc: - addr: 0.0.0.0:9000 - timeout: 1s -data: - database: - driver: mysql - source: root:root@tcp(127.0.0.1:3306)/testdb?charset=utf8mb4&parseTime=True&loc=Local - redis: - addr: 127.0.0.1:6379 - dial_timeout: 1s - read_timeout: 0.4s - write_timeout: 0.6s \ No newline at end of file diff --git a/examples/transaction/gorm/generate.go b/examples/transaction/gorm/generate.go deleted file mode 100644 index 4aac2aa9f..000000000 --- a/examples/transaction/gorm/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package generate - -//go:generate kratos proto client . diff --git a/examples/transaction/gorm/internal/biz/README.md b/examples/transaction/gorm/internal/biz/README.md deleted file mode 100644 index 26a66b630..000000000 --- a/examples/transaction/gorm/internal/biz/README.md +++ /dev/null @@ -1 +0,0 @@ -# Biz diff --git a/examples/transaction/gorm/internal/biz/biz.go b/examples/transaction/gorm/internal/biz/biz.go deleted file mode 100644 index f2ca2350f..000000000 --- a/examples/transaction/gorm/internal/biz/biz.go +++ /dev/null @@ -1,14 +0,0 @@ -package biz - -import ( - "context" - - "github.com/google/wire" -) - -// ProviderSet is biz providers. -var ProviderSet = wire.NewSet(NewUserUsecase) - -type Transaction interface { - ExecTx(context.Context, func(ctx context.Context) error) error -} diff --git a/examples/transaction/gorm/internal/biz/transaction.go b/examples/transaction/gorm/internal/biz/transaction.go deleted file mode 100644 index a0ed8001c..000000000 --- a/examples/transaction/gorm/internal/biz/transaction.go +++ /dev/null @@ -1,52 +0,0 @@ -package biz - -import ( - "context" - - "github.com/go-kratos/kratos/v2/log" -) - -type User struct { - Name string - Email string -} - -type UserRepo interface { - CreateUser(ctx context.Context, a *User) (int64, error) -} - -type CardRepo interface { - CreateCard(ctx context.Context, id int64) (int64, error) -} - -type UserUsecase struct { - userRepo UserRepo - cardRepo CardRepo - tm Transaction -} - -func NewUserUsecase(user UserRepo, card CardRepo, tm Transaction, logger log.Logger) *UserUsecase { - return &UserUsecase{userRepo: user, cardRepo: card, tm: tm} -} - -func (u *UserUsecase) CreateUser(ctx context.Context, m *User) (int, error) { - var ( - err error - id int64 - ) - err = u.tm.ExecTx(ctx, func(ctx context.Context) error { - id, err = u.userRepo.CreateUser(ctx, m) - if err != nil { - return err - } - _, err = u.cardRepo.CreateCard(ctx, id) - if err != nil { - return err - } - return nil - }) - if err != nil { - return 0, err - } - return int(id), nil -} diff --git a/examples/transaction/gorm/internal/conf/conf.pb.go b/examples/transaction/gorm/internal/conf/conf.pb.go deleted file mode 100644 index e57b932f2..000000000 --- a/examples/transaction/gorm/internal/conf/conf.pb.go +++ /dev/null @@ -1,763 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.1 -// protoc v3.15.8 -// source: conf.proto - -package conf - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - durationpb "google.golang.org/protobuf/types/known/durationpb" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Bootstrap struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Trace *Trace `protobuf:"bytes,1,opt,name=trace,proto3" json:"trace,omitempty"` - Server *Server `protobuf:"bytes,2,opt,name=server,proto3" json:"server,omitempty"` - Data *Data `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` -} - -func (x *Bootstrap) Reset() { - *x = Bootstrap{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Bootstrap) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Bootstrap) ProtoMessage() {} - -func (x *Bootstrap) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Bootstrap.ProtoReflect.Descriptor instead. -func (*Bootstrap) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{0} -} - -func (x *Bootstrap) GetTrace() *Trace { - if x != nil { - return x.Trace - } - return nil -} - -func (x *Bootstrap) GetServer() *Server { - if x != nil { - return x.Server - } - return nil -} - -func (x *Bootstrap) GetData() *Data { - if x != nil { - return x.Data - } - return nil -} - -type Server struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Http *Server_HTTP `protobuf:"bytes,1,opt,name=http,proto3" json:"http,omitempty"` - Grpc *Server_GRPC `protobuf:"bytes,2,opt,name=grpc,proto3" json:"grpc,omitempty"` -} - -func (x *Server) Reset() { - *x = Server{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server) ProtoMessage() {} - -func (x *Server) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server.ProtoReflect.Descriptor instead. -func (*Server) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{1} -} - -func (x *Server) GetHttp() *Server_HTTP { - if x != nil { - return x.Http - } - return nil -} - -func (x *Server) GetGrpc() *Server_GRPC { - if x != nil { - return x.Grpc - } - return nil -} - -type Data struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Database *Data_Database `protobuf:"bytes,1,opt,name=database,proto3" json:"database,omitempty"` - Redis *Data_Redis `protobuf:"bytes,2,opt,name=redis,proto3" json:"redis,omitempty"` -} - -func (x *Data) Reset() { - *x = Data{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data) ProtoMessage() {} - -func (x *Data) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data.ProtoReflect.Descriptor instead. -func (*Data) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{2} -} - -func (x *Data) GetDatabase() *Data_Database { - if x != nil { - return x.Database - } - return nil -} - -func (x *Data) GetRedis() *Data_Redis { - if x != nil { - return x.Redis - } - return nil -} - -type Trace struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Endpoint string `protobuf:"bytes,1,opt,name=endpoint,proto3" json:"endpoint,omitempty"` -} - -func (x *Trace) Reset() { - *x = Trace{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Trace) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Trace) ProtoMessage() {} - -func (x *Trace) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Trace.ProtoReflect.Descriptor instead. -func (*Trace) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{3} -} - -func (x *Trace) GetEndpoint() string { - if x != nil { - return x.Endpoint - } - return "" -} - -type Server_HTTP struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - Timeout *durationpb.Duration `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"` -} - -func (x *Server_HTTP) Reset() { - *x = Server_HTTP{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server_HTTP) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server_HTTP) ProtoMessage() {} - -func (x *Server_HTTP) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server_HTTP.ProtoReflect.Descriptor instead. -func (*Server_HTTP) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{1, 0} -} - -func (x *Server_HTTP) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Server_HTTP) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Server_HTTP) GetTimeout() *durationpb.Duration { - if x != nil { - return x.Timeout - } - return nil -} - -type Server_GRPC struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - Timeout *durationpb.Duration `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"` -} - -func (x *Server_GRPC) Reset() { - *x = Server_GRPC{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Server_GRPC) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Server_GRPC) ProtoMessage() {} - -func (x *Server_GRPC) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Server_GRPC.ProtoReflect.Descriptor instead. -func (*Server_GRPC) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{1, 1} -} - -func (x *Server_GRPC) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Server_GRPC) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Server_GRPC) GetTimeout() *durationpb.Duration { - if x != nil { - return x.Timeout - } - return nil -} - -type Data_Database struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Driver string `protobuf:"bytes,1,opt,name=driver,proto3" json:"driver,omitempty"` - Source string `protobuf:"bytes,2,opt,name=source,proto3" json:"source,omitempty"` -} - -func (x *Data_Database) Reset() { - *x = Data_Database{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data_Database) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data_Database) ProtoMessage() {} - -func (x *Data_Database) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data_Database.ProtoReflect.Descriptor instead. -func (*Data_Database) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{2, 0} -} - -func (x *Data_Database) GetDriver() string { - if x != nil { - return x.Driver - } - return "" -} - -func (x *Data_Database) GetSource() string { - if x != nil { - return x.Source - } - return "" -} - -type Data_Redis struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` - Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` - Password string `protobuf:"bytes,3,opt,name=password,proto3" json:"password,omitempty"` - Db int32 `protobuf:"varint,4,opt,name=db,proto3" json:"db,omitempty"` - DialTimeout *durationpb.Duration `protobuf:"bytes,5,opt,name=dial_timeout,json=dialTimeout,proto3" json:"dial_timeout,omitempty"` - ReadTimeout *durationpb.Duration `protobuf:"bytes,6,opt,name=read_timeout,json=readTimeout,proto3" json:"read_timeout,omitempty"` - WriteTimeout *durationpb.Duration `protobuf:"bytes,7,opt,name=write_timeout,json=writeTimeout,proto3" json:"write_timeout,omitempty"` -} - -func (x *Data_Redis) Reset() { - *x = Data_Redis{} - if protoimpl.UnsafeEnabled { - mi := &file_conf_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Data_Redis) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Data_Redis) ProtoMessage() {} - -func (x *Data_Redis) ProtoReflect() protoreflect.Message { - mi := &file_conf_proto_msgTypes[7] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Data_Redis.ProtoReflect.Descriptor instead. -func (*Data_Redis) Descriptor() ([]byte, []int) { - return file_conf_proto_rawDescGZIP(), []int{2, 1} -} - -func (x *Data_Redis) GetNetwork() string { - if x != nil { - return x.Network - } - return "" -} - -func (x *Data_Redis) GetAddr() string { - if x != nil { - return x.Addr - } - return "" -} - -func (x *Data_Redis) GetPassword() string { - if x != nil { - return x.Password - } - return "" -} - -func (x *Data_Redis) GetDb() int32 { - if x != nil { - return x.Db - } - return 0 -} - -func (x *Data_Redis) GetDialTimeout() *durationpb.Duration { - if x != nil { - return x.DialTimeout - } - return nil -} - -func (x *Data_Redis) GetReadTimeout() *durationpb.Duration { - if x != nil { - return x.ReadTimeout - } - return nil -} - -func (x *Data_Redis) GetWriteTimeout() *durationpb.Duration { - if x != nil { - return x.WriteTimeout - } - return nil -} - -var File_conf_proto protoreflect.FileDescriptor - -var file_conf_proto_rawDesc = []byte{ - 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x6b, 0x72, - 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, - 0x6e, 0x66, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0xa4, 0x01, 0x0a, 0x09, 0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, - 0x12, 0x31, 0x0a, 0x05, 0x74, 0x72, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x1b, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x54, 0x72, 0x61, 0x63, 0x65, 0x52, 0x05, 0x74, 0x72, - 0x61, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, - 0x72, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x2e, 0x0a, 0x04, 0x64, 0x61, 0x74, - 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, - 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, - 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xcc, 0x02, 0x0a, 0x06, 0x53, 0x65, - 0x72, 0x76, 0x65, 0x72, 0x12, 0x35, 0x0a, 0x04, 0x68, 0x74, 0x74, 0x70, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, - 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x04, 0x68, 0x74, 0x74, 0x70, 0x12, 0x35, 0x0a, 0x04, 0x67, - 0x72, 0x70, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x6b, 0x72, 0x61, 0x74, - 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, - 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x47, 0x52, 0x50, 0x43, 0x52, 0x04, 0x67, 0x72, - 0x70, 0x63, 0x1a, 0x69, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, - 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, - 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x33, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, - 0x6f, 0x75, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x1a, 0x69, 0x0a, - 0x04, 0x47, 0x52, 0x50, 0x43, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, - 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, - 0x64, 0x64, 0x72, 0x12, 0x33, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, - 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x22, 0xdb, 0x03, 0x0a, 0x04, 0x44, 0x61, 0x74, - 0x61, 0x12, 0x3f, 0x0a, 0x08, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x2e, - 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, - 0x73, 0x65, 0x12, 0x36, 0x0a, 0x05, 0x72, 0x65, 0x64, 0x69, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x20, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, - 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x52, 0x65, - 0x64, 0x69, 0x73, 0x52, 0x05, 0x72, 0x65, 0x64, 0x69, 0x73, 0x1a, 0x3a, 0x0a, 0x08, 0x44, 0x61, - 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x12, 0x16, - 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, - 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0x9d, 0x02, 0x0a, 0x05, 0x52, 0x65, 0x64, 0x69, 0x73, - 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, - 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x1a, - 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x64, 0x62, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x64, 0x62, 0x12, 0x3c, 0x0a, 0x0c, 0x64, 0x69, - 0x61, 0x6c, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x64, 0x69, 0x61, - 0x6c, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3c, 0x0a, 0x0c, 0x72, 0x65, 0x61, 0x64, - 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x72, 0x65, 0x61, 0x64, 0x54, - 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3e, 0x0a, 0x0d, 0x77, 0x72, 0x69, 0x74, 0x65, 0x5f, - 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0c, 0x77, 0x72, 0x69, 0x74, 0x65, 0x54, - 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x22, 0x23, 0x0a, 0x05, 0x54, 0x72, 0x61, 0x63, 0x65, 0x12, - 0x1a, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x42, 0x3e, 0x5a, 0x3c, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, - 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x73, 0x2f, 0x62, 0x6c, 0x6f, 0x67, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, 0x63, 0x6f, 0x6e, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, -} - -var ( - file_conf_proto_rawDescOnce sync.Once - file_conf_proto_rawDescData = file_conf_proto_rawDesc -) - -func file_conf_proto_rawDescGZIP() []byte { - file_conf_proto_rawDescOnce.Do(func() { - file_conf_proto_rawDescData = protoimpl.X.CompressGZIP(file_conf_proto_rawDescData) - }) - return file_conf_proto_rawDescData -} - -var file_conf_proto_msgTypes = make([]protoimpl.MessageInfo, 8) -var file_conf_proto_goTypes = []interface{}{ - (*Bootstrap)(nil), // 0: kratos.internal.conf.Bootstrap - (*Server)(nil), // 1: kratos.internal.conf.Server - (*Data)(nil), // 2: kratos.internal.conf.Data - (*Trace)(nil), // 3: kratos.internal.conf.Trace - (*Server_HTTP)(nil), // 4: kratos.internal.conf.Server.HTTP - (*Server_GRPC)(nil), // 5: kratos.internal.conf.Server.GRPC - (*Data_Database)(nil), // 6: kratos.internal.conf.Data.Database - (*Data_Redis)(nil), // 7: kratos.internal.conf.Data.Redis - (*durationpb.Duration)(nil), // 8: google.protobuf.Duration -} -var file_conf_proto_depIdxs = []int32{ - 3, // 0: kratos.internal.conf.Bootstrap.trace:type_name -> kratos.internal.conf.Trace - 1, // 1: kratos.internal.conf.Bootstrap.server:type_name -> kratos.internal.conf.Server - 2, // 2: kratos.internal.conf.Bootstrap.data:type_name -> kratos.internal.conf.Data - 4, // 3: kratos.internal.conf.Server.http:type_name -> kratos.internal.conf.Server.HTTP - 5, // 4: kratos.internal.conf.Server.grpc:type_name -> kratos.internal.conf.Server.GRPC - 6, // 5: kratos.internal.conf.Data.database:type_name -> kratos.internal.conf.Data.Database - 7, // 6: kratos.internal.conf.Data.redis:type_name -> kratos.internal.conf.Data.Redis - 8, // 7: kratos.internal.conf.Server.HTTP.timeout:type_name -> google.protobuf.Duration - 8, // 8: kratos.internal.conf.Server.GRPC.timeout:type_name -> google.protobuf.Duration - 8, // 9: kratos.internal.conf.Data.Redis.dial_timeout:type_name -> google.protobuf.Duration - 8, // 10: kratos.internal.conf.Data.Redis.read_timeout:type_name -> google.protobuf.Duration - 8, // 11: kratos.internal.conf.Data.Redis.write_timeout:type_name -> google.protobuf.Duration - 12, // [12:12] is the sub-list for method output_type - 12, // [12:12] is the sub-list for method input_type - 12, // [12:12] is the sub-list for extension type_name - 12, // [12:12] is the sub-list for extension extendee - 0, // [0:12] is the sub-list for field type_name -} - -func init() { file_conf_proto_init() } -func file_conf_proto_init() { - if File_conf_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_conf_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Bootstrap); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Trace); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server_HTTP); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Server_GRPC); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data_Database); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conf_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Data_Redis); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_conf_proto_rawDesc, - NumEnums: 0, - NumMessages: 8, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_conf_proto_goTypes, - DependencyIndexes: file_conf_proto_depIdxs, - MessageInfos: file_conf_proto_msgTypes, - }.Build() - File_conf_proto = out.File - file_conf_proto_rawDesc = nil - file_conf_proto_goTypes = nil - file_conf_proto_depIdxs = nil -} diff --git a/examples/transaction/gorm/internal/conf/conf.proto b/examples/transaction/gorm/internal/conf/conf.proto deleted file mode 100644 index 491c21a13..000000000 --- a/examples/transaction/gorm/internal/conf/conf.proto +++ /dev/null @@ -1,49 +0,0 @@ -syntax = "proto3"; -package kratos.internal.conf; - -option go_package = "github.com/go-kratos/kratos/examples/blog/internal/conf;conf"; - -import "google/protobuf/duration.proto"; - -message Bootstrap { - Trace trace = 1; - Server server = 2; - Data data = 3; -} - -message Server { - message HTTP { - string network = 1; - string addr = 2; - google.protobuf.Duration timeout = 3; - } - message GRPC { - string network = 1; - string addr = 2; - google.protobuf.Duration timeout = 3; - } - HTTP http = 1; - GRPC grpc = 2; -} - -message Data { - message Database { - string driver = 1; - string source = 2; - } - message Redis { - string network = 1; - string addr = 2; - string password = 3; - int32 db = 4; - google.protobuf.Duration dial_timeout = 5; - google.protobuf.Duration read_timeout = 6; - google.protobuf.Duration write_timeout = 7; - } - Database database = 1; - Redis redis = 2; -} - -message Trace { - string endpoint = 1; -} \ No newline at end of file diff --git a/examples/transaction/gorm/internal/data/README.md b/examples/transaction/gorm/internal/data/README.md deleted file mode 100644 index a9f7e8dad..000000000 --- a/examples/transaction/gorm/internal/data/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Data - -``` -go generate ./ent -``` \ No newline at end of file diff --git a/examples/transaction/gorm/internal/data/data.go b/examples/transaction/gorm/internal/data/data.go deleted file mode 100644 index 031e4bb96..000000000 --- a/examples/transaction/gorm/internal/data/data.go +++ /dev/null @@ -1,71 +0,0 @@ -package data - -import ( - "context" - - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/biz" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/conf" - "github.com/go-kratos/kratos/v2/log" - "github.com/google/wire" - "gorm.io/driver/mysql" - "gorm.io/gorm" - - // init mysql driver - _ "github.com/go-sql-driver/mysql" -) - -// ProviderSet is data providers. -var ProviderSet = wire.NewSet(NewData, NewDB, NewTransaction, NewUserRepo, NewCardRepo) - -// Data . -type Data struct { - db *gorm.DB - log *log.Helper -} - -type contextTxKey struct{} - -func (d *Data) ExecTx(ctx context.Context, fn func(ctx context.Context) error) error { - return d.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { - ctx = context.WithValue(ctx, contextTxKey{}, tx) - return fn(ctx) - }) -} - -func (d *Data) DB(ctx context.Context) *gorm.DB { - tx, ok := ctx.Value(contextTxKey{}).(*gorm.DB) - if ok { - return tx - } - return d.db -} - -// NewTransaction . -func NewTransaction(d *Data) biz.Transaction { - return d -} - -// NewData . -func NewData(db *gorm.DB, logger log.Logger) (*Data, func(), error) { - l := log.NewHelper(log.With(logger, "module", "transaction/data")) - d := &Data{ - db: db, - log: l, - } - return d, func() { - }, nil -} - -// NewDB gorm Connecting to a Database -func NewDB(conf *conf.Data, logger log.Logger) *gorm.DB { - log := log.NewHelper(log.With(logger, "module", "order-service/data/gorm")) - - db, err := gorm.Open(mysql.Open(conf.Database.Source), &gorm.Config{}) - if err != nil { - log.Fatalf("failed opening connection to mysql: %v", err) - } - if err := db.AutoMigrate(&User{}, &Card{}); err != nil { - log.Fatal(err) - } - return db -} diff --git a/examples/transaction/gorm/internal/data/transaction.go b/examples/transaction/gorm/internal/data/transaction.go deleted file mode 100644 index 6e4b1d3c7..000000000 --- a/examples/transaction/gorm/internal/data/transaction.go +++ /dev/null @@ -1,64 +0,0 @@ -package data - -import ( - "context" - "time" - - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/biz" - "github.com/go-kratos/kratos/v2/log" -) - -type userRepo struct { - data *Data - log *log.Helper -} - -type cardRepo struct { - data *Data - log *log.Helper -} - -type User struct { - ID int64 - Name string - Email string - CreatedAt time.Time - UpdatedAt time.Time -} - -type Card struct { - ID int64 - UserID int64 - Money int64 - CreatedAt time.Time - UpdatedAt time.Time -} - -// NewUserRepo . -func NewUserRepo(data *Data, logger log.Logger) biz.UserRepo { - return &userRepo{ - data: data, - log: log.NewHelper(logger), - } -} - -func (u *userRepo) CreateUser(ctx context.Context, m *biz.User) (int64, error) { - user := User{Name: m.Name, Email: m.Email} - result := u.data.DB(ctx).Create(&user) - return user.ID, result.Error -} - -func NewCardRepo(data *Data, logger log.Logger) biz.CardRepo { - return &cardRepo{ - data: data, - log: log.NewHelper(logger), - } -} - -func (c *cardRepo) CreateCard(ctx context.Context, id int64) (int64, error) { - var card Card - card.UserID = id - card.Money = 1000 - result := c.data.DB(ctx).Save(&card) - return card.ID, result.Error -} diff --git a/examples/transaction/gorm/internal/server/grpc.go b/examples/transaction/gorm/internal/server/grpc.go deleted file mode 100644 index 44c568f94..000000000 --- a/examples/transaction/gorm/internal/server/grpc.go +++ /dev/null @@ -1,37 +0,0 @@ -package server - -import ( - v1 "github.com/go-kratos/kratos/examples/transaction/api/transaction/v1" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/conf" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/service" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/middleware/tracing" - "github.com/go-kratos/kratos/v2/middleware/validate" - "github.com/go-kratos/kratos/v2/transport/grpc" -) - -// NewGRPCServer new a gRPC server. -func NewGRPCServer(c *conf.Server, logger log.Logger, transaction *service.TransactionService) *grpc.Server { - opts := []grpc.ServerOption{ - grpc.Middleware( - recovery.Recovery(), - tracing.Server(), - logging.Server(logger), - validate.Validator(), - ), - } - if c.Grpc.Network != "" { - opts = append(opts, grpc.Network(c.Grpc.Network)) - } - if c.Grpc.Addr != "" { - opts = append(opts, grpc.Address(c.Grpc.Addr)) - } - if c.Grpc.Timeout != nil { - opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) - } - srv := grpc.NewServer(opts...) - v1.RegisterTransactionServiceServer(srv, transaction) - return srv -} diff --git a/examples/transaction/gorm/internal/server/http.go b/examples/transaction/gorm/internal/server/http.go deleted file mode 100644 index 2de797f2e..000000000 --- a/examples/transaction/gorm/internal/server/http.go +++ /dev/null @@ -1,37 +0,0 @@ -package server - -import ( - v1 "github.com/go-kratos/kratos/examples/transaction/api/transaction/v1" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/conf" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/service" - "github.com/go-kratos/kratos/v2/log" - "github.com/go-kratos/kratos/v2/middleware/logging" - "github.com/go-kratos/kratos/v2/middleware/recovery" - "github.com/go-kratos/kratos/v2/middleware/tracing" - "github.com/go-kratos/kratos/v2/middleware/validate" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// NewHTTPServer new a HTTP server. -func NewHTTPServer(c *conf.Server, logger log.Logger, transaction *service.TransactionService) *http.Server { - opts := []http.ServerOption{ - http.Middleware( - recovery.Recovery(), - tracing.Server(), - logging.Server(logger), - validate.Validator(), - ), - } - if c.Http.Network != "" { - opts = append(opts, http.Network(c.Http.Network)) - } - if c.Http.Addr != "" { - opts = append(opts, http.Address(c.Http.Addr)) - } - if c.Http.Timeout != nil { - opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration())) - } - srv := http.NewServer(opts...) - v1.RegisterTransactionServiceHTTPServer(srv, transaction) - return srv -} diff --git a/examples/transaction/gorm/internal/server/server.go b/examples/transaction/gorm/internal/server/server.go deleted file mode 100644 index 4d267a7a3..000000000 --- a/examples/transaction/gorm/internal/server/server.go +++ /dev/null @@ -1,8 +0,0 @@ -package server - -import ( - "github.com/google/wire" -) - -// ProviderSet is server providers. -var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer) diff --git a/examples/transaction/gorm/internal/service/README.md b/examples/transaction/gorm/internal/service/README.md deleted file mode 100644 index 42321b7b1..000000000 --- a/examples/transaction/gorm/internal/service/README.md +++ /dev/null @@ -1 +0,0 @@ -# Service diff --git a/examples/transaction/gorm/internal/service/service.go b/examples/transaction/gorm/internal/service/service.go deleted file mode 100644 index ad3e067d3..000000000 --- a/examples/transaction/gorm/internal/service/service.go +++ /dev/null @@ -1,20 +0,0 @@ -package service - -import ( - pb "github.com/go-kratos/kratos/examples/transaction/api/transaction/v1" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/biz" - - "github.com/go-kratos/kratos/v2/log" - "github.com/google/wire" -) - -// ProviderSet is service providers. -var ProviderSet = wire.NewSet(NewTransactionService) - -type TransactionService struct { - pb.UnimplementedTransactionServiceServer - - log *log.Helper - - user *biz.UserUsecase -} diff --git a/examples/transaction/gorm/internal/service/transaction.go b/examples/transaction/gorm/internal/service/transaction.go deleted file mode 100644 index 69d075481..000000000 --- a/examples/transaction/gorm/internal/service/transaction.go +++ /dev/null @@ -1,31 +0,0 @@ -package service - -import ( - "context" - "strconv" - - pb "github.com/go-kratos/kratos/examples/transaction/api/transaction/v1" - "github.com/go-kratos/kratos/examples/transaction/gorm/internal/biz" - - "github.com/go-kratos/kratos/v2/log" -) - -func NewTransactionService(user *biz.UserUsecase, logger log.Logger) *TransactionService { - return &TransactionService{ - user: user, - log: log.NewHelper(logger), - } -} - -func (b *TransactionService) CreateUser(ctx context.Context, in *pb.CreateUserRequest) (*pb.CreateUserReply, error) { - id, err := b.user.CreateUser(ctx, &biz.User{ - Name: in.Name, - Email: in.Email, - }) - if err != nil { - return nil, err - } - return &pb.CreateUserReply{ - Id: strconv.Itoa(id), - }, nil -} diff --git a/examples/transaction/gorm/openapi.yaml b/examples/transaction/gorm/openapi.yaml deleted file mode 100644 index c4afd3ba2..000000000 --- a/examples/transaction/gorm/openapi.yaml +++ /dev/null @@ -1,126 +0,0 @@ -# Generated with protoc-gen-openapi -# https://github.com/google/gnostic/tree/master/apps/protoc-gen-openapi - -openapi: 3.0.3 -info: - title: BlogService - version: 0.0.1 -paths: - /v1/article/: - get: - operationId: BlogService_ListArticle - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ListArticleReply' - post: - operationId: BlogService_CreateArticle - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CreateArticleRequest' - required: true - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateArticleReply' - /v1/article/{id}: - get: - operationId: BlogService_GetArticle - parameters: - - name: id - in: query - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/GetArticleReply' - put: - operationId: BlogService_UpdateArticle - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/UpdateArticleRequest' - required: true - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/UpdateArticleReply' - delete: - operationId: BlogService_DeleteArticle - parameters: - - name: id - in: query - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/DeleteArticleReply' -components: - schemas: - Article: - properties: - id: - type: integer - format: int64 - title: - type: string - content: - type: string - like: - type: integer - format: int64 - CreateArticleReply: - properties: - Article: - $ref: '#/components/schemas/Article' - CreateArticleRequest: - properties: - title: - type: string - content: - type: string - DeleteArticleReply: - properties: {} - GetArticleReply: - properties: - Article: - $ref: '#/components/schemas/Article' - ListArticleReply: - properties: - results: - type: array - items: - $ref: '#/components/schemas/Article' - UpdateArticleReply: - properties: - Article: - $ref: '#/components/schemas/Article' - UpdateArticleRequest: - properties: - id: - type: integer - format: int64 - title: - type: string - content: - type: string diff --git a/examples/transaction/openapi.yaml b/examples/transaction/openapi.yaml deleted file mode 100644 index e5401afcd..000000000 --- a/examples/transaction/openapi.yaml +++ /dev/null @@ -1,42 +0,0 @@ -# Generated with protoc-gen-openapi -# https://github.com/google/gnostic/tree/master/apps/protoc-gen-openapi - -openapi: 3.0.3 -info: - title: TransactionService API - version: 0.0.1 -paths: - /v1/transaction: - post: - tags: - - TransactionService - operationId: TransactionService_CreateUser - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CreateUserRequest' - required: true - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateUserReply' -components: - schemas: - CreateUserReply: - type: object - properties: - id: - type: string - CreateUserRequest: - type: object - properties: - name: - type: string - email: - type: string -tags: - - name: TransactionService diff --git a/examples/validate/api/example.pb.go b/examples/validate/api/example.pb.go deleted file mode 100644 index 341a1e049..000000000 --- a/examples/validate/api/example.pb.go +++ /dev/null @@ -1,387 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.13.0 -// source: example.proto - -package v1 - -import ( - _ "github.com/envoyproxy/protoc-gen-validate/validate" - _ "google.golang.org/genproto/googleapis/api/annotations" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Reply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` -} - -func (x *Reply) Reset() { - *x = Reply{} - if protoimpl.UnsafeEnabled { - mi := &file_example_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Reply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Reply) ProtoMessage() {} - -func (x *Reply) ProtoReflect() protoreflect.Message { - mi := &file_example_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Reply.ProtoReflect.Descriptor instead. -func (*Reply) Descriptor() ([]byte, []int) { - return file_example_proto_rawDescGZIP(), []int{0} -} - -func (x *Reply) GetMessage() string { - if x != nil { - return x.Message - } - return "" -} - -type Request struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - Age int32 `protobuf:"varint,2,opt,name=age,proto3" json:"age,omitempty"` - Code uint32 `protobuf:"varint,3,opt,name=code,proto3" json:"code,omitempty"` - Score float32 `protobuf:"fixed32,4,opt,name=score,proto3" json:"score,omitempty"` - State bool `protobuf:"varint,5,opt,name=state,proto3" json:"state,omitempty"` - Path string `protobuf:"bytes,6,opt,name=path,proto3" json:"path,omitempty"` - Phone string `protobuf:"bytes,7,opt,name=phone,proto3" json:"phone,omitempty"` - Explain string `protobuf:"bytes,8,opt,name=explain,proto3" json:"explain,omitempty"` - Name string `protobuf:"bytes,9,opt,name=name,proto3" json:"name,omitempty"` - Card string `protobuf:"bytes,10,opt,name=card,proto3" json:"card,omitempty"` - Info *Info `protobuf:"bytes,11,opt,name=info,proto3" json:"info,omitempty"` -} - -func (x *Request) Reset() { - *x = Request{} - if protoimpl.UnsafeEnabled { - mi := &file_example_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Request) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Request) ProtoMessage() {} - -func (x *Request) ProtoReflect() protoreflect.Message { - mi := &file_example_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Request.ProtoReflect.Descriptor instead. -func (*Request) Descriptor() ([]byte, []int) { - return file_example_proto_rawDescGZIP(), []int{1} -} - -func (x *Request) GetId() int64 { - if x != nil { - return x.Id - } - return 0 -} - -func (x *Request) GetAge() int32 { - if x != nil { - return x.Age - } - return 0 -} - -func (x *Request) GetCode() uint32 { - if x != nil { - return x.Code - } - return 0 -} - -func (x *Request) GetScore() float32 { - if x != nil { - return x.Score - } - return 0 -} - -func (x *Request) GetState() bool { - if x != nil { - return x.State - } - return false -} - -func (x *Request) GetPath() string { - if x != nil { - return x.Path - } - return "" -} - -func (x *Request) GetPhone() string { - if x != nil { - return x.Phone - } - return "" -} - -func (x *Request) GetExplain() string { - if x != nil { - return x.Explain - } - return "" -} - -func (x *Request) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *Request) GetCard() string { - if x != nil { - return x.Card - } - return "" -} - -func (x *Request) GetInfo() *Info { - if x != nil { - return x.Info - } - return nil -} - -type Info struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` -} - -func (x *Info) Reset() { - *x = Info{} - if protoimpl.UnsafeEnabled { - mi := &file_example_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Info) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Info) ProtoMessage() {} - -func (x *Info) ProtoReflect() protoreflect.Message { - mi := &file_example_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Info.ProtoReflect.Descriptor instead. -func (*Info) Descriptor() ([]byte, []int) { - return file_example_proto_rawDescGZIP(), []int{2} -} - -func (x *Info) GetAddress() string { - if x != nil { - return x.Address - } - return "" -} - -var File_example_proto protoreflect.FileDescriptor - -var file_example_proto_rawDesc = []byte{ - 0x0a, 0x0d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x0b, 0x61, 0x70, 0x69, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x1a, 0x1c, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x22, 0x21, 0x0a, 0x05, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, - 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x88, 0x03, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, - 0xfa, 0x42, 0x04, 0x22, 0x02, 0x20, 0x00, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1b, 0x0a, 0x03, 0x61, - 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x42, 0x09, 0xfa, 0x42, 0x06, 0x1a, 0x04, 0x10, - 0x78, 0x20, 0x00, 0x52, 0x03, 0x61, 0x67, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x42, 0x0b, 0xfa, 0x42, 0x08, 0x2a, 0x06, 0x30, 0x01, 0x30, - 0x02, 0x30, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x25, 0x0a, 0x05, 0x73, 0x63, 0x6f, - 0x72, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x02, 0x42, 0x0f, 0xfa, 0x42, 0x0c, 0x0a, 0x0a, 0x3d, - 0x00, 0x00, 0x00, 0x00, 0x3d, 0xe1, 0xfa, 0xc7, 0x42, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, - 0x12, 0x1d, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x42, - 0x07, 0xfa, 0x42, 0x04, 0x6a, 0x02, 0x08, 0x01, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, - 0x21, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0d, 0xfa, - 0x42, 0x0a, 0x72, 0x08, 0x0a, 0x06, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x04, 0x70, 0x61, - 0x74, 0x68, 0x12, 0x1e, 0x0a, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, - 0x09, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x72, 0x03, 0x98, 0x01, 0x0b, 0x52, 0x05, 0x70, 0x68, 0x6f, - 0x6e, 0x65, 0x12, 0x21, 0x0a, 0x07, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x69, 0x6e, 0x18, 0x08, 0x20, - 0x01, 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x03, 0x52, 0x07, 0x65, 0x78, - 0x70, 0x6c, 0x61, 0x69, 0x6e, 0x12, 0x1d, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x09, 0x20, - 0x01, 0x28, 0x09, 0x42, 0x09, 0xfa, 0x42, 0x06, 0x72, 0x04, 0x10, 0x01, 0x18, 0x0a, 0x52, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2a, 0x0a, 0x04, 0x63, 0x61, 0x72, 0x64, 0x18, 0x0a, 0x20, 0x01, - 0x28, 0x09, 0x42, 0x16, 0xfa, 0x42, 0x13, 0x72, 0x11, 0x32, 0x0f, 0x28, 0x3f, 0x69, 0x29, 0x5e, - 0x5b, 0x30, 0x2d, 0x39, 0x61, 0x2d, 0x66, 0x5d, 0x2b, 0x24, 0x52, 0x04, 0x63, 0x61, 0x72, 0x64, - 0x12, 0x2f, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x49, 0x6e, 0x66, - 0x6f, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x8a, 0x01, 0x02, 0x10, 0x01, 0x52, 0x04, 0x69, 0x6e, 0x66, - 0x6f, 0x22, 0x20, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, - 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, - 0x65, 0x73, 0x73, 0x32, 0x64, 0x0a, 0x0e, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x52, 0x0a, 0x0c, 0x54, 0x65, 0x73, 0x74, 0x56, 0x61, 0x6c, - 0x69, 0x64, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x61, 0x70, - 0x69, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, - 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x22, 0x0d, 0x2f, 0x76, 0x31, 0x2f, 0x76, 0x61, 0x6c, - 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x3a, 0x01, 0x2a, 0x42, 0x4c, 0x0a, 0x0f, 0x76, 0x61, 0x6c, - 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x50, 0x00, 0x5a, 0x37, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, - 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, - 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_example_proto_rawDescOnce sync.Once - file_example_proto_rawDescData = file_example_proto_rawDesc -) - -func file_example_proto_rawDescGZIP() []byte { - file_example_proto_rawDescOnce.Do(func() { - file_example_proto_rawDescData = protoimpl.X.CompressGZIP(file_example_proto_rawDescData) - }) - return file_example_proto_rawDescData -} - -var file_example_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_example_proto_goTypes = []interface{}{ - (*Reply)(nil), // 0: api.example.Reply - (*Request)(nil), // 1: api.example.Request - (*Info)(nil), // 2: api.example.Info -} -var file_example_proto_depIdxs = []int32{ - 2, // 0: api.example.Request.info:type_name -> api.example.Info - 1, // 1: api.example.ExampleService.TestValidate:input_type -> api.example.Request - 0, // 2: api.example.ExampleService.TestValidate:output_type -> api.example.Reply - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_example_proto_init() } -func file_example_proto_init() { - if File_example_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_example_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Reply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_example_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Request); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_example_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Info); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_example_proto_rawDesc, - NumEnums: 0, - NumMessages: 3, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_example_proto_goTypes, - DependencyIndexes: file_example_proto_depIdxs, - MessageInfos: file_example_proto_msgTypes, - }.Build() - File_example_proto = out.File - file_example_proto_rawDesc = nil - file_example_proto_goTypes = nil - file_example_proto_depIdxs = nil -} diff --git a/examples/validate/api/example.pb.validate.go b/examples/validate/api/example.pb.validate.go deleted file mode 100644 index ac0130ac5..000000000 --- a/examples/validate/api/example.pb.validate.go +++ /dev/null @@ -1,493 +0,0 @@ -// Code generated by protoc-gen-validate. DO NOT EDIT. -// source: example.proto - -package v1 - -import ( - "bytes" - "errors" - "fmt" - "net" - "net/mail" - "net/url" - "regexp" - "strings" - "time" - "unicode/utf8" - - "google.golang.org/protobuf/types/known/anypb" -) - -// ensure the imports are used -var ( - _ = bytes.MinRead - _ = errors.New("") - _ = fmt.Print - _ = utf8.UTFMax - _ = (*regexp.Regexp)(nil) - _ = (*strings.Reader)(nil) - _ = net.IPv4len - _ = time.Duration(0) - _ = (*url.URL)(nil) - _ = (*mail.Address)(nil) - _ = anypb.Any{} -) - -// Validate checks the field values on Reply with the rules defined in the -// proto definition for this message. If any rules are violated, the first -// error encountered is returned, or nil if there are no violations. -func (m *Reply) Validate() error { - return m.validate(false) -} - -// ValidateAll checks the field values on Reply with the rules defined in the -// proto definition for this message. If any rules are violated, the result is -// a list of violation errors wrapped in ReplyMultiError, or nil if none found. -func (m *Reply) ValidateAll() error { - return m.validate(true) -} - -func (m *Reply) validate(all bool) error { - if m == nil { - return nil - } - - var errors []error - - // no validation rules for Message - - if len(errors) > 0 { - return ReplyMultiError(errors) - } - return nil -} - -// ReplyMultiError is an error wrapping multiple validation errors returned by -// Reply.ValidateAll() if the designated constraints aren't met. -type ReplyMultiError []error - -// Error returns a concatenation of all the error messages it wraps. -func (m ReplyMultiError) Error() string { - var msgs []string - for _, err := range m { - msgs = append(msgs, err.Error()) - } - return strings.Join(msgs, "; ") -} - -// AllErrors returns a list of validation violation errors. -func (m ReplyMultiError) AllErrors() []error { return m } - -// ReplyValidationError is the validation error returned by Reply.Validate if -// the designated constraints aren't met. -type ReplyValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e ReplyValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e ReplyValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e ReplyValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e ReplyValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e ReplyValidationError) ErrorName() string { return "ReplyValidationError" } - -// Error satisfies the builtin error interface -func (e ReplyValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sReply.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = ReplyValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = ReplyValidationError{} - -// Validate checks the field values on Request with the rules defined in the -// proto definition for this message. If any rules are violated, the first -// error encountered is returned, or nil if there are no violations. -func (m *Request) Validate() error { - return m.validate(false) -} - -// ValidateAll checks the field values on Request with the rules defined in the -// proto definition for this message. If any rules are violated, the result is -// a list of violation errors wrapped in RequestMultiError, or nil if none found. -func (m *Request) ValidateAll() error { - return m.validate(true) -} - -func (m *Request) validate(all bool) error { - if m == nil { - return nil - } - - var errors []error - - if m.GetId() <= 0 { - err := RequestValidationError{ - field: "Id", - reason: "value must be greater than 0", - } - if !all { - return err - } - errors = append(errors, err) - } - - if val := m.GetAge(); val <= 0 || val >= 120 { - err := RequestValidationError{ - field: "Age", - reason: "value must be inside range (0, 120)", - } - if !all { - return err - } - errors = append(errors, err) - } - - if _, ok := _Request_Code_InLookup[m.GetCode()]; !ok { - err := RequestValidationError{ - field: "Code", - reason: "value must be in list [1 2 3]", - } - if !all { - return err - } - errors = append(errors, err) - } - - if _, ok := _Request_Score_NotInLookup[m.GetScore()]; ok { - err := RequestValidationError{ - field: "Score", - reason: "value must not be in list [0 99.99]", - } - if !all { - return err - } - errors = append(errors, err) - } - - if m.GetState() != true { - err := RequestValidationError{ - field: "State", - reason: "value must equal true", - } - if !all { - return err - } - errors = append(errors, err) - } - - if m.GetPath() != "/hello" { - err := RequestValidationError{ - field: "Path", - reason: "value must equal /hello", - } - if !all { - return err - } - errors = append(errors, err) - } - - if utf8.RuneCountInString(m.GetPhone()) != 11 { - err := RequestValidationError{ - field: "Phone", - reason: "value length must be 11 runes", - } - if !all { - return err - } - errors = append(errors, err) - - } - - if utf8.RuneCountInString(m.GetExplain()) < 3 { - err := RequestValidationError{ - field: "Explain", - reason: "value length must be at least 3 runes", - } - if !all { - return err - } - errors = append(errors, err) - } - - if l := utf8.RuneCountInString(m.GetName()); l < 1 || l > 10 { - err := RequestValidationError{ - field: "Name", - reason: "value length must be between 1 and 10 runes, inclusive", - } - if !all { - return err - } - errors = append(errors, err) - } - - if !_Request_Card_Pattern.MatchString(m.GetCard()) { - err := RequestValidationError{ - field: "Card", - reason: "value does not match regex pattern \"(?i)^[0-9a-f]+$\"", - } - if !all { - return err - } - errors = append(errors, err) - } - - if m.GetInfo() == nil { - err := RequestValidationError{ - field: "Info", - reason: "value is required", - } - if !all { - return err - } - errors = append(errors, err) - } - - if all { - switch v := interface{}(m.GetInfo()).(type) { - case interface{ ValidateAll() error }: - if err := v.ValidateAll(); err != nil { - errors = append(errors, RequestValidationError{ - field: "Info", - reason: "embedded message failed validation", - cause: err, - }) - } - case interface{ Validate() error }: - if err := v.Validate(); err != nil { - errors = append(errors, RequestValidationError{ - field: "Info", - reason: "embedded message failed validation", - cause: err, - }) - } - } - } else if v, ok := interface{}(m.GetInfo()).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return RequestValidationError{ - field: "Info", - reason: "embedded message failed validation", - cause: err, - } - } - } - - if len(errors) > 0 { - return RequestMultiError(errors) - } - return nil -} - -// RequestMultiError is an error wrapping multiple validation errors returned -// by Request.ValidateAll() if the designated constraints aren't met. -type RequestMultiError []error - -// Error returns a concatenation of all the error messages it wraps. -func (m RequestMultiError) Error() string { - var msgs []string - for _, err := range m { - msgs = append(msgs, err.Error()) - } - return strings.Join(msgs, "; ") -} - -// AllErrors returns a list of validation violation errors. -func (m RequestMultiError) AllErrors() []error { return m } - -// RequestValidationError is the validation error returned by Request.Validate -// if the designated constraints aren't met. -type RequestValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e RequestValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e RequestValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e RequestValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e RequestValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e RequestValidationError) ErrorName() string { return "RequestValidationError" } - -// Error satisfies the builtin error interface -func (e RequestValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sRequest.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = RequestValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = RequestValidationError{} - -var _Request_Code_InLookup = map[uint32]struct{}{ - 1: {}, - 2: {}, - 3: {}, -} - -var _Request_Score_NotInLookup = map[float32]struct{}{ - 0: {}, - 99.99: {}, -} - -var _Request_Card_Pattern = regexp.MustCompile("(?i)^[0-9a-f]+$") - -// Validate checks the field values on Info with the rules defined in the proto -// definition for this message. If any rules are violated, the first error -// encountered is returned, or nil if there are no violations. -func (m *Info) Validate() error { - return m.validate(false) -} - -// ValidateAll checks the field values on Info with the rules defined in the -// proto definition for this message. If any rules are violated, the result is -// a list of violation errors wrapped in InfoMultiError, or nil if none found. -func (m *Info) ValidateAll() error { - return m.validate(true) -} - -func (m *Info) validate(all bool) error { - if m == nil { - return nil - } - - var errors []error - - // no validation rules for Address - - if len(errors) > 0 { - return InfoMultiError(errors) - } - return nil -} - -// InfoMultiError is an error wrapping multiple validation errors returned by -// Info.ValidateAll() if the designated constraints aren't met. -type InfoMultiError []error - -// Error returns a concatenation of all the error messages it wraps. -func (m InfoMultiError) Error() string { - var msgs []string - for _, err := range m { - msgs = append(msgs, err.Error()) - } - return strings.Join(msgs, "; ") -} - -// AllErrors returns a list of validation violation errors. -func (m InfoMultiError) AllErrors() []error { return m } - -// InfoValidationError is the validation error returned by Info.Validate if the -// designated constraints aren't met. -type InfoValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e InfoValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e InfoValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e InfoValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e InfoValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e InfoValidationError) ErrorName() string { return "InfoValidationError" } - -// Error satisfies the builtin error interface -func (e InfoValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sInfo.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = InfoValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = InfoValidationError{} diff --git a/examples/validate/api/example.proto b/examples/validate/api/example.proto deleted file mode 100644 index 35cc6e771..000000000 --- a/examples/validate/api/example.proto +++ /dev/null @@ -1,43 +0,0 @@ -syntax = "proto3"; - -package api.example; - -option go_package = "github.com/go-kratos/kratos/examples/validate/api/v1;v1"; -option java_multiple_files = true; -option java_package = "validate.api.v1"; - -import "google/api/annotations.proto"; -// the validate rules: -// https://github.com/envoyproxy/protoc-gen-validate -import "validate/validate.proto"; - -service ExampleService { - rpc TestValidate (Request) returns (Reply) { - option (google.api.http) = { - post: "/v1/validate" - body: "*" - }; - } -} - -message Reply { - string message = 1; -} - -message Request { - int64 id = 1 [(validate.rules).int64 = {gt: 0}]; - int32 age = 2 [(validate.rules).int32 = {gt:0, lt: 120}]; - uint32 code = 3 [(validate.rules).uint32 = {in: [1,2,3]}]; - float score = 4 [(validate.rules).float = {not_in: [0, 99.99]}]; - bool state = 5 [(validate.rules).bool.const = true]; - string path = 6 [(validate.rules).string.const = "/hello"]; - string phone = 7 [(validate.rules).string.len = 11]; - string explain = 8 [(validate.rules).string.min_len = 3]; - string name = 9 [(validate.rules).string = {min_len: 1, max_len: 10}]; - string card = 10 [(validate.rules).string.pattern = "(?i)^[0-9a-f]+$"]; - Info info = 11 [(validate.rules).message.required = true]; -} - -message Info { - string address = 1; -} \ No newline at end of file diff --git a/examples/validate/api/example_grpc.pb.go b/examples/validate/api/example_grpc.pb.go deleted file mode 100644 index 90fe42ce2..000000000 --- a/examples/validate/api/example_grpc.pb.go +++ /dev/null @@ -1,101 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package v1 - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// ExampleServiceClient is the client API for ExampleService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type ExampleServiceClient interface { - TestValidate(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) -} - -type exampleServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewExampleServiceClient(cc grpc.ClientConnInterface) ExampleServiceClient { - return &exampleServiceClient{cc} -} - -func (c *exampleServiceClient) TestValidate(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) { - out := new(Reply) - err := c.cc.Invoke(ctx, "/api.example.ExampleService/TestValidate", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// ExampleServiceServer is the server API for ExampleService service. -// All implementations must embed UnimplementedExampleServiceServer -// for forward compatibility -type ExampleServiceServer interface { - TestValidate(context.Context, *Request) (*Reply, error) - mustEmbedUnimplementedExampleServiceServer() -} - -// UnimplementedExampleServiceServer must be embedded to have forward compatible implementations. -type UnimplementedExampleServiceServer struct { -} - -func (UnimplementedExampleServiceServer) TestValidate(context.Context, *Request) (*Reply, error) { - return nil, status.Errorf(codes.Unimplemented, "method TestValidate not implemented") -} -func (UnimplementedExampleServiceServer) mustEmbedUnimplementedExampleServiceServer() {} - -// UnsafeExampleServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to ExampleServiceServer will -// result in compilation errors. -type UnsafeExampleServiceServer interface { - mustEmbedUnimplementedExampleServiceServer() -} - -func RegisterExampleServiceServer(s grpc.ServiceRegistrar, srv ExampleServiceServer) { - s.RegisterService(&ExampleService_ServiceDesc, srv) -} - -func _ExampleService_TestValidate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(Request) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ExampleServiceServer).TestValidate(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/api.example.ExampleService/TestValidate", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ExampleServiceServer).TestValidate(ctx, req.(*Request)) - } - return interceptor(ctx, in, info, handler) -} - -// ExampleService_ServiceDesc is the grpc.ServiceDesc for ExampleService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var ExampleService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "api.example.ExampleService", - HandlerType: (*ExampleServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "TestValidate", - Handler: _ExampleService_TestValidate_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "example.proto", -} diff --git a/examples/validate/api/example_http.pb.go b/examples/validate/api/example_http.pb.go deleted file mode 100644 index 9b32eb94a..000000000 --- a/examples/validate/api/example_http.pb.go +++ /dev/null @@ -1,71 +0,0 @@ -// Code generated by protoc-gen-go-http. DO NOT EDIT. -// versions: -// protoc-gen-go-http v2.0.0 - -package v1 - -import ( - context "context" - http "github.com/go-kratos/kratos/v2/transport/http" - binding "github.com/go-kratos/kratos/v2/transport/http/binding" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the kratos package it is being compiled against. -var _ = new(context.Context) -var _ = binding.EncodeURL - -const _ = http.SupportPackageIsVersion1 - -type ExampleServiceHTTPServer interface { - TestValidate(context.Context, *Request) (*Reply, error) -} - -func RegisterExampleServiceHTTPServer(s *http.Server, srv ExampleServiceHTTPServer) { - r := s.Route("/") - r.POST("/v1/validate", _ExampleService_TestValidate0_HTTP_Handler(srv)) -} - -func _ExampleService_TestValidate0_HTTP_Handler(srv ExampleServiceHTTPServer) func(ctx http.Context) error { - return func(ctx http.Context) error { - var in Request - if err := ctx.Bind(&in); err != nil { - return err - } - http.SetOperation(ctx, "/api.example.ExampleService/TestValidate") - h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.TestValidate(ctx, req.(*Request)) - }) - out, err := h(ctx, &in) - if err != nil { - return err - } - reply := out.(*Reply) - return ctx.Result(200, reply) - } -} - -type ExampleServiceHTTPClient interface { - TestValidate(ctx context.Context, req *Request, opts ...http.CallOption) (rsp *Reply, err error) -} - -type ExampleServiceHTTPClientImpl struct { - cc *http.Client -} - -func NewExampleServiceHTTPClient(client *http.Client) ExampleServiceHTTPClient { - return &ExampleServiceHTTPClientImpl{client} -} - -func (c *ExampleServiceHTTPClientImpl) TestValidate(ctx context.Context, in *Request, opts ...http.CallOption) (*Reply, error) { - var out Reply - pattern := "/v1/validate" - path := binding.EncodeURL(pattern, in, false) - opts = append(opts, http.Operation("/api.example.ExampleService/TestValidate")) - opts = append(opts, http.PathTemplate(pattern)) - err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) - if err != nil { - return nil, err - } - return &out, err -} diff --git a/examples/validate/main.go b/examples/validate/main.go deleted file mode 100644 index 58904e8f1..000000000 --- a/examples/validate/main.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "context" - "log" - - v1 "github.com/go-kratos/kratos/examples/validate/api" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/middleware/validate" - "github.com/go-kratos/kratos/v2/transport/grpc" - "github.com/go-kratos/kratos/v2/transport/http" -) - -// go build -ldflags "-X main.Version=x.y.z" -var ( - // Name is the name of the compiled software. - Name = "errors" - // Version is the version of the compiled software. - // Version = "v1.0.0" -) - -type server struct { - v1.UnimplementedExampleServiceServer -} - -func (s *server) TestValidate(ctx context.Context, in *v1.Request) (*v1.Reply, error) { - return &v1.Reply{Message: "ok"}, nil -} - -func main() { - s := &server{} - grpcSrv := grpc.NewServer( - grpc.Address(":9000"), - grpc.Middleware( - validate.Validator(), - )) - httpSrv := http.NewServer( - http.Address(":8000"), - http.Middleware( - validate.Validator(), - )) - v1.RegisterExampleServiceServer(grpcSrv, s) - v1.RegisterExampleServiceHTTPServer(httpSrv, s) - app := kratos.New( - kratos.Name(Name), - kratos.Server( - grpcSrv, - httpSrv, - ), - ) - - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/examples/ws/client/client.go b/examples/ws/client/client.go deleted file mode 100644 index f9d090dab..000000000 --- a/examples/ws/client/client.go +++ /dev/null @@ -1,76 +0,0 @@ -package main - -import ( - "flag" - "log" - "net/url" - "os" - "os/signal" - "time" - - "github.com/gorilla/websocket" -) - -var addr = flag.String("addr", "localhost:8080", "http service address") - -func main() { - flag.Parse() - log.SetFlags(0) - - interrupt := make(chan os.Signal, 1) - signal.Notify(interrupt, os.Interrupt) - - u := url.URL{Scheme: "ws", Host: *addr, Path: "/ws"} - log.Printf("connecting to %s", u.String()) - - c, _, err := websocket.DefaultDialer.Dial(u.String(), nil) - if err != nil { - log.Fatal("dial:", err) - } - defer c.Close() - - done := make(chan struct{}) - - go func() { - defer close(done) - for { - _, message, err := c.ReadMessage() - if err != nil { - log.Println("read:", err) - return - } - log.Printf("recv: %s", message) - } - }() - - ticker := time.NewTicker(time.Second) - defer ticker.Stop() - - for { - select { - case <-done: - return - case t := <-ticker.C: - err := c.WriteMessage(websocket.TextMessage, []byte(t.String())) - if err != nil { - log.Println("write:", err) - return - } - case <-interrupt: - log.Println("interrupt") - - // Cleanly close the connection by sending a close message and then - // waiting (with timeout) for the server to close the connection. - err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) - if err != nil { - log.Println("write close:", err) - return - } - select { - case <-done: - case <-time.After(time.Second): - } - return - } - } -} diff --git a/examples/ws/handler/handler.go b/examples/ws/handler/handler.go deleted file mode 100644 index 139be8e99..000000000 --- a/examples/ws/handler/handler.go +++ /dev/null @@ -1,32 +0,0 @@ -package handler - -import ( - "log" - "net/http" - - "github.com/gorilla/websocket" -) - -var upgrader = websocket.Upgrader{} - -func WsHandler(w http.ResponseWriter, r *http.Request) { - c, err := upgrader.Upgrade(w, r, nil) - if err != nil { - log.Print("upgrade:", err) - return - } - defer c.Close() - for { - mt, message, err := c.ReadMessage() - if err != nil { - log.Println("read:", err) - break - } - log.Printf("recv: %s", message) - err = c.WriteMessage(mt, message) - if err != nil { - log.Println("write:", err) - break - } - } -} diff --git a/examples/ws/main.go b/examples/ws/main.go deleted file mode 100644 index 92a08bf22..000000000 --- a/examples/ws/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "log" - - "github.com/go-kratos/kratos/examples/ws/handler" - "github.com/go-kratos/kratos/v2" - "github.com/go-kratos/kratos/v2/transport/http" - "github.com/gorilla/mux" -) - -func main() { - router := mux.NewRouter() - router.HandleFunc("/ws", handler.WsHandler) - - httpSrv := http.NewServer(http.Address(":8080")) - httpSrv.HandlePrefix("/", router) - - app := kratos.New( - kratos.Name("ws"), - kratos.Server( - httpSrv, - ), - ) - if err := app.Run(); err != nil { - log.Println(err) - } -}