Compare commits

..

475 Commits

Author SHA1 Message Date
LinXiaoWei bffc1a0989
feat(transport): add endpoint option for server (#2904) 1 year ago
包子 32b1d13f90
deps: upgrade kratos version to v2.6.3 (#2903) 1 year ago
dependabot[bot] db2a565d1c
build(deps): bump github.com/prometheus/common (#2840) 1 year ago
jessetang fcd3b18e83
fix(encoding/form): failed to decode the map type (#2468) 1 year ago
freezeChen 3445f3ea8e
fix: logging middle don't get trace_id value when logger is filterLogger (#2869) 1 year ago
Tony Chen 32c0d2dd97
feat: add omitempty prefix to rule path (#2870) 1 year ago
xu0o0 e86ad248c3
fix(cli): fix import path with `--nomod` (#2775) 1 year ago
liaochuntao 69d73225a9
update polaris-standalone docker image (#2854) 1 year ago
Fengbin Shi 49ffd95a0c
fix: http parse pb message body panic (#2847) 1 year ago
haiyux 96480c11ee
fix: fix go import path when add project --nomod (#2837) 2 years ago
dependabot[bot] 1d50f50262
build(deps): bump actions/setup-go from 4.0.0 to 4.0.1 (#2829) 2 years ago
dependabot[bot] 6d741828c2
build(deps): bump google.golang.org/grpc in /contrib/opensergo (#2823) 2 years ago
Xudong Cai 4a56b5669d
chore: remove the dependency of grpc_testing module (#2824) 2 years ago
包子 56777ee655
deps: upgrade kratos version to v2.6.2 (#2817) 2 years ago
dependabot[bot] b1cd1d3cf8
build(deps): bump google.golang.org/grpc in /contrib/config/etcd (#2767) 2 years ago
dependabot[bot] 37a521d59f
build(deps): bump google.golang.org/grpc in /contrib/opensergo (#2768) 2 years ago
dependabot[bot] 6cf407b9bd
build(deps): bump github.com/prometheus/client_golang (#2787) 2 years ago
dependabot[bot] a904794546
build(deps): bump github.com/aliyun/aliyun-log-go-sdk (#2807) 2 years ago
chen quan a837603c6d
chore: embedding template (#2810) 2 years ago
dependabot[bot] 0b1fdbe51c
build(deps): bump go.etcd.io/etcd/client/v3 in /contrib/config/etcd (#2788) 2 years ago
dependabot[bot] 81988e6a85
build(deps): bump go.etcd.io/etcd/client/v3 in /contrib/registry/etcd (#2789) 2 years ago
Haibo 1f10166028
fix(tracing): use global provider by default, but allow custom providers (#2803) 2 years ago
dependabot[bot] c6a4604839
build(deps): bump github.com/hashicorp/consul/api (#2731) 2 years ago
Bin aed172b8dd
feat: jwt KeyFunc external return (#2809) 2 years ago
dependabot[bot] 520b321fe9
build(deps): bump golang.org/x/net in /contrib/opensergo (#2779) 2 years ago
ibrahim albarghouthi 3958f9d5c0
refactor: metadata supports key corresponding to multiple values (#2772) 2 years ago
dependabot[bot] e9870cb48f
build(deps): bump github.com/hashicorp/consul/api (#2733) 2 years ago
dependabot[bot] f8c19c37af
build(deps): bump google.golang.org/protobuf in /contrib/log/aliyun (#2751) 2 years ago
woniu317 d0847cd462
feat: log helper support sprint option (#2616) 2 years ago
jessetang f03f5f8988
fix(middleware/tracing): golang filename modify (#2727) 2 years ago
jessetang d470886977
refactor(transport): format import and init slice cap (#2741) 2 years ago
Bin 446774f9e5
fix:proto nesting causes template generation problems (#2718) 2 years ago
yonwoo9 e273c5188a
chore: update comment (#2747) 2 years ago
jessetang 393bf4dbcb
fix(contrib/registry/servicecomb): wrong stop ticker (#2749) 2 years ago
虫子樱桃 6a4d17d79a
add http.ResponseController type alias (#2713) 2 years ago
Bin 99ccd00434
fix: package path to filepath (#2672) 2 years ago
dependabot[bot] f47a238478
build(deps): bump k8s.io/client-go in /contrib/config/kubernetes (#2756) 2 years ago
dependabot[bot] 3d1af9af38
build(deps): bump k8s.io/apimachinery in /contrib/config/kubernetes (#2757) 2 years ago
jessetang 9a973d29c2
fix: rectification of non-standard lint codes (#2746) 2 years ago
jessetang 0c2d2632ac
fix(transport/grpc/resolver/discovery/resolver.go): remove attributes.Attributes.New() (#2742) 2 years ago
包子 78a2089f2b
feat: issue translate (#2744) 2 years ago
Xin d05729399e
fix: change the working directory of the command (#2560) 2 years ago
包子 8af9ca33bd
feat: support grpc balancer health check (#2736) 2 years ago
dependabot[bot] bd26120ec6
build(deps): bump actions/setup-go from 3.5.0 to 4.0.0 (#2737) 2 years ago
jessetang 6369db2e8e
fix(cmd/kratos/internal/base/repo.go): missing error (#2734) 2 years ago
jessetang 492248d032
fix(cmd): import format (#2735) 2 years ago
虫子樱桃 ae4dd7f4a8
fix: refactor project creation params process (#2714) 2 years ago
包子 33cb4576e9
Update Makefile (#2725) 2 years ago
包子 768ffd71d4
fix(grpc/balancer): fix the problem that the watch log cannot be closed (#2726) 2 years ago
jessetang 9ee4fcb48a
fix: remove repeat `net/http` package (#2708) 2 years ago
jessetang ae2dcb04c0
fix: markdown form format (#2721) 2 years ago
Xin 6602dc325e
fix: correct message of CmdServer (#2724) 2 years ago
包子 7eca8f8034
deps: upgrade kratos version to v2.6.1 (#2716) 2 years ago
yonwoo9 665a72e67f
fix: fix contrib registry eureka watcher as *watcher (#2693) 2 years ago
包子 a672980a15
fix: upgrade go.sum (#2715) 2 years ago
dependabot[bot] 51fac4ff90
build(deps): bump k8s.io/client-go in /contrib/config/kubernetes (#2695) 2 years ago
dependabot[bot] 9c7182058e
build(deps): bump github.com/hashicorp/consul/api (#2688) 2 years ago
dependabot[bot] 91be9c1071
build(deps): bump k8s.io/apimachinery in /contrib/config/kubernetes (#2694) 2 years ago
dependabot[bot] a11002d7ee
build(deps): bump github.com/hashicorp/consul/api (#2685) 2 years ago
dependabot[bot] 15de2007c7
build(deps): bump golang.org/x/sync in /contrib/registry/zookeeper (#2687) 2 years ago
dependabot[bot] 1579155a2c
build(deps): bump golang.org/x/net in /contrib/opensergo (#2699) 2 years ago
dependabot[bot] 51a34df0a6
build(deps): bump golang.org/x/net in /contrib/config/polaris (#2706) 2 years ago
dependabot[bot] 61176708e6
build(deps): bump golang.org/x/net (#2703) 2 years ago
dependabot[bot] b79c142580
build(deps): bump golang.org/x/net in /contrib/polaris (#2705) 2 years ago
dependabot[bot] f458e2535f
build(deps): bump github.com/prometheus/common (#2698) 2 years ago
dependabot[bot] 8203a90047
build(deps): bump golang.org/x/net in /contrib/registry/servicecomb (#2704) 2 years ago
dependabot[bot] c65f823c38
build(deps): bump golang.org/x/text in /cmd/protoc-gen-go-errors (#2675) 2 years ago
dependabot[bot] a6c9fdd9d3
build(deps): bump golang.org/x/text in /contrib/opensergo (#2678) 2 years ago
dependabot[bot] 7e89bbd799
build(deps): bump golang.org/x/text in /contrib/polaris (#2679) 2 years ago
包子 834b781ee2
feat: support load balance for streaming connection creation (#2669) 2 years ago
hoslo 19f008b483
feat: Add latency to the recover handler context (#2653) 2 years ago
180909 e4595db3d8
fix: cmd `proto add` nil pointer (#2670) 2 years ago
dependabot[bot] e33d644a78
build(deps): bump golang.org/x/text from 0.3.7 to 0.3.8 in /cmd/kratos (#2676) 2 years ago
180909 d8d231e725
fix(selector): version NodeFilter append func (#2671) 2 years ago
weetime bab67facad
fix(contrib): fix eureka server load too high (#2546) 2 years ago
thinkgo d0b1d84850
feat: add comment to http server interface method (#2657) 2 years ago
dependabot[bot] 54f19c1dcb
build(deps): bump github.com/prometheus/common (#2668) 2 years ago
dependabot[bot] 8d5010495a
build(deps): bump google.golang.org/grpc in /contrib/config/etcd (#2662) 2 years ago
jessetang 6330a5688e
chore: replace deprecated method (#2667) 2 years ago
包子 27eadd83b4
fix: polaris get service name (#2615) 2 years ago
YuanXin Hu 0a076443cb
feat: support polaris ratelimit ability (#2586) 2 years ago
aveyuan 7def38acde
feat(log): update zap interface (#2620) 2 years ago
LiuDui 77abb6356f
chore: update pull request template (#2649) 2 years ago
包子 50da181d69
fix: do not re register after service logout (#2647) 2 years ago
包子 a006328db6
fix: polaris temporarily delete the watch test (#2652) 2 years ago
leyou240 613282b096
chore(ci): update go.yaml support golang 1.20 (#2651) 2 years ago
LiuDui 08f37391e1
chore: clean up deprecated code (#2648) 2 years ago
cui fliter 239121155d
chore: fix comment (#2645) 2 years ago
jerjjj b242403bc1
update gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b to 3.0.0 (#2630) 2 years ago
Kevin Wan 63b23af418
chore: update go-zero link in readme (#2628) 2 years ago
liyaopinner 35800916dc
feat: add grpc client stream interceptor opts (#2610) 2 years ago
longxboy bebea0c103
feat: add subset alg for instances (#2613) 2 years ago
虫子樱桃 61744753eb
fix: project creation `--nomod` (#2611) 2 years ago
桂后昌 b2689af39c
feat(transport/http): request body read multiple times (#2542) 2 years ago
180909 e22775cfcc
chore(transport): fix the test name (#2543) 2 years ago
cui fliter 9cc1047c75
chore: fix a few function names on comments (#2430) 2 years ago
包子 7e896ae4c0
feat: support polaris service governance (#2605) 2 years ago
包子 33d51a84c3
feat(registry): consul support re-registry when service does not exist (#2606) 2 years ago
longxboy eafbe908a8
feat:add buf apis (#2604) 2 years ago
dependabot[bot] f49ac647e8
build(deps): bump github.com/aliyun/aliyun-log-go-sdk (#2598) 2 years ago
baeNewJeans 65c51594f9
fix(contrib/registry/etcd): rewatch when error occur (#2603) 2 years ago
包子 480b16b817
feat: grpc use the admin api (#2596) 2 years ago
dependabot[bot] b26023888d
build(deps): bump github.com/hashicorp/consul/api (#2561) 2 years ago
刘思圆 a3f24ee704
fix(contrib/log/tencent): tencentcloud-cls-sdk-go 为异步上传,需要显式调用"Start"方法开启才会生效 (#2514) 2 years ago
Remember 271b6c2924
fix(consul):return err if ctx is done (#2550) 2 years ago
Luckystar c442a320a0
feat: support for windows make install (#2554) 2 years ago
soukengo b0db594829
fix(registry): add zookeeper exists watcher when the node does not exist (#2555) 2 years ago
dependabot[bot] 33fff02a62
build(deps): bump github.com/aliyun/aliyun-log-go-sdk (#2577) 2 years ago
Juan C. Yamacho H d12498ed38
feat(middleware): redacter interface for logging (#2564) 2 years ago
虫子樱桃 852a77faa6
Feat project create with dir name add test (#2576) 2 years ago
dependabot[bot] 6f78ccacd9
build(deps): bump k8s.io/apimachinery in /contrib/config/kubernetes (#2581) 2 years ago
dependabot[bot] 2c3fab50a3
build(deps): bump actions/setup-go from 3.3.1 to 3.5.0 (#2585) 2 years ago
dependabot[bot] 2a9808df14
build(deps): bump github.com/polarismesh/polaris-go (#2589) 2 years ago
dependabot[bot] 89d8eeba62
build(deps): bump github.com/apolloconfig/agollo/v4 (#2591) 2 years ago
dependabot[bot] a017ab0957
build(deps): bump github.com/hashicorp/consul/api (#2563) 2 years ago
baozhecheng a45f3afdff Revert "feat: support polaris service governance" 2 years ago
baozhecheng b67d514bfa feat: support polaris service governance 2 years ago
Xingwang Liu facafba64a
fix(registry): ServiceInstance does not implement an Equal method for grpc Attributes. (#2575) 2 years ago
baozhecheng e36612e9ca Revert "fix issue:#2358 Support for creating a project with specifying the name for its place dir (#2573)" 2 years ago
虫子樱桃 3d322fe6c1
fix issue:#2358 Support for creating a project with specifying the name for its place dir (#2573) 2 years ago
woniu317 2cf82fa4a7
feat: consul registry support get services from multiple datacenters (#2536) 2 years ago
jessetang 3393990cd8
test(encoding/form/encode): add test and fix code style (#2539) 2 years ago
dependabot[bot] 3c3829795c
build(deps): bump github.com/aliyun/aliyun-log-go-sdk (#2548) 2 years ago
Ccheers 8732b76386
fix(circuitbreaker): add WithCircuitBreaker to fix WithGroup is useless (#2535) 2 years ago
Aurélien Perrier d779faf091
feat(transport/grpc): support custom healthcheck (#2541) 2 years ago
qshuai a82c82d49f
fix(config): fix codec NPE as parsing format wrongly, fix #2517 (#2518) 2 years ago
180909 c530d63e75
chore(cmd): use t.Cleanup (#2537) 2 years ago
包子 a7bae93ee0
deps: upgrade kratos version to v2.5.3 (#2500) 2 years ago
dependabot[bot] b339ae8956
build(deps): bump github.com/apolloconfig/agollo/v4 (#2421) 2 years ago
dependabot[bot] 3f698aa2c0
build(deps): bump go.etcd.io/etcd/client/v3 in /contrib/registry/etcd (#2384) 2 years ago
dependabot[bot] c5888ff464
build(deps): bump google.golang.org/grpc in /contrib/opensergo (#2452) 2 years ago
dependabot[bot] 878eca54ab
build(deps): bump google.golang.org/grpc in /contrib/config/etcd (#2453) 2 years ago
yeqown 275f815e40
typo: correct var name (#2496) 2 years ago
Cluas 383f28faeb
fix(selector): set global do not work (#2489) 2 years ago
dependabot[bot] e9ef3eea2d
build(deps): bump github.com/hashicorp/consul/api (#2472) 2 years ago
dependabot[bot] 58d9e3be56
build(deps): bump github.com/prometheus/client_golang (#2494) 2 years ago
dependabot[bot] 818452dd53
build(deps): bump github.com/polarismesh/polaris-go (#2493) 2 years ago
dependabot[bot] 699f0304ed
build(deps): bump github.com/aliyun/aliyun-log-go-sdk (#2492) 2 years ago
dependabot[bot] c888d50cc5
build(deps): bump google.golang.org/grpc in /contrib/registry/etcd (#2454) 2 years ago
jessetang a1a2b9dbd9
test(encoding/form): add unit test and code style modift (#2467) 2 years ago
JellyTony 590c469081
feat: add app Before and Afters option (#2403) 2 years ago
Miguel Martínez Triviño 0f38511ea8
fix(filter): filter out keyvals if keyFunc is provided (#2484) 2 years ago
jessetang 511f1917ce
fix(contrib/log): test case error (#2487) 2 years ago
jessetang 2a65502be2
style(config): code style tweaks and abstracts some methods (#2465) 2 years ago
dependabot[bot] 03d9494b19
build(deps): bump github.com/hashicorp/consul/api (#2473) 2 years ago
dependabot[bot] c4c1ebab47
build(deps): bump github.com/aliyun/aliyun-log-go-sdk (#2483) 2 years ago
Tony Chen f0878b0a78
fix ewma panic (#2480) 2 years ago
jessetang 3c65f16737
style(contrib/config): code style modify (#2475) 2 years ago
包子 dcae38d656
deps: upgrade kratos version to v2.5.2 (#2464) 2 years ago
Jesse a911f8f9ee
fix(log): toString float32 precision loss and convert uint use `FormatUint` (#2461) 2 years ago
dependabot[bot] 4bd1fde7ef
build(deps): bump actions/setup-go from 3.3.0 to 3.3.1 (#2462) 2 years ago
Jesse 54655e4b24
cleanup: use HTTP package methods replace GET POST DELETE... (#2412) 2 years ago
Tony Chen 185aaa7184
fix net error (#2460) 2 years ago
Guoqiang Ding 40300677ee
fix(metadata): sort services by lexicographical order on ListServices (#2397) 2 years ago
Jesse 6bb3ad6f27
fix: in for defer close (#2411) 2 years ago
Jesse 54c6fb3631
test(middleware/auth/jwt): add test TestNewContextAndFromContext (#2447) 2 years ago
Jesse b5482d1794
test(middleware/metadata): supplement test and modify code style (#2448) 2 years ago
Guoqiang Ding e3feea6eeb
docs(config/etcd): fix the missing step of Load (#2450) 2 years ago
ruohone d82d607c21
[Feature] add path prefix for http server (#2439) 2 years ago
jesse.tang 7a99e8bbdc
cleanup: regex replcae \. => . (#2435) 2 years ago
jesse.tang 77d260241c
test(middleware/logging): TestExtractError (#2443) 2 years ago
jesse.tang 2de6ba028c
cleanup: update scpSyntaxRe regexp (#2444) 2 years ago
jesse.tang b5cd1c693d
fix: contrib/registry/eureka/client.go serveice -> serivce (#2440) 2 years ago
jesse.tang c5e86ca36d
style: kratos interface check (#2441) 2 years ago
包子 8743f3e50c
deps: upgrade kratos version v2.5.1 (#2431) 2 years ago
jesse.tang 69fcd50c0a
feat: golangci add goimports local-prefixes (#2413) 2 years ago
jesse.tang 9f65c1a03d
cleanup: remove redundancy type conversion and golangci add unconvert (#2409) 2 years ago
Tony Chen a680321309
add custom binding (#2428) 2 years ago
Tony Chen 468630cc4b
expose request from transport (#2427) 2 years ago
180909 9301bfa407
chore(log): let log toString same (#2414) 2 years ago
leyou240 ff59a89b06
chore: Update go.yml (#2426) 2 years ago
jesse.tang 0ecc2b422f
style: modify declaring empty slices (#2378) 2 years ago
Gaffey faa3adc300
style(config/value): optimize atomicValue format string (#2401) 2 years ago
180909 b10e067fe9
test(log): add toString unit test (#2373) 2 years ago
jesse.tang 0e698b248a
cleanup: remove fmt and errors new err (#2377) 2 years ago
180909 2936b5ba80
cleanup: remove the repeated import (#2393) 2 years ago
jesse.tang 4d95050747
fix: fmt import (#2379) 2 years ago
swliao425 8d067a32db
fix(aliyun log): 'format bool' is missing in 'toString' function (#2406) 2 years ago
180909 2170a12aa4
fix: modify interface check way on selector (#2399) 2 years ago
180909 add67beeb3
fix(http/binding): fix http encode url (#2400) 2 years ago
包子 7866ff75fd
fix(registry/consul): use health check option to control custom checks (#2391) 2 years ago
Tony Chen 2d325fd386
fix(http/binding): fix http encode url (#2392) 2 years ago
jesse.tang 080165f2ee
cleanup: modify deprecated field (#2380) 2 years ago
jesse.tang 9737a3c5e4
fix: typo and grammatical errors (#2368) 2 years ago
Jiepeng Cao 7f2666be9f
typo for log (#2374) 2 years ago
jesse.tang 7a320233cd
fix: .gitignore del Repeated .*so (#2367) 2 years ago
Loner1024 d3f80c1061
test: supplement the unit testing of transport/grpc (#2371) 2 years ago
jesse.tang b0b49be383
feat: remote assert libraries (#2372) 2 years ago
jesse.tang 0ed01efdfd
revise err logic or null pointer exception (#2376) 2 years ago
jesse.tang f2a33929d0
fix: modify interface check way (#2375) 2 years ago
包子 ae505063fe
fix(apollo): config return nil when watch err 2 years ago
Guoqiang Ding 667d63839c
fix(makefile): add "make proto" for proto generating (#2130) 2 years ago
hshe e176ddfcdd
feat(internal/host): prefer ipv4 than ipv6 (#2342) 2 years ago
180909 0f0c75e20b
feat(cmd): user prePage to check changelog dev (#2340) 2 years ago
180909 18c5734930
test(cmd): add ModulePath test (#2337) 2 years ago
180909 8d76eebf8b
test(cmd/change): add ParseGithubURL test (#2339) 2 years ago
GongGuoWei cb69bf3714
test(config): add etcd config method test (#2349) 2 years ago
黄仲辉 617ee1aa39
fix(lint): Using deprecated package `io/ioutil` cause lint interrupted, change to `os` or `io` package. (#2353) 2 years ago
180909 39536d3279
fix(cmd): fix CmdAdd long message example (#2343) 2 years ago
dependabot[bot] e820b392e9
build(deps): bump github.com/hashicorp/consul/api (#2279) 2 years ago
dependabot[bot] aaabd07474
build(deps): bump actions/setup-go from 3.2.1 to 3.3.0 (#2313) 2 years ago
dependabot[bot] 7a336ca353
build(deps): bump google.golang.org/protobuf in /contrib/opensergo (#2248) 2 years ago
dependabot[bot] 503efd3825
build(deps): bump go.uber.org/zap in /contrib/log/zap (#2326) 2 years ago
icylight 60b00c8ade
fix(config/env): prefixs typo (#2321) 2 years ago
Wang-TaoTao ad7597c0b1
fix: init global selector to wrr (#2323) 2 years ago
icylight cbfb6db9cf
fix(internal/host): Extract can't return the minium index ip (#2298) 2 years ago
虫子樱桃 20c2425c18
fix `kratos new -r` not support scp styled git url.issue https://gith… (#2295) 2 years ago
包子 890bc21ac1
docs: update readme.md, remove qq group (#2341) 2 years ago
川桑 361391732b
test(selector): improve coverage (#2320) 2 years ago
包子 b354f185c0
feat(registry): consul support user custom checks (#2317) 2 years ago
jesse.tang 73a8323ee7
fix: slice/map make init cap (#2300) 2 years ago
Germiniku cb6176dbbb
feat(tracing) custom tracer name (#2310) 2 years ago
过客龙门 0ce9e8d069
specify array capacity hints (#2299) 2 years ago
dependabot[bot] b1bb0bd18f
build(deps): bump github.com/hashicorp/consul/api (#2278) 2 years ago
dependabot[bot] 869fcd57c8
build(deps): bump go.uber.org/zap in /contrib/log/zap (#2280) 2 years ago
icylight 5c3f0aa73e
style(metadata): specify map capacity hints (#2296) 2 years ago
jesse.tang 6ca225b078
add notes by not used defer (#2291) 2 years ago
YidaZhou ba72230477
doc: grammar problems in the Readme file (#2281) 2 years ago
Astone 205aa88d86
fix: encoding form decode field mask from well-know (#2285) 2 years ago
pwli bdfeb4bf78
fix typo (#2284) 2 years ago
haiyux 39796ea0dc
fix: delete endpoint service discovery compatibility (#2289) 2 years ago
包子 563ad0d34a
deps: upgreade kratos version to v2.5.0 (#2286) 2 years ago
包子 3f31b4d734
bc: apollo unable to get and watch to the properties file (#2269) 2 years ago
Tony Chen 2d206076f8
fix logger caller depth (#2283) 2 years ago
Germiniku de2f93fbec
refactor(log) aliyun use the same interface name (#2251) 2 years ago
longxboy 11cd43e3c3
refactor: unify selector filter (#2277) 2 years ago
kkf1 d11c6892b4
feat: add servicecomb registry (#2114) 2 years ago
Haibo 6d665c0ce6
fix: wrong order of Logger prefix kvs (#2273) 2 years ago
包子 84235462b7
feat(registry): consul get service support remote (#2275) 2 years ago
SeniorPlayer b9b7888d51
fix(log): DefaultCaller doesn't returns "pkg/file:line", it returns "file:line" now. For example, both biz/user.go and data/user.go are printed as user.go in logger. It's not clear. (#2274) 2 years ago
realityone f0c2a6ed90
Global logger (#2265) 2 years ago
Weizhen Wang 57dee517e5
fix(chore): set nacos-server v2.1.0 and consul v1.12.3 (#2268) 2 years ago
Kagaya e4d73db523
fix lint error (#2266) 2 years ago
dependabot[bot] 0aa9719e3a
build(deps): bump google.golang.org/protobuf in /contrib/log/aliyun (#2249) 2 years ago
shifengbin c407afc81d
fix: in case url or form bind param error should return BadRequest (#2256) 2 years ago
Germiniku fea863e783
feat(log): add tencent cls (#2244) 2 years ago
林晓炜 1f3ac4ea22
fix(registry): contrib/registry/zookeeper ephemeral nodes handling after restart (#2245) 2 years ago
dependabot[bot] aae0339692
build(deps): bump github.com/prometheus/common (#2210) 2 years ago
包子 eff368621f
deps: upgrade kratos version to v2.4.1 (#2242) 2 years ago
kiripeng a5eb913aa0
chore: go workspace contain go.work and go.work.sum (#2241) 2 years ago
180909 ffa1c2696c
update ignore for go workspace (#2240) 2 years ago
dependabot[bot] 86eba94646
build(deps): bump k8s.io/client-go in /contrib/config/kubernetes (#2217) 2 years ago
dependabot[bot] 2951b420f1
build(deps): bump k8s.io/client-go in /contrib/registry/kubernetes (#2218) 2 years ago
Tony Chen f3b0da3f04
feat(middleware): add selector matcher (#2239) 2 years ago
dependabot[bot] 377356d04d
build(deps): bump github.com/hashicorp/consul/api (#2211) 2 years ago
dependabot[bot] 247a74e631
build(deps): bump github.com/hashicorp/consul/api (#2209) 2 years ago
Tony Chen 3c54997dd8
fix default behavior for gRPC encoding (#2187) 2 years ago
dependabot[bot] e6767bc612
build(deps): bump k8s.io/api in /contrib/config/kubernetes (#2219) 2 years ago
dependabot[bot] 9d24dac487
build(deps): bump k8s.io/api in /contrib/registry/kubernetes (#2220) 2 years ago
dependabot[bot] e2c1fd7489
build(deps): bump github.com/go-zookeeper/zk (#2236) 2 years ago
hshe b7422717cf
proto build client structName not match to server's structName (#2200) 2 years ago
Haibo 59b758ceda
feat: support passing program args with run cmd (#2207) 2 years ago
林晓炜 246d8d9c28
fix: zookeeper add auto re-register (#2235) 2 years ago
Paul 92b3c8f94a
fix(contrib/config/polaris): Use injected client properly (#2238) 2 years ago
haiyux 14cfd65b62
fix: remove unuseful file when use nomod (#2234) 2 years ago
wangcong 82dfb955f5
fix(contrib): add logrus fatal level (#2222) 2 years ago
风雨雾凇 de0e4e2228
docs: update README_zh.md (#2208) 2 years ago
dependabot[bot] 1ab3d8f028
build(deps): bump github.com/prometheus/common (#2188) 2 years ago
dependabot[bot] 0ff80e42e7
build(deps): bump actions/setup-go from 3.2.0 to 3.2.1 (#2189) 2 years ago
Walrus Yu d1da8aa1ae
Feature/improve app test (#2190) 2 years ago
shengzhou ede5f889d4
test: increase endpoint,env, options and reader tests coverage. (#2192) 2 years ago
rogerogers bcef2b8e3f
test(contrib): update unit test for contrib/registry/polaris (#2196) 2 years ago
jakezhu9 85af73a84b
test(log): increase tests coverage (#2197) 2 years ago
包子 1451b9e0c0
deps: upgrade kratos version to v2.4.0 (#2186) 2 years ago
潘雄 96c8de9bc4
style(contrib/registry/*) annotation perfect (#2185) 2 years ago
Tony Chen d0a0edf67b
feat(http): add http router walk (#2181) 2 years ago
jakezhu9 afd108cdc7
test(options): increase tests coverage (#2183) 2 years ago
Ccheers b3eff576ce
test(transport): add unit test for transport coverage: 91.7% of state… (#2172) 2 years ago
rogerogers 63827466a3
test(contrib): add unit test for contrib/metrics/prometheus (#2182) 2 years ago
freezeChen 187c65bf8c
test(contrib/config/consul): add unit test for contrib/config/consul (#2179) 2 years ago
Tony Chen 6ac63e6439
fix(transport): http endpoint listening (#2180) 2 years ago
Tony Chen c90eab4577
fix transport early listening (#2177) 2 years ago
川桑 102391165e
test(errors): improve coverage (#2178) 2 years ago
Giovanny Gutiérrez 2209da5e24
feat(metadata): Ignore service if the dependencies are not found (#2171) 2 years ago
dependabot[bot] 1ea4ef7412
build(deps): bump k8s.io/client-go in /contrib/registry/kubernetes (#2120) 2 years ago
川桑 d88052b7dd
fix(errors): panic when err of Clone is nil (#2176) 2 years ago
darkweak c9fbb27b5b
tests(coverage): Increase middleware tests coverage (#2165) 2 years ago
shengzhou dec323113f
test(config/file): add format test (#2147) (#2168) 2 years ago
dependabot[bot] 8d0d7838ca
build(deps): bump github.com/hashicorp/consul/api (#2082) 2 years ago
rogerogers 2525e81e55
test(contrib): add unit test for contrib/registry/k8s (#2166) 2 years ago
dependabot[bot] 08fccfcb66
build(deps): bump github.com/hashicorp/consul/api (#2081) 2 years ago
dependabot[bot] 8e9e15e04b
build(deps): bump k8s.io/client-go in /contrib/config/kubernetes (#2122) 2 years ago
Betula-L e09d294388
feat: add logrus to contrib log (#2077) 2 years ago
dependabot[bot] 39bfeeb2f7
build(deps): bump k8s.io/api in /contrib/registry/kubernetes (#2124) 2 years ago
Y.Horie 106bc07def
test(contrib): add unit test for aliyun.go (#2164) 2 years ago
Tony Chen 0bcdb8d59c
fix(encoding/form): encode optional value (#2155) 2 years ago
shengzhou 5df19c47d8
test(encoding/form): well konw types test (#2147) (#2160) 2 years ago
Loner1024 62b58848d6
test: supplement the unit testing of metadata (#2161) 2 years ago
dependabot[bot] b6954d1aeb
build(deps): bump github.com/aliyun/aliyun-log-go-sdk (#2152) 2 years ago
rogerogers 6c36cc9544
feat: add contrib/config/polaris polaris as configcenter (#2158) 2 years ago
wangcong 20b7c9f4d7
test(nacos): add nacos unit test and remove unused function (#2145) 2 years ago
haiyux addcbba66e
feat: add protoc-gen-go-http annotations synchronization with protoc-gen-go-grpc (#2151) 2 years ago
Guoqiang Ding 035c2f5387
fix: typo on emptypb.Empty (#2150) 2 years ago
rogerogers 8c0a354797
test(contrib): add unit test for contrib/config/k8s (#2140) 2 years ago
freezeChen ed8b2352b7
test(contrib): add unit test for contrib/registry/consul (#2148) 2 years ago
liuyi0618 52031f1381
feat(contrib):add etcd watcher withKeysOnly option (#2146) 2 years ago
Y.Horie 9015ffb920
test(contrib): add unit test for fluent.go (#2141) 2 years ago
ThereWeGo 4ca25e4679
fix: show git output (#2143) 2 years ago
shifengbin 2ad7ffdd7e
fix: remove the output of the proto command 2 years ago
zoujiejun 3905182e98
test(contrib): add unit test for opensergo.go (#2137) 2 years ago
Ccheers 13c33fc4d3
feat(contrib): add unit test for zap_test.go & register_test.go (#2136) 2 years ago
haiyux 25c5996360
fix:fix url ptr not encode (#2117) 2 years ago
Guoqiang Ding 2f8703bff2
fix: allow the case of proto not found, such like gogo.proto (#2132) 2 years ago
charviki a3439c9713
fix: catch server stop error (#2125) 2 years ago
Tony Chen a0e624c0b8
fix(binding): fix bind field mask (#2112) 2 years ago
Cluas 6fa5700c3c
chore(contrib/config): uniformly canceled by CancelFunc (#2111) 2 years ago
包子 3aaac45e3d
fix: regenerate the proto file (#2108) 2 years ago
longxboy 2a989ea0fe
fix dup gen const for http (#2102) 2 years ago
YuanXin Hu e3c37b936f
use offical image (#2105) 2 years ago
Cluas 4f8d8ef8da
feat(config): add ErrorWatcherStopped and return on watcher.Next() after Watcher.Stop() (#2092) 2 years ago
haiyux 752f011ba1
fix:fix proto add underscore problem (#2101) 2 years ago
raw34 228ceaae9d
fix: kratos proto server cmd method name bugfix (#2089) (#2094) 2 years ago
包子 4b7afe52af
fix(config): apollo get the original configuration file directly (#2100) 2 years ago
longxboy 123fc1e6c8
feat: add peer for selector (#2088) 2 years ago
longxboy eb280903f0
fix: operation http constant name conflict (#2087) 2 years ago
longxboy 93adaba60a
add http operation const (#2086) 2 years ago
包子 874d4c3edc
doc: update pull request template (#2080) 2 years ago
workman-Lu d1550b366b
The clear interaction for user (#1916) 2 years ago
虫子樱桃 c6f6caa887
Add Flusher type alias . (#2078) 2 years ago
包子 95dce00852
deps: upgrade kratos version to v.2.3.1 (#2075) 2 years ago
haiyux ad5e9032a3
feat: make secure url to grpcs://127.0.0.1/ (#2072) 2 years ago
Tony Chen 1b3529fd0b
transport/http(feat): add redirector to forward request (#2074) 2 years ago
dependabot[bot] 5de1f081f6
build(deps): bump gopkg.in/yaml.v3 in /contrib/config/nacos (#2067) 3 years ago
dependabot[bot] b5e7b8d61b
build(deps): bump gopkg.in/yaml.v3 in /contrib/config/apollo (#2068) 3 years ago
Tony Chen 97c103a395
fix with logger (#2062) 3 years ago
dependabot[bot] b74e330289
build(deps): bump k8s.io/client-go in /contrib/config/kubernetes (#2056) 3 years ago
dependabot[bot] 7d425b898e
build(deps): bump k8s.io/client-go in /contrib/registry/kubernetes (#2057) 3 years ago
dependabot[bot] 8ad8578c40
build(deps): bump github.com/aliyun/aliyun-log-go-sdk (#2053) 3 years ago
dependabot[bot] a926195f66
build(deps): bump k8s.io/api in /contrib/config/kubernetes (#2052) 3 years ago
Tony Chen dccee86141
log: remove component logger to use global logger (#2061) 3 years ago
dependabot[bot] 925a0b725e
build(deps): bump k8s.io/api in /contrib/registry/kubernetes (#2058) 3 years ago
包子 6e685a474b
fix: config log 3 years ago
包子 c01fd054ec
feat: add config log (#2060) 3 years ago
Tony Chen 503ec03f37
app: fix instance nil when not registered (#2059) 3 years ago
dependabot[bot] 84b23fd301
build(deps): bump actions/setup-go from 2 to 3.2.0 (#2048) 3 years ago
dependabot[bot] 8fd0dc7680
build(deps): bump golangci/golangci-lint-action from 2 to 3 (#2047) 3 years ago
dependabot[bot] 6be806e7c0
build(deps): bump actions/checkout from 2 to 3 (#2046) 3 years ago
dependabot[bot] d1c6b732b4
build(deps): bump github/codeql-action from 1 to 2 (#2045) 3 years ago
包子 65d0ddbaae
Update dependabot.yml 3 years ago
包子 c304680444
Create dependabot.yml 3 years ago
longxboy 944d480f78
feat:add context for log (#2041) 3 years ago
包子 70317d05a0
deps: upgrade kratos version to v2.3.0 (#2036) 3 years ago
Tony Chen 97fd33ece7
opensergo: fix http path & method (#2035) 3 years ago
Kagaya 643caa6df9
feat(contrib/opensergo): add opensergo reportMetadata fields (#1996) 3 years ago
Tony Chen 79497dd3a5
log: fix global logger (#2034) 3 years ago
Tony Chen 6eae1745bd
http: handle default mux (#2033) 3 years ago
longxboy 655fe37188
fix:fix error camel case (#2032) 3 years ago
haiyux 71ea97fd93
deps: upgrade go mod version (#2028) 3 years ago
songzhibin97 398012aed4
Update project.go (#2024) 3 years ago
songzhibin97 0bbd008397
Update server.go (#2021) 3 years ago
songzhibin97 aa6529fb2d
style:change (#2022) 3 years ago
songzhibin97 ec2e3ab24e
Update path.go (#2023) 3 years ago
songzhibin97 bbb96f1e1f
Update run.go (#2025) 3 years ago
songzhibin97 c1dbc2dbd3
stype:gen_go_errors (#2026) 3 years ago
songzhibin97 b49b7c6ca8
Update server.go (#2027) 3 years ago
songzhibin97 0c511808ce
style:ewma (#2018) 3 years ago
songzhibin97 92ba6a3209
Style:trace (#2017) 3 years ago
songzhibin97 9e66ac2f5b
Update jwt.go (#2016) 3 years ago
songzhibin97 1dfac59204
Update metadata.go (#2015) 3 years ago
songzhibin97 2eb615b38a
style:log (#2014) 3 years ago
songzhibin97 5e0744a47b
Update encode.go (#2019) 3 years ago
Ccheers 8dec7cf5e8
feat(registry): zookeeper watch node changed (#1986) 3 years ago
songzhibin97 c412d65f57
Update endpoint.go (#2012) 3 years ago
songzhibin97 2ee49311c1
Update host.go (#2013) 3 years ago
songzhibin97 1dfb77bfe1
Update errors.go (#2009) 3 years ago
songzhibin97 ef6fb480c6
fix:#2006 config.atomicValue Other basic types are supported (#2007) 3 years ago
songzhibin97 8a8626331d
Update file.go (#2005) 3 years ago
qi 53c8877ce4
fix(protoc-gen-go-errors): fix generated function comments have extra blank lines. (#2008) 3 years ago
songzhibin97 5c66fcdc5a
fix:#2002 definition service lowercase generation cannot be exported (#2003) 3 years ago
JinChang 912abb4848
Added ability to configure protojson (#1993) 3 years ago
包子 c9f95dc2e8
fix: update ci gocyclo min-complexity 50 (#2000) 3 years ago
pwli f0a058713f
fix:(transport/http): fix unexpected overriding behavior when return an error (#1984) 3 years ago
houseme 0d9319b1ee
fix: Replace the docker image of Polaris (#1999) 3 years ago
songzhibin97 8ff5f2fe88
fix:#1987 Http and grpc generate route alignment (#1988) 3 years ago
Comolli ec78198050
feat: decode google.protobuf.BytesValue compatible base64.URLEncoding. (#1991) 3 years ago
Kagaya ab04490d49
docs: remove redundant info & fix typo in pr template (#1997) 3 years ago
Kagaya bf9f4886e9
ignore polaris test & add eureka consul test (#1998) 3 years ago
qi c8c870b77f
fix: query params: parse list failed, unsupported message type: "google.protobuf.Struct" #1967 (#1989) 3 years ago
Nikita Krasnikov ed144f6813
Fix buildMethodDesc for two and more message field (#1979) 3 years ago
witt ddc82ce45e
fix: delete redundant type conversion (#1977) 3 years ago
Jinming Guo bc9d2074af
fix: add 'go mod tidy' cmd to make quick-start available (#1973) 3 years ago
Underworld511 36dfcdb0a6
Update README_zh.md (#1975) 3 years ago
包子 091ba2dae7
deps: upgrade kratos version to v2.2.2 (#1944) 3 years ago
Elric Li eb2dcae83d
feat(log): Helper implemented io.Writer (#1927) 3 years ago
JeffreyBool 245f55d3ba
feat: protoc-gen-go-errors add comment (#1961) 3 years ago
林晓炜 9098e9dd39
feat(registry): contrib/registry/zookeeper add digest acl support (#1964) 3 years ago
张东龙 60465ccca2
fix(transport/http): responseEncoder should not write any data when it need to write nil (#1945) 3 years ago
haiyux 4e73384a9e
feat:new and add karge warehouse (#1953) 3 years ago
haiyux 73545347e8
fix: fix kratos run when cmd number is one (#1956) 3 years ago
haiyux d4c4908ef6
fix: fix choose failed when paths cmd/server (#1954) 3 years ago
Casper-Mars d4e1942480
fix(contrib/opensergo): fix index error (#1951) 3 years ago
张东龙 259cd84653
fix bind test errors (#1950) 3 years ago
李洛克 4472cdbf49
fix client do method done not use when err not nil (#1948) 3 years ago
Tony Chen ae230eb550
feat: add opensergo metadata (#1947) 3 years ago
yeqown fbf7855cf2
feat(discovery): provide an option to disable discovery debug log (#1942) 3 years ago
Tony Chen d0b704b8f3
feat(selector): add node scheme (#1932) 3 years ago
Windfarer 3990d91b9b
correct the func name in meatadata log (#1915) 3 years ago
Xudong Cai 9ca08888df
fix: error case2Camel (#1923) 3 years ago
Tony Chen a72fc68ffd
feat: add error cause for statck trace (#1910) 3 years ago
Casper-Mars 96cfbe6c22
feat: change description of Kratos (#1920) 3 years ago
Casper-Mars 19637d9b87
feat(registry): consul client add DeregisterCriticalServiceAfter option (#1917) 3 years ago
Casper-Mars 4f21094a56
fix(cmd/protoc-gen-go-errors):fix lint problem (#1919) 3 years ago
yoogo d5a2fb59ad
fix(cmd): protoc-gen-go-http use self release (#1909) 3 years ago
Tony Chen fd2335ba38
add json codec for grpc (#1908) 3 years ago
包子 558ef4ebae
fix(transport): fix the problem that the context is not delivered correctly (#1906) 3 years ago
包子 99a0646acb
fix(log/aliyun): Improper Input Validation in GoGo Protobuf CVE-2021-3121 (#1902) 3 years ago
Cluas 13208d7908
fix(log): FilterFunc keyvals lost logger prefix (#1901) 3 years ago
Cluas d4c0c57681
feat(log): log load config only when Debug level (#1899) 3 years ago
weetime 69df1ab9a6
feat(contrib): add eureka registry (#1792) (#1793) 3 years ago
Tony Chen 7a5c2207a1
fix: starter parent ctx (#1895) 3 years ago
longxboy e66a2905ab
feat: supprt non-kratos instance in consul registry (#1892) 3 years ago
包子 e98c0078cb
deps: upgrade kratos version to 2.2.1 (#1890) 3 years ago
包子 93b56d364d
fix: update semantic (#1891) 3 years ago
包子 de2d4eacda
fix(cmd): proto-gen-go-http warn only when ending with a slash (#1887) 3 years ago
Tony Chen 51fb0e0440
fix(log): call depth (#1885) 3 years ago
letian d373c51acf
fix: kratos command error on windows (#1884) 3 years ago
Tony Chen c550a886e9
fix: decode empty body (#1882) 3 years ago
Sasha Melentyev 096e2b0d79
ci: Add 1.18 (#1880) 3 years ago
hoslo f68702a8c2
fix: graceful shutdown (#1873) 3 years ago
包子 64bd619967
chore: remove examples (#1871) 3 years ago
包子 1c37eff18a
feat: add semantic.yml (#1876) 3 years ago
kwanhur ac99a5c877
style(cmd/errors/examples/middleware/transport): fix common words' spelling mistakes (#1872) 3 years ago
Chen Xinyuan 4387085047
fix: fix some typos (#1869) 3 years ago
kwanhur 79057d4326
chore(examples): optimize typos of swagger/server (#1862) 3 years ago
cui fliter ed6ab7caf9
docs: fix some typos (#1852) 3 years ago
YuanXin Hu e739f1d282
Example for Polaris (#1850) 3 years ago
Tony Chen 03ad2b6636
fix: error code judgment (#1849) 3 years ago
Sasha Melentyev 48d407cc9b
perf: add prealloc (#1846) 3 years ago
Sasha Melentyev da147b5763
feat: add zero prealloc (#1847) 3 years ago
Sasha Melentyev 997b6a9f79
build: add matrix strategy with go version (#1845) 3 years ago
Sasha Melentyev d679466a7b
perf(app): add prealloc (#1843) 3 years ago
Sasha Melentyev f56b325a3d
feat(example/transaction/ent): add ent install in Makefile (#1844) 3 years ago
YuanXin Hu f3313476ac
Discovery For Tencent Polaris (#1839) 3 years ago
高永立 2ee4e5f37a
feat(examples/transaction): feature transaction gorm (#1838) 3 years ago
Casper-Mars 5e18a15109
fix(config/config):fix type not match bug (#1837) 3 years ago
包子 d6896127b1
deps: upgrade kratos version to 2.2.0 (#1834) 3 years ago
包子 c9f1d7db6d
feat(examples/transaction): add transaction examples (#1836) 3 years ago
haiyux 24393ee655
fix lint (#1833) 3 years ago
youn a52b17c268
fix: add yaml / yml parser (#1808) 3 years ago
Zhen Wang 4dadafff90
fix(jwt): parse server custom claims (#1817) 3 years ago
Jin Peng 85800cedb9
fix(contrib): get nacos service of customize group name (#1798) 3 years ago
haiyux 9dec67bddd
update contrib readme (#1831) 3 years ago
YuanXin Hu 6446212258
feat(registry/polaris): add registry for Tencent Polaris (#1816) 3 years ago
Casper-Mars c1e98e41de
fix(config/consul):Config from consul skip empty key (#1830) 3 years ago
Tony Chen 6ec695064b
move container group to internal (#1827) 3 years ago
包子 991bb932f0
deps(thirdparty): clean oepnapi2 proto (#1826) 3 years ago
haiyux 370a1585a5
fix: fix the latest version of lint problem (#1825) 3 years ago
包子 cde962a6c1
fix(cmd/http): warn only when a get or delete request declares a body (#1789) 3 years ago
Jason C.H 471a2aab79
fix: k8s discovery interface (#1820) 3 years ago
haiyux 9662ef3c21
feat:add examples redirect url (#1807) 3 years ago
haiyux 86b8b6c366
fix: fix ci tool (#1803) 3 years ago
Tony Chen 34d0cccefd
fix: allocates new objects each time (#1802) 3 years ago
haiyux 18315303f0
deps:upgrade go mod version (#1800) 3 years ago
zjx-ERROR 0f23c1c516
解决consul client以IPv6地址格式register consul server health check时报错:[Check socket connection failed ... too many colons in address] (#1790) 3 years ago
包子 9ea78f302d
deps: upgrade kratos version to v2.1.5 (#1785) 3 years ago
guihouchang 1c18228d61
feat: add logger sdk for aliyun (#1748) 3 years ago
gopower ef99b7d1ef
deps[cmd]: Upgrade Cobra 1.2.1 -> v1.3.0 (#1783) 3 years ago
ArthurQ 92e4a83dbf
fix: change consul config docs (#1784) 3 years ago
longxboy a87abe223c
fix: consul heartbeat ttl not registered (#1781) 3 years ago
shengwudiyi c250958af6
fix: perhaps MISSING (#1779) 3 years ago
yangjianfeng9527 f050b07432
fixed the problem that grpc stop could not close properly 3 years ago
haiyux 9bf178b1d1
fix:fix log caller error (#1773) 3 years ago
haiyux 89583885e4
feat:add stream interceptor use ctx encapsulation (#1770) 3 years ago
Tony Chen 0965bf8e22
fix(cmd/kratos): specified version for upgrade (#1772) 3 years ago
realityone 83fad75c0f
make logger appliance as logger proxy (#1765) 3 years ago
haiyux 00c05e82a3
test:remove testify go mod (#1766) 3 years ago
MARATRIX Li c6c5e4595c
optimization: optimize global logger (#1763) 3 years ago
包子 a0006677e9
fix(cmd/kratos): filepath walk nil pointer reference problem (#1762) 3 years ago
realityone 0ed2e0f379
feat(log): add global logger appliance, as process level default logger (#1761) 3 years ago
Heelie d082075676
fix: change installation package path for protoc-gen-openapi (#1759) 3 years ago
kwame 8bb55663d9
zk 作为注册服务,异常端开,zk节点信息没有清理 (#1758) 3 years ago
haiyux cd4aa7f412
feat:sync to gitee where release a version (#1755) 3 years ago
Casper-Mars 76ab0baa56
feat(middleware/auth/jwt): add customer header (#1752) 3 years ago
haiyux 1c3185f9e5
readme:add log third party log library readme (#1753) 3 years ago
haiyux da70e22201
upgrade:upgrade grpc and opentelemetry version (#1751) 3 years ago
  1. 2
      .github/ISSUE_TEMPLATE/feature-request.md
  2. 87
      .github/dependabot.yml
  3. 37
      .github/pull_request_template.md
  4. 33
      .github/semantic.yml
  5. 12
      .github/stable.yml
  6. 6
      .github/workflows/codeql-analysis.yml
  7. 6
      .github/workflows/gitee-sync.yml
  8. 40
      .github/workflows/go.yml
  9. 16
      .github/workflows/issue-translator.yml
  10. 6
      .github/workflows/lint.yml
  11. 5
      .gitignore
  12. 15
      .golangci.yml
  13. 8
      CONTRIBUTING.md
  14. 35
      Makefile
  15. 32
      README.md
  16. 30
      README_zh.md
  17. 8
      SECURITY.md
  18. 168
      api/metadata/metadata.pb.go
  19. 2
      api/metadata/metadata.proto
  20. 6
      api/metadata/metadata_grpc.pb.go
  21. 2
      api/metadata/metadata_http.pb.go
  22. 75
      api/metadata/server.go
  23. 88
      app.go
  24. 120
      app_test.go
  25. 14
      cmd/kratos/go.mod
  26. 605
      cmd/kratos/go.sum
  27. 8
      cmd/kratos/internal/base/install.go
  28. 34
      cmd/kratos/internal/base/mod_test.go
  29. 37
      cmd/kratos/internal/base/path.go
  30. 53
      cmd/kratos/internal/base/repo.go
  31. 35
      cmd/kratos/internal/base/repo_test.go
  32. 58
      cmd/kratos/internal/base/vcs_url.go
  33. 55
      cmd/kratos/internal/base/vcs_url_test.go
  34. 8
      cmd/kratos/internal/change/change.go
  35. 20
      cmd/kratos/internal/change/get.go
  36. 25
      cmd/kratos/internal/change/get_test.go
  37. 67
      cmd/kratos/internal/project/add.go
  38. 16
      cmd/kratos/internal/project/new.go
  39. 81
      cmd/kratos/internal/project/project.go
  40. 29
      cmd/kratos/internal/project/project_linux_test.go
  41. 144
      cmd/kratos/internal/project/project_test.go
  42. 30
      cmd/kratos/internal/project/project_windows_test.go
  43. 19
      cmd/kratos/internal/proto/add/add.go
  44. 38
      cmd/kratos/internal/proto/add/add_test.go
  45. 6
      cmd/kratos/internal/proto/add/proto.go
  46. 8
      cmd/kratos/internal/proto/client/client.go
  47. 8
      cmd/kratos/internal/proto/proto.go
  48. 41
      cmd/kratos/internal/proto/server/server.go
  49. 102
      cmd/kratos/internal/proto/server/server_test.go
  50. 4
      cmd/kratos/internal/proto/server/template.go
  51. 57
      cmd/kratos/internal/run/run.go
  52. 20
      cmd/kratos/internal/upgrade/upgrade.go
  53. 4
      cmd/kratos/main.go
  54. 2
      cmd/kratos/version.go
  55. 50
      cmd/protoc-gen-go-errors/errors.go
  56. 17
      cmd/protoc-gen-go-errors/errorsTemplate.tpl
  57. 5
      cmd/protoc-gen-go-errors/go.mod
  58. 29
      cmd/protoc-gen-go-errors/go.sum
  59. 22
      cmd/protoc-gen-go-errors/template.go
  60. 2
      cmd/protoc-gen-go-errors/version.go
  61. 6
      cmd/protoc-gen-go-http/go.mod
  62. 70
      cmd/protoc-gen-go-http/go.sum
  63. 106
      cmd/protoc-gen-go-http/http.go
  64. 93
      cmd/protoc-gen-go-http/httpTemplate.tpl
  65. 52
      cmd/protoc-gen-go-http/http_test.go
  66. 7
      cmd/protoc-gen-go-http/main.go
  67. 100
      cmd/protoc-gen-go-http/template.go
  68. 2
      cmd/protoc-gen-go-http/version.go
  69. 36
      config/config.go
  70. 56
      config/config_test.go
  71. 16
      config/env/env.go
  72. 59
      config/env/env_test.go
  73. 4
      config/env/watcher.go
  74. 15
      config/env/watcher_test.go
  75. 4
      config/file/file.go
  76. 32
      config/file/file_test.go
  77. 43
      config/file/format_test.go
  78. 5
      config/file/watcher.go
  79. 8
      config/options.go
  80. 71
      config/options_test.go
  81. 20
      config/reader.go
  82. 219
      config/reader_test.go
  83. 105
      config/value.go
  84. 151
      config/value_test.go
  85. 65
      container/group/group_test.go
  86. 6
      contrib/config/apollo/README.md
  87. 208
      contrib/config/apollo/apollo.go
  88. 146
      contrib/config/apollo/apollo_test.go
  89. 7
      contrib/config/apollo/go.mod
  90. 1508
      contrib/config/apollo/go.sum
  91. 25
      contrib/config/apollo/json_parser.go
  92. 13
      contrib/config/apollo/parser.go
  93. 62
      contrib/config/apollo/watcher.go
  94. 45
      contrib/config/consul/README.md
  95. 16
      contrib/config/consul/config.go
  96. 175
      contrib/config/consul/config_test.go
  97. 10
      contrib/config/consul/go.mod
  98. 1596
      contrib/config/consul/go.sum
  99. 37
      contrib/config/consul/watcher.go
  100. 17
      contrib/config/etcd/README.md
  101. Some files were not shown because too many files have changed in this diff Show More

@ -43,7 +43,7 @@ example:
### Requirements description of the feature
<!--
example:
The event interface should be added to Kratos. The interface should contain subscribers and publishers, and the message body should contain key value heade
The event interface should be added to Kratos. The interface should contain subscribers and publishers, and the message body should contain key value head
-->
### References
<!--

@ -0,0 +1,87 @@
---
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "/contrib/config/apollo"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/config/consul"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/config/etcd"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/config/kubernetes"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/config/nacos"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/encoding/msgpack"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/log/aliyun"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/log/zap"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/log/fluent"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/metrics/datadog"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/metrics/prometheus"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/opensergo"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/registry/apollo"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/registry/consul"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/registry/etcd"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/registry/kubernetes"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/registry/nacos"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/registry/zookeeper"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/registry/eureka"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/contrib/registry/polaris"
schedule:
interval: "weekly"

@ -3,24 +3,21 @@
1. If this is your first time contributing to Kratos, please read our contribution guide: https://go-kratos.dev/en/docs/community/contribution/
2. Ensure you have added or ran the appropriate tests and lint for your PR, please use `make lint` and `make test` before filing your PR, use `make clean` to tidy your go mod.
3. If the PR is unfinished, you may need mark it as a WIP(Work In Progress) PR or draft PR
4. Please use a conventional commits format title: `<type>[optional scope]: <description>`
Some suggestion on <type>:
fix: A bug fix
feat: A new feature
test: Adding missing tests or correcting existing tests
refactor: A code change that neither fixes a bug nor adds a feature
break: Changes has break change
docs: Documentation only changes
deps: Changes external dependencies
style: Changes that do not affect the meaning of the code (white-space, formatting, etc)
chore Daily work, examples, etc.
ci: Changes to our CI configuration files and scripts
3. If the PR is unfinished, you may need to mark it as a WIP(Work In Progress) PR or Draft PR
4. Please use a semantic commits format title, such as `<type>[optional scope]: <description>`, see: https://go-kratos.dev/docs/community/contribution#type
5. at the same time, please note that similar work should be submitted in one PR as far as possible to reduce the workload of reviewers. Do not split a work into multiple PR unless it should.
-->
<!--
🎉 感谢您向 Kratos 发送 PR!以下是一些提示:
如果这是你第一次为 Kratos 贡献,请阅读我们的贡献指南:https://go-kratos.dev/en/docs/community/contribution/
2、确保您已经为您的 PR 添加或运行了适当的测试和lint,请在提交PR之前使用“make lint”和“make test”,使用“make clean”整理您的 go.mod。
3、如果 PR 未完成,您可能需要将其标记为 WIP(Work In Progress)PR 或 Draft PR
4、请使用语义提交格式标题,如“<类型>[可选范围]:<说明>`,请参阅:https://go-kratos.dev/docs/community/contribution#type
5. 同时请注意,同类的工作请尽量在一个PR中提交,以减轻 review 者的工作负担,不要把一项工作拆分成很多个PR,除非它应该这样做。
-->
#### Description (what this PR does / why we need it):
<!--
* The description should include the motivation for this PR or contrast this with previous behavior
@ -30,14 +27,14 @@
#### Which issue(s) this PR fixes (resolves / be part of):
<!--
* Automatically closes linked issue when PR is merged.
* If you PR is not fully resolved issue, please use `part of #<issue number>` instead.
* If your PR is not fully resolved the issue, please use `part of #<issue number>` instead.
Usage: `fixes/resolves #<issue number>`, or `fixes/resolves (paste link of issue)`.
-->
fixes #
#### Other special notes for reviewer:
#### Other special notes for the reviewers:
<!--
* Somethings that need extra attention for reviewer
* Somethings that need extra attention for the reviewers
* Some additional notes, TODO list, etc.
-->

@ -0,0 +1,33 @@
titleOnly: true
commitOnly: false
titleAndCommits: false
scopes:
- api
- cmd
- config
- contrib
- docs
- encoding
- hack
- internal
- log
- metadata
- metrics
- middleware
- registry
- selector
- third_party
- transport
types:
- deps
- feat
- fix
- docs
- style
- refactor
- perf
- test
- build
- ci
- chore
- revert

@ -0,0 +1,12 @@
daysUntilStale: 30
daysUntilClose: 3
exemptLabels:
- pinned
- security
- bug
staleLabel: wontfix
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
closeComment: true

@ -11,12 +11,12 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: go
- name: CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2

@ -2,6 +2,8 @@ on:
push:
branches:
- main
tags:
- "*"
name: Sync to Gitee
jobs:
@ -10,9 +12,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v1
uses: actions/checkout@v3
- name: Mirror Github to Gitee
uses: Yikun/hub-mirror-action@v1.0
uses: Yikun/hub-mirror-action@v1.2
with:
src: github/go-kratos
dst: gitee/go-kratos

@ -11,6 +11,9 @@ on:
jobs:
build:
strategy:
matrix:
go: [1.19,1.20.x]
name: build & test
runs-on: ubuntu-latest
services:
@ -22,22 +25,43 @@ jobs:
ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
ETCD_ADVERTISE_CLIENT_URLS: http://0.0.0.0:2379
consul:
image: consul:latest
image: consul:1.12.3
ports:
- 8500:8500
nacos:
image: nacos/nacos-server:latest
image: nacos/nacos-server:v2.1.0
env:
MODE: standalone
ports:
- "8848:8848"
- "9848:9848"
polaris:
image: polarismesh/polaris-standalone:latest
ports:
- 8090:8090
- 8091:8091
- 8093:8093
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4.0.1
with:
go-version: ${{ matrix.go }}
- name: Setup Environment
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- name: Module cache
uses: actions/cache@v3
with:
go-version: 1.16
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go
- name: Build
run: go build ./...
@ -59,9 +83,3 @@ jobs:
cd cmd/protoc-gen-go-http
go build ./...
go test ./...
- name: Examples
run: |
cd examples
go build ./...
go test ./...

@ -0,0 +1,16 @@
name: 'issue-translator'
on:
issue_comment:
types: [created]
issues:
types: [opened]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: usthe/issues-translate-action@v2.7
with:
IS_MODIFY_TITLE: true
CUSTOM_BOT_NOTE: Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}

@ -15,7 +15,7 @@ jobs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout Repo
uses: actions/checkout@v2
uses: actions/checkout@v3
- id: set-matrix
run: ./hack/resolve-modules.sh
@ -27,9 +27,9 @@ jobs:
strategy:
matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: latest
working-directory: ${{ matrix.workdir }}

5
.gitignore vendored

@ -3,7 +3,6 @@
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
@ -15,6 +14,10 @@
# Dependency directories (remove the comment below to include it)
vendor/
# Go workspace file
go.work
go.work.sum
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a

@ -28,10 +28,10 @@ linters:
- structcheck
- typecheck
- unused
- unconvert
- varcheck
- whitespace
- wastedassign
- unconvert
# don't enable:
# - asciicheck
@ -57,12 +57,15 @@ linters-settings:
lll:
line-length: 160
gomnd:
settings:
mnd:
# don't include the "operation", "argument" and "assign"
checks: case,condition,return
# don't include the "operation", "argument" and "assign"
checks:
- case
- condition
- return
goconst:
ignore-tests: true
gocyclo:
# recommend 10-20
min-complexity: 30
min-complexity: 50
goimports:
local-prefixes: github.com/go-kratos # Put imports beginning with prefix after 3rd-party packages

@ -1,7 +1,7 @@
The kratos community wants to be helped by a wide range of developers, so you'd like to take a few minutes to read this guide before you mention the problem or pull request.
## Reportings Bug or Fixing Bugs
We use github issues to manage issues. If you want to submit , first make sure you've searched for existing issues, pull requests and read our [FAQ](https://go-kratos.dev/docs/intro/faq).
## Reporting Bug or Fixing Bugs
We use GitHub issues to manage issues. If you want to submit , first make sure you've searched for existing issues, pull requests and read our [FAQ](https://go-kratos.dev/docs/intro/faq).
When submitting a bug report, use the issue template we provide to clearly describe the problems encountered and how to reproduce, and if convenient it is best to provide a minimal reproduce repository.
@ -16,9 +16,9 @@ After the function is implemented, a merge request will be initiated to associat
After the merge is completed, Close all issues.
## How to submit code
If you've never submitted code on github, follow these steps:
If you've never submitted code on GitHub, follow these steps:
- First, please fork items to your github account
- First, please fork items to your GitHub account
- Then create a new feature branch based on the main branch and name it features such as feature-log
- Write code
- Submit code to the far end branch

@ -1,9 +1,27 @@
user := $(shell whoami)
rev := $(shell git rev-parse --short HEAD)
os := $(shell expr substr $(shell uname -s) 1 5)
# GOBIN > GOPATH > INSTALLDIR
# Mac OS X
ifeq ($(shell uname),Darwin)
GOBIN := $(shell echo ${GOBIN} | cut -d':' -f1)
GOPATH := $(shell echo $(GOPATH) | cut -d':' -f1)
endif
# Linux
ifeq ($(os),Linux)
GOBIN := $(shell echo ${GOBIN} | cut -d':' -f1)
GOPATH := $(shell echo $(GOPATH) | cut -d':' -f1)
endif
# Windows
ifeq ($(os),MINGW)
GOBIN := $(subst \,/,$(GOBIN))
GOPATH := $(subst \,/,$(GOPATH))
GOBIN :=/$(shell echo "$(GOBIN)" | cut -d';' -f1 | sed 's/://g')
GOPATH :=/$(shell echo "$(GOPATH)" | cut -d';' -f1 | sed 's/://g')
endif
BIN := ""
TOOLS_SHELL="./hack/tools.sh"
@ -14,7 +32,7 @@ LINTER := bin/golangci-lint
ifneq ($(GOBIN),)
BIN=$(GOBIN)
else
# check GOPATH
# check GOPATH
ifneq ($(GOPATH),)
BIN=$(GOPATH)/bin
endif
@ -37,9 +55,9 @@ ifeq ($(user),root)
@cp ./cmd/protoc-gen-go-http/protoc-gen-go-http /usr/bin
else
#!root, install for current user
$(shell if [ -z $(BIN) ]; then read -p "Please select installdir: " REPLY; mkdir -p $${REPLY};\
cp ./cmd/kratos/kratos $${REPLY}/;cp ./cmd/protoc-gen-go-errors/protoc-gen-go-errors $${REPLY}/;cp ./cmd/protoc-gen-go-http/protoc-gen-go-http $${REPLY}/;else mkdir -p $(BIN);\
cp ./cmd/kratos/kratos $(BIN);cp ./cmd/protoc-gen-go-errors/protoc-gen-go-errors $(BIN);cp ./cmd/protoc-gen-go-http/protoc-gen-go-http $(BIN); fi)
$(shell if [ -z '$(BIN)' ]; then read -p "Please select installdir: " REPLY; mkdir -p $${REPLY};\
cp ./cmd/kratos/kratos $${REPLY}/;cp ./cmd/protoc-gen-go-errors/protoc-gen-go-errors $${REPLY}/;cp ./cmd/protoc-gen-go-http/protoc-gen-go-http $${REPLY}/;else mkdir -p '$(BIN)';\
cp ./cmd/kratos/kratos '$(BIN)';cp ./cmd/protoc-gen-go-errors/protoc-gen-go-errors '$(BIN)';cp ./cmd/protoc-gen-go-http/protoc-gen-go-http '$(BIN)'; fi)
endif
@which protoc-gen-go &> /dev/null || go get google.golang.org/protobuf/cmd/protoc-gen-go
@which protoc-gen-go-grpc &> /dev/null || go get google.golang.org/grpc/cmd/protoc-gen-go-grpc
@ -71,9 +89,14 @@ test:
.PHONY: test-coverage
test-coverage:
@${TOOLS_SHELL} test_coverage
@echo "go test with coverage finished"
@echo "go test with coverage finished"
.PHONY: lint
lint: $(LINTER)
@${TOOLS_SHELL} lint
@echo "lint check finished"
@echo "lint check finished"
.PHONY: proto
proto:
protoc --proto_path=./api --proto_path=./third_party --go_out=paths=source_relative:./api --go-grpc_out=paths=source_relative:./api --go-http_out=paths=source_relative:./api metadata/metadata.proto
protoc --proto_path=./third_party --go_out=paths=source_relative:./errors/errors.proto

@ -4,7 +4,7 @@
<a href="https://github.com/go-kratos/kratos/actions"><img src="https://github.com/go-kratos/kratos/workflows/Go/badge.svg" alt="Build Status"></a>
<a href="https://pkg.go.dev/github.com/go-kratos/kratos/v2"><img src="https://pkg.go.dev/badge/github.com/go-kratos/kratos/v2" alt="GoDoc"></a>
<a href="https://codecov.io/gh/go-kratos/kratos"><img src="https://codecov.io/gh/go-kratos/kratos/master/graph/badge.svg" alt="codeCov"></a>
<a href="https://goreportcard.com/report/github.com/go-kratos/kratos"><img src="https://goreportcard.com/badge/github.com/go-kratos/kratos" alt="Go Report Card" /a>
<a href="https://goreportcard.com/report/github.com/go-kratos/kratos"><img src="https://goreportcard.com/badge/github.com/go-kratos/kratos" alt="Go Report Card"></a>
<a href="https://github.com/go-kratos/kratos/blob/main/LICENSE"><img src="https://img.shields.io/github/license/go-kratos/kratos" alt="License"></a>
<a href="https://github.com/avelino/awesome-go"><img src="https://awesome.re/mentioned-badge.svg" alt="Awesome Go"></a>
<a href="https://discord.gg/BWzJsUJ"><img src="https://img.shields.io/discord/766619759214854164?label=chat&logo=discord" alt="Discord"></a>
@ -17,29 +17,29 @@
## About Kratos
> The name is inspired by the game God of War which is based on Greek myths, tells the Kratos from mortals to become a God of War and launches the adventure of killing god.
> The name is inspired by the Greek-mythology-based game "God of War". It tells the adventures of Kratos becoming a god of war from a mortal and launching a god-killing slaughter.
Kratos is a microservice-oriented governance framework implemented by golang, which offers convenient capabilities to help you quickly build a bulletproof application from scratch, such as:
- The [communication protocol](https://go-kratos.dev/en/docs/component/api) is based on the HTTP/gRPC through the definition of Protobuf.
- Abstract [transport](https://go-kratos.dev/en/docs/component/transport/overview) layer are support: [HTTP](https://go-kratos.dev/en/docs/component/transport/http) / [gRPC](https://go-kratos.dev/en/docs/component/transport/grpc).
- Powerful [middleware](https://go-kratos.dev/en/docs/component/middleware/overview) design, support: [Tracing (OpenTelemetry)](https://go-kratos.dev/en/docs/component/middleware/tracing)、[Metrics (Prometheus is default)](https://go-kratos.dev/en/docs/component/middleware/metrics)、[Recovery](https://go-kratos.dev/en/docs/component/middleware/recovery) and more.
- Abstract [transport](https://go-kratos.dev/en/docs/component/transport/overview) layer support: [HTTP](https://go-kratos.dev/en/docs/component/transport/http) / [gRPC](https://go-kratos.dev/en/docs/component/transport/grpc).
- Powerful [middleware](https://go-kratos.dev/en/docs/component/middleware/overview) design, support: [Tracing (OpenTelemetry)](https://go-kratos.dev/en/docs/component/middleware/tracing), [Metrics (Prometheus is default)](https://go-kratos.dev/en/docs/component/middleware/metrics), [Recovery](https://go-kratos.dev/en/docs/component/middleware/recovery) and more.
- [Registry](https://go-kratos.dev/en/docs/component/registry) interface able to be connected with various other centralized registries through plug-ins.
- The [standard log interfaces](https://go-kratos.dev/en/docs/component/log) ease the integration of the third-party log libs and logs are collected through the *Fluentd*.
- The selection of the content [encoding](https://go-kratos.dev/en/docs/component/encoding) is automatically supported by Accept and Content-Type.
- The [standard log interfaces](https://go-kratos.dev/en/docs/component/log) ease the integration of the third-party log libs with logs collected through the *Fluentd*.
- Automatically support the selection of the content [encoding](https://go-kratos.dev/en/docs/component/encoding) with Accept and Content-Type.
- Multiple data sources are supported for [configurations](https://go-kratos.dev/en/docs/component/config) and dynamic configurations (use atomic operations).
- In the protocol of HTTP/gRPC, use uniform [metadata](https://go-kratos.dev/en/docs/component/metadata) transfer method.
- In the protocol of HTTP/gRPC, use the uniform [metadata](https://go-kratos.dev/en/docs/component/metadata) transfer method.
- You can define [errors](https://go-kratos.dev/en/docs/component/errors/) in protos and generate enums with protoc-gen-go.
- You can define [verification rules](https://go-kratos.dev/en/docs/component/middleware/validate) in Protobuf which is supported by HTTP/gRPC service.
- [Swagger API](https://go-kratos.dev/en/docs/guide/openapi) generated Automatically and embed Swagger UI endpoint can be started by adding [Swagger plugin](https://github.com/go-kratos/swagger-api).
- You can define [verification rules](https://go-kratos.dev/en/docs/component/middleware/validate) in Protobuf supported by the HTTP/gRPC service.
- [Swagger API](https://go-kratos.dev/en/docs/guide/openapi) is generated Automatically and embed Swagger UI endpoint can be started by adding [Swagger plugin](https://github.com/go-kratos/swagger-api).
Kratos is accessible, powerful, and provides tools required for large, robust applications.
## 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 [moderm template](https://github.com/go-kratos/kratos-layout), This template should help reduce the work required to setup up a modern project.
We also provide a [modern template](https://github.com/go-kratos/kratos-layout). This template should help reduce the work required to setup up modern projects.
### Goals
@ -47,13 +47,13 @@ Kratos boosts your productivity. With the integration of excellent resources and
### Principles
* **Simple**: Appropriate design, plain and easy code.
* **Simple**: Appropriate design with plain and easy code.
* **General**: Cover the various utilities for business development.
* **Highly efficient**: Speeding up the efficiency of businesses upgrading.
* **Stable**: The base libs validated in the production environment which have the characters of the high testability, high coverage as well as high security and reliability.
* **Stable**: The base libs validated in the production environment have the characteristics of high testability, high coverage as well as high security and reliability.
* **Robust**: Eliminating misusing through high quality of the base libs.
* **High-performance**: Optimal performance excluding the optimization of hacking in case of *unsafe*. 
* **Expandability**: Properly designed interfaces, you can expand utilities such as base libs to meet your further requirements.
* **Expandability**: Properly designed interfaces where you can expand utilities such as base libs to meet your further requirements.
* **Fault-tolerance**: Designed against failure, enhance the understanding and exercising of SRE within Kratos to achieve more robustness.
* **Toolchain**: Includes an extensive toolchain, such as the code generation of cache, the lint tool, and so forth.
@ -73,6 +73,7 @@ go install github.com/go-kratos/kratos/cmd/kratos/v2@latest && kratos upgrade
```shell
kratos new helloworld
cd helloworld/ && go mod tidy
kratos run
```
@ -89,7 +90,6 @@ If you discover a security vulnerability within Kratos, please send an e-mail to
- [Wechat Group](https://github.com/go-kratos/kratos/issues/682)
- [Discord Group](https://discord.gg/BWzJsUJ)
- [go-kratos.dev](https://go-kratos.dev/en)
- QQ Group: 716486124
## Contributors
@ -110,5 +110,5 @@ The following project had particular influence on kratos's design.
- [go-kit/kit](https://github.com/go-kit/kit) is a programming toolkit for building microservices in go.
- [asim/go-micro](https://github.com/asim/go-micro) a distributed systems development framework.
- [google/go-cloud](https://github.com/google/go-cloud) is go cloud development kit.
- [tal-tech/go-zero](https://github.com/tal-tech/go-zero) is a web and rpc framework with lots of builtin engineering practices.
- [zeromicro/go-zero](https://github.com/zeromicro/go-zero) is a web and rpc framework with lots of builtin engineering practices.
- [beego/beego](https://github.com/beego/beego) is a web framework including RESTful APIs, web apps and backend services.

@ -4,7 +4,7 @@
<a href="https://github.com/go-kratos/kratos/actions"><img src="https://github.com/go-kratos/kratos/workflows/Go/badge.svg" alt="Build Status"></a>
<a href="https://pkg.go.dev/github.com/go-kratos/kratos/v2"><img src="https://pkg.go.dev/badge/github.com/go-kratos/kratos/v2" alt="GoDoc"></a>
<a href="https://codecov.io/gh/go-kratos/kratos"><img src="https://codecov.io/gh/go-kratos/kratos/master/graph/badge.svg" alt="codeCov"></a>
<a href="https://goreportcard.com/report/github.com/go-kratos/kratos"><img src="https://goreportcard.com/badge/github.com/go-kratos/kratos" alt="Go Report Card" /a>
<a href="https://goreportcard.com/report/github.com/go-kratos/kratos"><img src="https://goreportcard.com/badge/github.com/go-kratos/kratos" alt="Go Report Card"></a>
<a href="https://github.com/go-kratos/kratos/blob/main/LICENSE"><img src="https://img.shields.io/github/license/go-kratos/kratos" alt="License"></a>
<a href="https://github.com/avelino/awesome-go"><img src="https://awesome.re/mentioned-badge.svg" alt="Awesome Go"></a>
<a href="https://discord.gg/BWzJsUJ"><img src="https://img.shields.io/discord/766619759214854164?label=chat&logo=discord" alt="Discord"></a>
@ -19,7 +19,7 @@ Translations: [English](README.md) | [简体中文](README_zh.md)
Kratos 一套轻量级 Go 微服务框架,包含大量微服务相关功能及工具。
> 名字来源于:《战神》游戏以希腊神话为背景,讲述由凡人成为战神的奎托斯(Kratos)成为战神并展开弑神屠杀的冒险历
> 名字来源于:《战神》游戏以希腊神话为背景,讲述奎托斯(Kratos)由凡人成为战神并展开弑神屠杀的冒险历。
## Goals
@ -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 规范定义,以实现微服务链路追踪;
* [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服务.
* [APIs](https://go-kratos.dev/docs/component/api) :协议通信以 HTTP/gRPC 为基础,通过 Protobuf 进行定义;
* [Errors](https://go-kratos.dev/docs/component/errors/) :通过 Protobuf 的 Enum 作为错误码定义,以及工具生成判定接口;
* [Metadata](https://go-kratos.dev/docs/component/metadata) :在协议通信 HTTP/gRPC 中,通过 Middleware 规范化服务元信息传递;
* [Config](https://go-kratos.dev/docs/component/config) :支持多数据源方式,进行配置合并铺平,通过 Atomic 方式支持动态配置;
* [Logger](https://go-kratos.dev/docs/component/log) :标准日志接口,可方便集成三方 log 库,并可通过 fluentd 收集日志;
* [Metrics](https://go-kratos.dev/docs/component/middleware/metrics) :统一指标接口,可以实现各种指标系统,默认集成 Prometheus;
* [Tracing](https://go-kratos.dev/docs/component/middleware/tracing) :遵循 OpenTelemetry 规范定义,以实现微服务链路追踪;
* [Encoding](https://go-kratos.dev/docs/component/encoding) :支持 Accept 和 Content-Type 进行自动选择内容编码;
* [Transport](https://go-kratos.dev/docs/component/transport/overview) :通用的 [HTTP](https://go-kratos.dev/docs/component/transport/http) /[gRPC](https://go-kratos.dev/docs/component/transport/grpc) 传输层,实现统一的 [Middleware](https://go-kratos.dev/docs/component/middleware/overview) 插件支持;
* [Registry](https://go-kratos.dev/docs/component/registry) :实现统一注册中心接口,可插件化对接各种注册中心;
* [Validation](https://go-kratos.dev/docs/component/middleware/validate): 通过Protobuf统一定义校验规则,并同时适用于HTTP/gRPC服务.
* [SwaggerAPI](https://go-kratos.dev/docs/guide/openapi): 通过集成第三方[Swagger插件](https://github.com/go-kratos/swagger-api) 能够自动生成Swagger API json并启动一个内置的Swagger 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

@ -5,10 +5,10 @@
Use this section to tell people about which versions of your project are
currently being supported with security updates.
| Version | Supported |
| ------- | ------------------ |
| 2.0.rc1 | :white_check_mark: |
| < 2.0.beta3 | :x: |
| Version | Supported |
|-------------|--------------------|
| 2.0.rc1 | :white_check_mark: |
| < 2.0.beta3 | :x: |
## Reporting a Vulnerability

@ -1,8 +1,8 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.17.3
// source: metadata.proto
// protoc-gen-go v1.28.0
// protoc v3.19.4
// source: metadata/metadata.proto
package metadata
@ -31,7 +31,7 @@ type ListServicesRequest struct {
func (x *ListServicesRequest) Reset() {
*x = ListServicesRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_msgTypes[0]
mi := &file_metadata_metadata_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -44,7 +44,7 @@ func (x *ListServicesRequest) String() string {
func (*ListServicesRequest) ProtoMessage() {}
func (x *ListServicesRequest) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_msgTypes[0]
mi := &file_metadata_metadata_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -57,7 +57,7 @@ func (x *ListServicesRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use ListServicesRequest.ProtoReflect.Descriptor instead.
func (*ListServicesRequest) Descriptor() ([]byte, []int) {
return file_metadata_proto_rawDescGZIP(), []int{0}
return file_metadata_metadata_proto_rawDescGZIP(), []int{0}
}
type ListServicesReply struct {
@ -72,7 +72,7 @@ type ListServicesReply struct {
func (x *ListServicesReply) Reset() {
*x = ListServicesReply{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_msgTypes[1]
mi := &file_metadata_metadata_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -85,7 +85,7 @@ func (x *ListServicesReply) String() string {
func (*ListServicesReply) ProtoMessage() {}
func (x *ListServicesReply) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_msgTypes[1]
mi := &file_metadata_metadata_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -98,7 +98,7 @@ func (x *ListServicesReply) ProtoReflect() protoreflect.Message {
// Deprecated: Use ListServicesReply.ProtoReflect.Descriptor instead.
func (*ListServicesReply) Descriptor() ([]byte, []int) {
return file_metadata_proto_rawDescGZIP(), []int{1}
return file_metadata_metadata_proto_rawDescGZIP(), []int{1}
}
func (x *ListServicesReply) GetServices() []string {
@ -126,7 +126,7 @@ type GetServiceDescRequest struct {
func (x *GetServiceDescRequest) Reset() {
*x = GetServiceDescRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_msgTypes[2]
mi := &file_metadata_metadata_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -139,7 +139,7 @@ func (x *GetServiceDescRequest) String() string {
func (*GetServiceDescRequest) ProtoMessage() {}
func (x *GetServiceDescRequest) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_msgTypes[2]
mi := &file_metadata_metadata_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -152,7 +152,7 @@ func (x *GetServiceDescRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetServiceDescRequest.ProtoReflect.Descriptor instead.
func (*GetServiceDescRequest) Descriptor() ([]byte, []int) {
return file_metadata_proto_rawDescGZIP(), []int{2}
return file_metadata_metadata_proto_rawDescGZIP(), []int{2}
}
func (x *GetServiceDescRequest) GetName() string {
@ -173,7 +173,7 @@ type GetServiceDescReply struct {
func (x *GetServiceDescReply) Reset() {
*x = GetServiceDescReply{}
if protoimpl.UnsafeEnabled {
mi := &file_metadata_proto_msgTypes[3]
mi := &file_metadata_metadata_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -186,7 +186,7 @@ func (x *GetServiceDescReply) String() string {
func (*GetServiceDescReply) ProtoMessage() {}
func (x *GetServiceDescReply) ProtoReflect() protoreflect.Message {
mi := &file_metadata_proto_msgTypes[3]
mi := &file_metadata_metadata_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -199,7 +199,7 @@ func (x *GetServiceDescReply) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetServiceDescReply.ProtoReflect.Descriptor instead.
func (*GetServiceDescReply) Descriptor() ([]byte, []int) {
return file_metadata_proto_rawDescGZIP(), []int{3}
return file_metadata_metadata_proto_rawDescGZIP(), []int{3}
}
func (x *GetServiceDescReply) GetFileDescSet() *descriptorpb.FileDescriptorSet {
@ -209,74 +209,74 @@ func (x *GetServiceDescReply) GetFileDescSet() *descriptorpb.FileDescriptorSet {
return nil
}
var File_metadata_proto protoreflect.FileDescriptor
var file_metadata_proto_rawDesc = []byte{
0x0a, 0x0e, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x12, 0x0a, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x1a, 0x20, 0x67, 0x6f,
0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 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, 0x15, 0x0a, 0x13,
0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x22, 0x49, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x18,
0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x22, 0x2b,
0x0a, 0x15, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63,
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, 0x5d, 0x0a, 0x13, 0x47,
0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x52, 0x65, 0x70,
0x6c, 0x79, 0x12, 0x46, 0x0a, 0x0d, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x64, 0x65, 0x73, 0x63, 0x5f,
0x73, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x6c, 0x65,
0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x0b, 0x66,
0x69, 0x6c, 0x65, 0x44, 0x65, 0x73, 0x63, 0x53, 0x65, 0x74, 0x32, 0xdd, 0x01, 0x0a, 0x08, 0x4d,
0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x61, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x53,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x1f, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73,
0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f,
0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x11, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0b, 0x12,
0x09, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x6e, 0x0a, 0x0e, 0x47, 0x65,
0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x12, 0x21, 0x2e, 0x6b,
0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x1f, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74,
0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x52, 0x65, 0x70, 0x6c, 0x79,
0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x42, 0x63, 0x0a, 0x15, 0x63, 0x6f,
0x6d, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e,
0x61, 0x70, 0x69, 0x50, 0x01, 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, 0x76, 0x32, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f,
0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x3b, 0x6d, 0x65, 0x74, 0x61, 0x64,
0x61, 0x74, 0x61, 0xa2, 0x02, 0x09, 0x4b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x41, 0x50, 0x49, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
var File_metadata_metadata_proto protoreflect.FileDescriptor
var file_metadata_metadata_proto_rawDesc = []byte{
0x0a, 0x17, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64,
0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x6b, 0x72, 0x61, 0x74, 0x6f,
0x73, 0x2e, 0x61, 0x70, 0x69, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f,
0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 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, 0x15, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x49, 0x0a, 0x11,
0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c,
0x79, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20,
0x03, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x18, 0x0a,
0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07,
0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x22, 0x2b, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x53, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 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, 0x5d, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x46, 0x0a, 0x0d, 0x66,
0x69, 0x6c, 0x65, 0x5f, 0x64, 0x65, 0x73, 0x63, 0x5f, 0x73, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x22, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70,
0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x0b, 0x66, 0x69, 0x6c, 0x65, 0x44, 0x65, 0x73, 0x63,
0x53, 0x65, 0x74, 0x32, 0xdd, 0x01, 0x0a, 0x08, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61,
0x12, 0x61, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73,
0x12, 0x1f, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4c, 0x69,
0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x1d, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4c,
0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79,
0x22, 0x11, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0b, 0x12, 0x09, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x73, 0x12, 0x6e, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x44, 0x65, 0x73, 0x63, 0x12, 0x21, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61,
0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73,
0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f,
0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x44, 0x65, 0x73, 0x63, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02,
0x12, 0x12, 0x10, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61,
0x6d, 0x65, 0x7d, 0x42, 0x63, 0x0a, 0x15, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75,
0x62, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x50, 0x01, 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, 0x76, 0x32, 0x2f, 0x61,
0x70, 0x69, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f,
0x61, 0x70, 0x69, 0x3b, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xa2, 0x02, 0x09, 0x4b,
0x72, 0x61, 0x74, 0x6f, 0x73, 0x41, 0x50, 0x49, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_metadata_proto_rawDescOnce sync.Once
file_metadata_proto_rawDescData = file_metadata_proto_rawDesc
file_metadata_metadata_proto_rawDescOnce sync.Once
file_metadata_metadata_proto_rawDescData = file_metadata_metadata_proto_rawDesc
)
func file_metadata_proto_rawDescGZIP() []byte {
file_metadata_proto_rawDescOnce.Do(func() {
file_metadata_proto_rawDescData = protoimpl.X.CompressGZIP(file_metadata_proto_rawDescData)
func file_metadata_metadata_proto_rawDescGZIP() []byte {
file_metadata_metadata_proto_rawDescOnce.Do(func() {
file_metadata_metadata_proto_rawDescData = protoimpl.X.CompressGZIP(file_metadata_metadata_proto_rawDescData)
})
return file_metadata_proto_rawDescData
return file_metadata_metadata_proto_rawDescData
}
var file_metadata_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_metadata_proto_goTypes = []interface{}{
var file_metadata_metadata_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_metadata_metadata_proto_goTypes = []interface{}{
(*ListServicesRequest)(nil), // 0: kratos.api.ListServicesRequest
(*ListServicesReply)(nil), // 1: kratos.api.ListServicesReply
(*GetServiceDescRequest)(nil), // 2: kratos.api.GetServiceDescRequest
(*GetServiceDescReply)(nil), // 3: kratos.api.GetServiceDescReply
(*descriptorpb.FileDescriptorSet)(nil), // 4: google.protobuf.FileDescriptorSet
}
var file_metadata_proto_depIdxs = []int32{
var file_metadata_metadata_proto_depIdxs = []int32{
4, // 0: kratos.api.GetServiceDescReply.file_desc_set:type_name -> google.protobuf.FileDescriptorSet
0, // 1: kratos.api.Metadata.ListServices:input_type -> kratos.api.ListServicesRequest
2, // 2: kratos.api.Metadata.GetServiceDesc:input_type -> kratos.api.GetServiceDescRequest
@ -289,13 +289,13 @@ var file_metadata_proto_depIdxs = []int32{
0, // [0:1] is the sub-list for field type_name
}
func init() { file_metadata_proto_init() }
func file_metadata_proto_init() {
if File_metadata_proto != nil {
func init() { file_metadata_metadata_proto_init() }
func file_metadata_metadata_proto_init() {
if File_metadata_metadata_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_metadata_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
file_metadata_metadata_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListServicesRequest); i {
case 0:
return &v.state
@ -307,7 +307,7 @@ func file_metadata_proto_init() {
return nil
}
}
file_metadata_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
file_metadata_metadata_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListServicesReply); i {
case 0:
return &v.state
@ -319,7 +319,7 @@ func file_metadata_proto_init() {
return nil
}
}
file_metadata_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
file_metadata_metadata_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetServiceDescRequest); i {
case 0:
return &v.state
@ -331,7 +331,7 @@ func file_metadata_proto_init() {
return nil
}
}
file_metadata_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
file_metadata_metadata_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetServiceDescReply); i {
case 0:
return &v.state
@ -348,18 +348,18 @@ func file_metadata_proto_init() {
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_metadata_proto_rawDesc,
RawDescriptor: file_metadata_metadata_proto_rawDesc,
NumEnums: 0,
NumMessages: 4,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_metadata_proto_goTypes,
DependencyIndexes: file_metadata_proto_depIdxs,
MessageInfos: file_metadata_proto_msgTypes,
GoTypes: file_metadata_metadata_proto_goTypes,
DependencyIndexes: file_metadata_metadata_proto_depIdxs,
MessageInfos: file_metadata_metadata_proto_msgTypes,
}.Build()
File_metadata_proto = out.File
file_metadata_proto_rawDesc = nil
file_metadata_proto_goTypes = nil
file_metadata_proto_depIdxs = nil
File_metadata_metadata_proto = out.File
file_metadata_metadata_proto_rawDesc = nil
file_metadata_metadata_proto_goTypes = nil
file_metadata_metadata_proto_depIdxs = nil
}

@ -11,7 +11,7 @@ option java_package = "com.github.kratos.api";
option objc_class_prefix = "KratosAPI";
// Metadata is api defintion metadata service.
// Metadata is api definition metadata service.
service Metadata {
// ListServices list the full name of all services.
rpc ListServices (ListServicesRequest) returns (ListServicesReply) {

@ -1,4 +1,8 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.19.4
// source: metadata/metadata.proto
package metadata
@ -137,5 +141,5 @@ var Metadata_ServiceDesc = grpc.ServiceDesc{
},
},
Streams: []grpc.StreamDesc{},
Metadata: "metadata.proto",
Metadata: "metadata/metadata.proto",
}

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go-http. DO NOT EDIT.
// versions:
// protoc-gen-go-http v2.0.0
// protoc-gen-go-http v2.3.0
package metadata

@ -4,8 +4,10 @@ import (
"bytes"
"compress/gzip"
"context"
"errors"
"fmt"
"io"
"sort"
"sync"
"google.golang.org/grpc"
@ -13,13 +15,12 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
dpb "google.golang.org/protobuf/types/descriptorpb"
)
//nolint:lll
//go:generate protoc --proto_path=. --proto_path=../../third_party --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. --go-http_out=paths=source_relative:. metadata.proto
"github.com/go-kratos/kratos/v2/log"
)
// Server is api meta server
type Server struct {
@ -63,26 +64,32 @@ func (s *Server) load() error {
}
var err error
protoregistry.GlobalFiles.RangeFiles(func(fd protoreflect.FileDescriptor) bool {
if fd.Services() != nil {
for i := 0; i < fd.Services().Len(); i++ {
svc := fd.Services().Get(i)
fdp, e := fileDescriptorProto(fd.Path())
if e != nil {
err = e
return false
}
fdps, e := allDependency(fdp)
if e != nil {
err = e
return false
}
s.services[string(svc.FullName())] = &dpb.FileDescriptorSet{File: fdps}
if svc.Methods() != nil {
for j := 0; j < svc.Methods().Len(); j++ {
method := svc.Methods().Get(j)
s.methods[string(svc.FullName())] = append(s.methods[string(svc.FullName())], string(method.Name()))
}
if fd.Services() == nil {
return true
}
for i := 0; i < fd.Services().Len(); i++ {
svc := fd.Services().Get(i)
fdp, e := fileDescriptorProto(fd.Path())
if e != nil {
err = e
return false
}
fdps, e := allDependency(fdp)
if e != nil {
if errors.Is(e, protoregistry.NotFound) {
// Skip this service if one of its dependencies is not found.
continue
}
err = e
return false
}
s.services[string(svc.FullName())] = &dpb.FileDescriptorSet{File: fdps}
if svc.Methods() == nil {
continue
}
for j := 0; j < svc.Methods().Len(); j++ {
method := svc.Methods().Get(j)
s.methods[string(svc.FullName())] = append(s.methods[string(svc.FullName())], string(method.Name()))
}
}
return true
@ -91,13 +98,16 @@ func (s *Server) load() error {
}
// ListServices return all services
func (s *Server) ListServices(ctx context.Context, in *ListServicesRequest) (*ListServicesReply, error) {
func (s *Server) ListServices(_ context.Context, _ *ListServicesRequest) (*ListServicesReply, error) {
s.lock.Lock()
defer s.lock.Unlock()
if err := s.load(); err != nil {
return nil, err
}
reply := new(ListServicesReply)
reply := &ListServicesReply{
Services: make([]string, 0, len(s.services)),
Methods: make([]string, 0, len(s.methods)),
}
for name := range s.services {
reply.Services = append(reply.Services, name)
}
@ -106,11 +116,13 @@ func (s *Server) ListServices(ctx context.Context, in *ListServicesRequest) (*Li
reply.Methods = append(reply.Methods, fmt.Sprintf("/%s/%s", name, method))
}
}
sort.Strings(reply.Services)
sort.Strings(reply.Methods)
return reply, nil
}
// GetServiceDesc return service meta by name
func (s *Server) GetServiceDesc(ctx context.Context, in *GetServiceDescRequest) (*GetServiceDescReply, error) {
func (s *Server) GetServiceDesc(_ context.Context, in *GetServiceDescRequest) (*GetServiceDescReply, error) {
s.lock.Lock()
defer s.lock.Unlock()
if err := s.load(); err != nil {
@ -134,11 +146,7 @@ func parseMetadata(meta interface{}) (*dpb.FileDescriptorProto, error) {
}
// Check if meta is the byte slice.
if enc, ok := meta.([]byte); ok {
fd, err := decodeFileDesc(enc)
if err != nil {
return nil, err
}
return fd, nil
return decodeFileDesc(enc)
}
return nil, fmt.Errorf("proto not sumpport metadata: %v", meta)
}
@ -162,7 +170,8 @@ func allDependency(fd *dpb.FileDescriptorProto) ([]*dpb.FileDescriptorProto, err
for _, dep := range fd.Dependency {
fdDep, err := fileDescriptorProto(dep)
if err != nil {
return nil, err
log.Warnf("%s", err)
continue
}
temp, err := allDependency(fdDep)
if err != nil {
@ -190,7 +199,7 @@ func decompress(b []byte) ([]byte, error) {
func fileDescriptorProto(path string) (*dpb.FileDescriptorProto, error) {
fd, err := protoregistry.GlobalFiles.FindFileByPath(path)
if err != nil {
return nil, err
return nil, fmt.Errorf("find proto by path failed, path: %s, err: %s", path, err)
}
fdpb := protodesc.ToFileDescriptorProto(fd)
return fdpb, nil

@ -31,7 +31,7 @@ type App struct {
opts options
ctx context.Context
cancel func()
lk sync.Mutex
mu sync.Mutex
instance *registry.ServiceInstance
}
@ -39,7 +39,6 @@ type App struct {
func New(opts ...Option) *App {
o := options{
ctx: context.Background(),
logger: log.NewHelper(log.DefaultLogger),
sigs: []os.Signal{syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT},
registrarTimeout: 10 * time.Second,
stopTimeout: 10 * time.Second,
@ -50,6 +49,9 @@ func New(opts ...Option) *App {
for _, opt := range opts {
opt(&o)
}
if o.logger != nil {
log.SetLogger(o.logger)
}
ctx, cancel := context.WithCancel(o.ctx)
return &App{
ctx: ctx,
@ -72,10 +74,10 @@ func (a *App) Metadata() map[string]string { return a.opts.metadata }
// Endpoint returns endpoints.
func (a *App) Endpoint() []string {
if a.instance == nil {
return []string{}
if a.instance != nil {
return a.instance.Endpoints
}
return a.instance.Endpoints
return nil
}
// Run executes all OnStart hooks registered with the application's Lifecycle.
@ -84,76 +86,90 @@ func (a *App) Run() error {
if err != nil {
return err
}
ctx := NewContext(a.ctx, a)
eg, ctx := errgroup.WithContext(ctx)
a.mu.Lock()
a.instance = instance
a.mu.Unlock()
sctx := NewContext(a.ctx, a)
eg, ctx := errgroup.WithContext(sctx)
wg := sync.WaitGroup{}
for _, fn := range a.opts.beforeStart {
if err = fn(sctx); err != nil {
return err
}
}
for _, srv := range a.opts.servers {
srv := srv
eg.Go(func() error {
<-ctx.Done() // wait for stop signal
sctx, cancel := context.WithTimeout(NewContext(context.Background(), a), a.opts.stopTimeout)
stopCtx, cancel := context.WithTimeout(NewContext(a.opts.ctx, a), a.opts.stopTimeout)
defer cancel()
return srv.Stop(sctx)
return srv.Stop(stopCtx)
})
wg.Add(1)
eg.Go(func() error {
wg.Done()
return srv.Start(ctx)
wg.Done() // here is to ensure server start has begun running before register, so defer is not needed
return srv.Start(sctx)
})
}
wg.Wait()
if a.opts.registrar != nil {
rctx, rcancel := context.WithTimeout(a.opts.ctx, a.opts.registrarTimeout)
rctx, rcancel := context.WithTimeout(ctx, a.opts.registrarTimeout)
defer rcancel()
if err := a.opts.registrar.Register(rctx, instance); err != nil {
if err = a.opts.registrar.Register(rctx, instance); err != nil {
return err
}
}
for _, fn := range a.opts.afterStart {
if err = fn(sctx); err != nil {
return err
}
a.lk.Lock()
a.instance = instance
a.lk.Unlock()
}
c := make(chan os.Signal, 1)
signal.Notify(c, a.opts.sigs...)
eg.Go(func() error {
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-c:
err := a.Stop()
if err != nil {
a.opts.logger.Errorf("failed to stop app: %v", err)
return err
}
}
select {
case <-ctx.Done():
return nil
case <-c:
return a.Stop()
}
})
if err := eg.Wait(); err != nil && !errors.Is(err, context.Canceled) {
if err = eg.Wait(); err != nil && !errors.Is(err, context.Canceled) {
return err
}
return nil
for _, fn := range a.opts.afterStop {
err = fn(sctx)
}
return err
}
// Stop gracefully stops the application.
func (a *App) Stop() error {
a.lk.Lock()
func (a *App) Stop() (err error) {
sctx := NewContext(a.ctx, a)
for _, fn := range a.opts.beforeStop {
err = fn(sctx)
}
a.mu.Lock()
instance := a.instance
a.lk.Unlock()
a.mu.Unlock()
if a.opts.registrar != nil && instance != nil {
ctx, cancel := context.WithTimeout(a.opts.ctx, a.opts.registrarTimeout)
ctx, cancel := context.WithTimeout(NewContext(a.ctx, a), a.opts.registrarTimeout)
defer cancel()
if err := a.opts.registrar.Deregister(ctx, instance); err != nil {
if err = a.opts.registrar.Deregister(ctx, instance); err != nil {
return err
}
}
if a.cancel != nil {
a.cancel()
}
return nil
return err
}
func (a *App) buildInstance() (*registry.ServiceInstance, error) {
endpoints := make([]string, 0) //nolint:gomnd
endpoints := make([]string, 0, len(a.opts.endpoints))
for _, e := range a.opts.endpoints {
endpoints = append(endpoints, e.String())
}

@ -2,7 +2,8 @@ package kratos
import (
"context"
"fmt"
"errors"
"net/url"
"reflect"
"sync"
"testing"
@ -11,7 +12,6 @@ import (
"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/stretchr/testify/assert"
)
type mockRegistry struct {
@ -19,9 +19,9 @@ type mockRegistry struct {
service map[string]*registry.ServiceInstance
}
func (r *mockRegistry) Register(ctx context.Context, service *registry.ServiceInstance) error {
func (r *mockRegistry) Register(_ context.Context, service *registry.ServiceInstance) error {
if service == nil || service.ID == "" {
return fmt.Errorf("no service id")
return errors.New("no service id")
}
r.lk.Lock()
defer r.lk.Unlock()
@ -30,11 +30,11 @@ func (r *mockRegistry) Register(ctx context.Context, service *registry.ServiceIn
}
// Deregister the registration.
func (r *mockRegistry) Deregister(ctx context.Context, service *registry.ServiceInstance) error {
func (r *mockRegistry) Deregister(_ context.Context, service *registry.ServiceInstance) error {
r.lk.Lock()
defer r.lk.Unlock()
if r.service[service.ID] == nil {
return fmt.Errorf("deregister service not found")
return errors.New("deregister service not found")
}
delete(r.service, service.ID)
return nil
@ -47,6 +47,22 @@ func TestApp(t *testing.T) {
Name("kratos"),
Version("v1.0.0"),
Server(hs, gs),
BeforeStart(func(_ context.Context) error {
t.Log("BeforeStart...")
return nil
}),
BeforeStop(func(_ context.Context) error {
t.Log("BeforeStop...")
return nil
}),
AfterStart(func(_ context.Context) error {
t.Log("AfterStart...")
return nil
}),
AfterStop(func(_ context.Context) error {
t.Log("AfterStop...")
return nil
}),
Registrar(&mockRegistry{service: make(map[string]*registry.ServiceInstance)}),
)
time.AfterFunc(time.Second, func() {
@ -60,19 +76,25 @@ func TestApp(t *testing.T) {
func TestApp_ID(t *testing.T) {
v := "123"
o := New(ID(v))
assert.Equal(t, v, o.ID())
if !reflect.DeepEqual(v, o.ID()) {
t.Fatalf("o.ID():%s is not equal to v:%s", o.ID(), v)
}
}
func TestApp_Name(t *testing.T) {
v := "123"
o := New(Name(v))
assert.Equal(t, v, o.Name())
if !reflect.DeepEqual(v, o.Name()) {
t.Fatalf("o.Name():%s is not equal to v:%s", o.Name(), v)
}
}
func TestApp_Version(t *testing.T) {
v := "123"
o := New(Version(v))
assert.Equal(t, v, o.Version())
if !reflect.DeepEqual(v, o.Version()) {
t.Fatalf("o.Version():%s is not equal to v:%s", o.Version(), v)
}
}
func TestApp_Metadata(t *testing.T) {
@ -81,10 +103,86 @@ func TestApp_Metadata(t *testing.T) {
"b": "2",
}
o := New(Metadata(v))
assert.Equal(t, v, o.Metadata())
if !reflect.DeepEqual(v, o.Metadata()) {
t.Fatalf("o.Metadata():%s is not equal to v:%s", o.Metadata(), v)
}
}
func TestApp_Endpoint(t *testing.T) {
v := []string{"https://go-kratos.dev", "localhost"}
var endpoints []*url.URL
for _, urlStr := range v {
if endpoint, err := url.Parse(urlStr); err != nil {
t.Errorf("invalid endpoint:%v", urlStr)
} else {
endpoints = append(endpoints, endpoint)
}
}
o := New(Endpoint(endpoints...))
if instance, err := o.buildInstance(); err != nil {
t.Error("build instance failed")
} else {
o.instance = instance
}
if !reflect.DeepEqual(o.Endpoint(), v) {
t.Errorf("Endpoint() = %v, want %v", o.Endpoint(), v)
}
}
func TestApp_buildInstance(t *testing.T) {
want := struct {
id string
name string
version string
metadata map[string]string
endpoints []string
}{
id: "1",
name: "kratos",
version: "v1.0.0",
metadata: map[string]string{
"a": "1",
"b": "2",
},
endpoints: []string{"https://go-kratos.dev", "localhost"},
}
var endpoints []*url.URL
for _, urlStr := range want.endpoints {
if endpoint, err := url.Parse(urlStr); err != nil {
t.Errorf("invalid endpoint:%v", urlStr)
} else {
endpoints = append(endpoints, endpoint)
}
}
app := New(
ID(want.id),
Name(want.name),
Version(want.version),
Metadata(want.metadata),
Endpoint(endpoints...),
)
if got, err := app.buildInstance(); err != nil {
t.Error("build got failed")
} else {
if got.ID != want.id {
t.Errorf("ID() = %v, want %v", got.ID, want.id)
}
if got.Name != want.name {
t.Errorf("Name() = %v, want %v", got.Name, want.name)
}
if got.Version != want.version {
t.Errorf("Version() = %v, want %v", got.Version, want.version)
}
if !reflect.DeepEqual(got.Endpoints, want.endpoints) {
t.Errorf("Endpoint() = %v, want %v", got.Endpoints, want.endpoints)
}
if !reflect.DeepEqual(got.Metadata, want.metadata) {
t.Errorf("Metadata() = %v, want %v", got.Metadata, want.metadata)
}
}
}
func TestApp_Context(t *testing.T) {
type fields struct {
id string
version string
@ -147,7 +245,7 @@ func TestApp_Endpoint(t *testing.T) {
endpoint []string
metadata map[string]string
}{
id: "3", version: "v3", name: "kratos-v3", endpoint: []string{},
id: "3", version: "v3", name: "kratos-v3", endpoint: nil,
metadata: map[string]string{},
},
},

@ -3,9 +3,13 @@ module github.com/go-kratos/kratos/cmd/kratos/v2
go 1.16
require (
github.com/AlecAivazis/survey/v2 v2.2.15
github.com/emicklei/proto v1.9.1
github.com/fatih/color v1.12.0
github.com/spf13/cobra v1.2.1
golang.org/x/mod v0.4.2
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/emicklei/proto v1.10.0
github.com/fatih/color v1.13.0
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
golang.org/x/text v0.4.0
gopkg.in/yaml.v3 v3.0.0 // indirect
)

@ -1,602 +1,79 @@
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.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.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/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/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=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/AlecAivazis/survey/v2 v2.2.15 h1:6UNMnk+YGegYFiPfdTOyZDIN+m08x2nGnqOn15BWcEQ=
github.com/AlecAivazis/survey/v2 v2.2.15/go.mod h1:TH2kPCDU3Kqq7pLbnCWwZXDBjnhZtmsCle5EiYDJ2fg=
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/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
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-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
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/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/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
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/emicklei/proto v1.9.1 h1:MUgjFo5xlMwYv72TnF5xmmdKZ04u+dVbv6wdARv16D8=
github.com/emicklei/proto v1.9.1/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
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/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
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/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
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/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/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/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
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/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/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-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
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/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
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-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
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/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
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/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/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
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/emicklei/proto v1.10.0 h1:pDGyFRVV5RvV+nkBK9iy3q67FBy9Xa7vwrOTE+g5aGw=
github.com/emicklei/proto v1.10.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
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/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
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/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.4 h1:5Myjjh3JY/NaAi4IsUbHADytDyl1VE1Y9PXDlL+P/VQ=
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
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.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
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.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
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/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
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/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/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/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
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/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
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/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw=
github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t68Nk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
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.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
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/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
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/etcd/api/v3 v3.5.0/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/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
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.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
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/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 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
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-20181023162649-9b4f9f5ad519/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-20190108225652-1e06a53dbb7e/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/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
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-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-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-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-20201209123823-ac852fbbde11/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/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-20210402161424-2e8d93401602/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/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
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/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-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
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-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-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-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/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-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-20200523222454-059865788121/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-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/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-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/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-20210630005230-0f9fa26af87c/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-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
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 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
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/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/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-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-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-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-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-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
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.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.44.0/go.mod h1:EBOGZqzyhtvMDoxwS97ctnh0zUmYY6CxqXsc1AvkYD8=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
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-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-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-20210222152913-aa3ee6e6a81c/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-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
google.golang.org/grpc v1.23.0/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.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
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=
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/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
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.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
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=
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=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

@ -7,13 +7,17 @@ import (
"fmt"
"os"
"os/exec"
"strings"
)
// GoInstall go get path.
func GoInstall(path ...string) error {
for _, p := range path {
fmt.Printf("go install %s@latest\n", p)
cmd := exec.Command("go", "install", fmt.Sprintf("%s@latest", p))
if !strings.Contains(p, "@") {
p += "@latest"
}
fmt.Printf("go install %s\n", p)
cmd := exec.Command("go", "install", p)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {

@ -1,6 +1,9 @@
package base
import "testing"
import (
"os"
"testing"
)
func TestModuleVersion(t *testing.T) {
v, err := ModuleVersion("golang.org/x/mod")
@ -9,3 +12,32 @@ func TestModuleVersion(t *testing.T) {
}
t.Log(v)
}
func TestModulePath(t *testing.T) {
if err := os.Mkdir("/tmp/test_mod", os.ModePerm); err != nil {
t.Fatal(err)
}
f, err := os.Create("/tmp/test_mod/go.mod")
if err != nil {
t.Fatal(err)
}
mod := `module github.com/go-kratos/kratos/v2
go 1.16`
_, err = f.WriteString(mod)
if err != nil {
t.Fatal(err)
}
p, err := ModulePath("/tmp/test_mod/go.mod")
if err != nil {
t.Fatal(err)
}
if p != "github.com/go-kratos/kratos/v2" {
t.Fatalf("want: %s, got: %s", "github.com/go-kratos/kratos/v2", p)
}
t.Cleanup(func() { os.RemoveAll("/tmp/test_mod") })
}

@ -5,7 +5,6 @@ import (
"fmt"
"log"
"os"
"path"
"path/filepath"
"strings"
@ -17,7 +16,7 @@ func kratosHome() string {
if err != nil {
log.Fatal(err)
}
home := path.Join(dir, ".kratos")
home := filepath.Join(dir, ".kratos")
if _, err := os.Stat(home); os.IsNotExist(err) {
if err := os.MkdirAll(home, 0o700); err != nil {
log.Fatal(err)
@ -27,7 +26,7 @@ func kratosHome() string {
}
func kratosHomeWithDir(dir string) string {
home := path.Join(kratosHome(), dir)
home := filepath.Join(kratosHome(), dir)
if _, err := os.Stat(home); os.IsNotExist(err) {
if err := os.MkdirAll(home, 0o700); err != nil {
log.Fatal(err)
@ -37,7 +36,6 @@ func kratosHomeWithDir(dir string) string {
}
func copyFile(src, dst string, replaces []string) error {
var err error
srcinfo, err := os.Stat(src)
if err != nil {
return err
@ -58,35 +56,34 @@ func copyFile(src, dst string, replaces []string) error {
}
func copyDir(src, dst string, replaces, ignores []string) error {
var err error
var fds []os.DirEntry
var srcinfo os.FileInfo
if srcinfo, err = os.Stat(src); err != nil {
srcinfo, err := os.Stat(src)
if err != nil {
return err
}
if err = os.MkdirAll(dst, srcinfo.Mode()); err != nil {
err = os.MkdirAll(dst, srcinfo.Mode())
if err != nil {
return err
}
if fds, err = os.ReadDir(src); err != nil {
fds, err := os.ReadDir(src)
if err != nil {
return err
}
for _, fd := range fds {
if hasSets(fd.Name(), ignores) {
continue
}
srcfp := path.Join(src, fd.Name())
dstfp := path.Join(dst, fd.Name())
srcfp := filepath.Join(src, fd.Name())
dstfp := filepath.Join(dst, fd.Name())
var e error
if fd.IsDir() {
if err = copyDir(srcfp, dstfp, replaces, ignores); err != nil {
return err
}
e = copyDir(srcfp, dstfp, replaces, ignores)
} else {
if err = copyFile(srcfp, dstfp, replaces); err != nil {
return err
}
e = copyFile(srcfp, dstfp, replaces)
}
if e != nil {
return e
}
}
return nil
@ -103,7 +100,7 @@ func hasSets(name string, sets []string) bool {
func Tree(path string, dir string) {
_ = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
if err == nil && info != nil && !info.IsDir() {
fmt.Printf("%s %s (%v bytes)\n", color.GreenString("CREATED"), strings.Replace(path, dir+"/", "", -1), info.Size())
}
return nil

@ -3,12 +3,16 @@ package base
import (
"context"
"fmt"
"net"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
)
var unExpandVarPath = []string{"~", ".", ".."}
// Repo is git repository manager.
type Repo struct {
url string
@ -16,19 +20,29 @@ type Repo struct {
branch string
}
func repoDir(url string) string {
vcsURL, err := ParseVCSUrl(url)
if err != nil {
return url
}
// check host contains port
host, _, err := net.SplitHostPort(vcsURL.Host)
if err != nil {
host = vcsURL.Host
}
for _, p := range unExpandVarPath {
host = strings.TrimLeft(host, p)
}
dir := path.Base(path.Dir(vcsURL.Path))
url = fmt.Sprintf("%s/%s", host, dir)
return url
}
// NewRepo new a repository manager.
func NewRepo(url string, branch string) *Repo {
var start int
start = strings.Index(url, "//")
if start == -1 {
start = strings.Index(url, ":") + 1
} else {
start += 2
}
end := strings.LastIndex(url, "/")
return &Repo{
url: url,
home: kratosHomeWithDir("repo/" + url[start:end]),
home: kratosHomeWithDir("repo/" + repoDir(url)),
branch: branch,
}
}
@ -55,15 +69,15 @@ func (r *Repo) Pull(ctx context.Context) error {
cmd.Dir = r.Path()
_, err := cmd.CombinedOutput()
if err != nil {
return nil
return err
}
cmd = exec.CommandContext(ctx, "git", "pull")
cmd.Dir = r.Path()
out, err := cmd.CombinedOutput()
fmt.Println(string(out))
if err != nil {
return err
}
fmt.Println(string(out))
return err
}
@ -79,10 +93,10 @@ func (r *Repo) Clone(ctx context.Context) error {
cmd = exec.CommandContext(ctx, "git", "clone", "-b", r.branch, r.url, r.Path())
}
out, err := cmd.CombinedOutput()
fmt.Println(string(out))
if err != nil {
return err
}
fmt.Println(string(out))
return nil
}
@ -91,9 +105,22 @@ func (r *Repo) CopyTo(ctx context.Context, to string, modPath string, ignores []
if err := r.Clone(ctx); err != nil {
return err
}
mod, err := ModulePath(path.Join(r.Path(), "go.mod"))
mod, err := ModulePath(filepath.Join(r.Path(), "go.mod"))
if err != nil {
return err
}
return copyDir(r.Path(), to, []string{mod, modPath}, ignores)
}
// CopyToV2 copies the repository to project path
func (r *Repo) CopyToV2(ctx context.Context, to string, modPath string, ignores, replaces []string) error {
if err := r.Clone(ctx); err != nil {
return err
}
mod, err := ModulePath(filepath.Join(r.Path(), "go.mod"))
if err != nil {
return err
}
replaces = append([]string{mod, modPath}, replaces...)
return copyDir(r.Path(), to, replaces, ignores)
}

@ -2,10 +2,42 @@ package base
import (
"context"
"os"
"testing"
)
func TestRepo(t *testing.T) {
urls := []string{
// ssh://[user@]host.xz[:port]/path/to/repo.git/
"ssh://git@github.com:7875/go-kratos/kratos.git",
// git://host.xz[:port]/path/to/repo.git/
"git://github.com:7875/go-kratos/kratos.git",
// http[s]://host.xz[:port]/path/to/repo.git/
"https://github.com:7875/go-kratos/kratos.git",
// ftp[s]://host.xz[:port]/path/to/repo.git/
"ftps://github.com:7875/go-kratos/kratos.git",
//[user@]host.xz:path/to/repo.git/
"git@github.com:go-kratos/kratos.git",
// ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
"ssh://git@github.com:7875/go-kratos/kratos.git",
// git://host.xz[:port]/~[user]/path/to/repo.git/
"git://github.com:7875/go-kratos/kratos.git",
//[user@]host.xz:/~[user]/path/to/repo.git/
"git@github.com:go-kratos/kratos.git",
///path/to/repo.git/
"//github.com/go-kratos/kratos.git",
// file:///path/to/repo.git/
"file://./github.com/go-kratos/kratos.git",
}
for _, url := range urls {
dir := repoDir(url)
if dir != "github.com/go-kratos" && dir != "/go-kratos" {
t.Fatal(url, "repoDir test failed", dir)
}
}
}
func TestRepoClone(t *testing.T) {
r := NewRepo("https://github.com/go-kratos/service-layout.git", "")
if err := r.Clone(context.Background()); err != nil {
t.Fatal(err)
@ -13,4 +45,7 @@ func TestRepo(t *testing.T) {
if err := r.CopyTo(context.Background(), "/tmp/test_repo", "github.com/go-kratos/kratos-layout", nil); err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
os.RemoveAll("/tmp/test_repo")
})
}

@ -0,0 +1,58 @@
package base
import (
"errors"
"net/url"
"regexp"
"strings"
)
var (
scpSyntaxRe = regexp.MustCompile(`^(\w+)@([\w.-]+):(.*)$`)
scheme = []string{"git", "https", "http", "git+ssh", "ssh", "file", "ftp", "ftps"}
)
// ParseVCSUrl ref https://github.com/golang/go/blob/master/src/cmd/go/internal/vcs/vcs.go
// see https://go-review.googlesource.com/c/go/+/12226/
// git url define https://git-scm.com/docs/git-clone#_git_urls
func ParseVCSUrl(repo string) (*url.URL, error) {
var (
repoURL *url.URL
err error
)
if m := scpSyntaxRe.FindStringSubmatch(repo); m != nil {
// Match SCP-like syntax and convert it to a URL.
// Eg, "git@github.com:user/repo" becomes
// "ssh://git@github.com/user/repo".
repoURL = &url.URL{
Scheme: "ssh",
User: url.User(m[1]),
Host: m[2],
Path: m[3],
}
} else {
if !strings.Contains(repo, "//") {
repo = "//" + repo
}
if strings.HasPrefix(repo, "//git@") {
repo = "ssh:" + repo
} else if strings.HasPrefix(repo, "//") {
repo = "https:" + repo
}
repoURL, err = url.Parse(repo)
if err != nil {
return nil, err
}
}
// Iterate over insecure schemes too, because this function simply
// reports the state of the repo. If we can't see insecure schemes then
// we can't report the actual repo URL.
for _, s := range scheme {
if repoURL.Scheme == s {
return repoURL, nil
}
}
return nil, errors.New("unable to parse repo url")
}

@ -0,0 +1,55 @@
package base
import (
"net"
"strings"
"testing"
)
func TestParseVCSUrl(t *testing.T) {
repos := []string{
// ssh://[user@]host.xz[:port]/path/to/repo.git/
"ssh://git@github.com:7875/go-kratos/kratos.git",
// git://host.xz[:port]/path/to/repo.git/
"git://github.com:7875/go-kratos/kratos.git",
// http[s]://host.xz[:port]/path/to/repo.git/
"https://github.com:7875/go-kratos/kratos.git",
// ftp[s]://host.xz[:port]/path/to/repo.git/
"ftps://github.com:7875/go-kratos/kratos.git",
//[user@]host.xz:path/to/repo.git/
"git@github.com:go-kratos/kratos.git",
// ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
"ssh://git@github.com:7875/go-kratos/kratos.git",
// git://host.xz[:port]/~[user]/path/to/repo.git/
"git://github.com:7875/go-kratos/kratos.git",
//[user@]host.xz:/~[user]/path/to/repo.git/
"git@github.com:go-kratos/kratos.git",
///path/to/repo.git/
"~/go-kratos/kratos.git",
// file:///path/to/repo.git/
"file://~/go-kratos/kratos.git",
}
for _, repo := range repos {
url, err := ParseVCSUrl(repo)
if err != nil {
t.Fatal(repo, err)
}
urlPath := strings.TrimLeft(url.Path, "/")
if urlPath != "go-kratos/kratos.git" {
t.Fatal(repo, "parse url failed", urlPath)
}
}
}
func TestParseSsh(t *testing.T) {
repo := "ssh://git@github.com:7875/go-kratos/kratos.git"
url, err := ParseVCSUrl(repo)
if err != nil {
t.Fatal(err)
}
host, _, err := net.SplitHostPort(url.Host)
if err != nil {
host = url.Host
}
t.Log(host, url.Path)
}

@ -28,7 +28,7 @@ func init() {
token = os.Getenv("GITHUB_TOKEN")
}
func run(cmd *cobra.Command, args []string) {
func run(_ *cobra.Command, args []string) {
owner, repo := ParseGithubURL(repoURL)
api := GithubAPI{Owner: owner, Repo: repo, Token: token}
version := "latest"
@ -38,8 +38,8 @@ func run(cmd *cobra.Command, args []string) {
if version == "dev" {
info := api.GetCommitsInfo()
fmt.Print(ParseCommitsInfo(info))
} else {
info := api.GetReleaseInfo(version)
fmt.Print(ParseReleaseInfo(info))
return
}
info := api.GetReleaseInfo(version)
fmt.Print(ParseReleaseInfo(info))
}

@ -43,7 +43,7 @@ func (g *GithubAPI) GetReleaseInfo(version string) ReleaseInfo {
if version != "latest" {
api = fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/tags/%s", g.Owner, g.Repo, version)
}
resp, code := requestGithubAPI(api, "GET", nil, g.Token)
resp, code := requestGithubAPI(api, http.MethodGet, nil, g.Token)
if code != http.StatusOK {
printGithubErrorInfo(resp)
}
@ -59,10 +59,11 @@ func (g *GithubAPI) GetReleaseInfo(version string) ReleaseInfo {
func (g *GithubAPI) GetCommitsInfo() []CommitInfo {
info := g.GetReleaseInfo("latest")
page := 1
prePage := 100
var list []CommitInfo
for {
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/commits?pre_page=100&page=%d&since=%s", g.Owner, g.Repo, page, info.PublishedAt)
resp, code := requestGithubAPI(url, "GET", nil, g.Token)
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/commits?pre_page=%d&page=%d&since=%s", g.Owner, g.Repo, prePage, page, info.PublishedAt)
resp, code := requestGithubAPI(url, http.MethodGet, nil, g.Token)
if code != http.StatusOK {
printGithubErrorInfo(resp)
}
@ -72,7 +73,7 @@ func (g *GithubAPI) GetCommitsInfo() []CommitInfo {
fatal(err)
}
list = append(list, res...)
if len(res) < http.StatusContinue {
if len(res) < prePage {
break
}
page++
@ -157,11 +158,12 @@ func ParseCommitsInfo(info []CommitInfo) string {
case "other":
text = "### Others\n"
}
if len(value) > 0 {
md[key] += text
for _, value := range value {
md[key] += fmt.Sprintf("- %s\n", value)
}
if len(value) == 0 {
continue
}
md[key] += text
for _, value := range value {
md[key] += fmt.Sprintf("- %s\n", value)
}
}
return fmt.Sprint(md["break"], md["deps"], md["feat"], md["fix"], md["chore"], md["other"])

@ -0,0 +1,25 @@
package change
import "testing"
func TestParseGithubURL(t *testing.T) {
urls := []struct {
url string
owner string
repo string
}{
{"https://github.com/go-kratos/kratos.git", "go-kratos", "kratos"},
{"https://github.com/go-kratos/kratos", "go-kratos", "kratos"},
{"git@github.com:go-kratos/kratos.git", "go-kratos", "kratos"},
{"https://github.com/go-kratos/go-kratos.dev.git", "go-kratos", "go-kratos.dev"},
}
for _, url := range urls {
owner, repo := ParseGithubURL(url.url)
if owner != url.owner {
t.Fatalf("owner want: %s, got: %s", owner, url.owner)
}
if repo != url.repo {
t.Fatalf("repo want: %s, got: %s", repo, url.repo)
}
}
}

@ -0,0 +1,67 @@
package project
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/AlecAivazis/survey/v2"
"github.com/fatih/color"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
)
var repoAddIgnores = []string{
".git", ".github", "api", "README.md", "LICENSE", "go.mod", "go.sum", "third_party", "openapi.yaml", ".gitignore",
}
func (p *Project) Add(ctx context.Context, dir string, layout string, branch string, mod string) error {
to := filepath.Join(dir, p.Name)
if _, err := os.Stat(to); !os.IsNotExist(err) {
fmt.Printf("🚫 %s already exists\n", p.Name)
override := false
prompt := &survey.Confirm{
Message: "📂 Do you want to override the folder ?",
Help: "Delete the existing folder and create the project.",
}
e := survey.AskOne(prompt, &override)
if e != nil {
return e
}
if !override {
return err
}
os.RemoveAll(to)
}
fmt.Printf("🚀 Add service %s, layout repo is %s, please wait a moment.\n\n", p.Name, layout)
repo := base.NewRepo(layout, branch)
if err := repo.CopyToV2(ctx, to, filepath.Join(mod, p.Path), repoAddIgnores, []string{filepath.Join(p.Path, "api"), "api"}); err != nil {
return err
}
e := os.Rename(
filepath.Join(to, "cmd", "server"),
filepath.Join(to, "cmd", p.Name),
)
if e != nil {
return e
}
base.Tree(to, dir)
fmt.Printf("\n🍺 Repository creation succeeded %s\n", color.GreenString(p.Name))
fmt.Print("💻 Use the following command to add a project 👇:\n\n")
fmt.Println(color.WhiteString("$ cd %s", p.Name))
fmt.Println(color.WhiteString("$ go generate ./..."))
fmt.Println(color.WhiteString("$ go build -o ./bin/ ./... "))
fmt.Println(color.WhiteString("$ ./bin/%s -conf ./configs\n", p.Name))
fmt.Println(" 🤝 Thanks for using Kratos")
fmt.Println(" 📚 Tutorial: https://go-kratos.dev/docs/getting-started/start")
return nil
}

@ -4,12 +4,12 @@ import (
"context"
"fmt"
"os"
"path"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
"path/filepath"
"github.com/AlecAivazis/survey/v2"
"github.com/fatih/color"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
)
// Project is a project template.
@ -20,14 +20,14 @@ type Project struct {
// New new a project from remote repo.
func (p *Project) New(ctx context.Context, dir string, layout string, branch string) error {
to := path.Join(dir, p.Name)
to := filepath.Join(dir, p.Name)
if _, err := os.Stat(to); !os.IsNotExist(err) {
fmt.Printf("🚫 %s already exists\n", p.Name)
override := false
prompt := &survey.Confirm{
Message: "📂 Do you want to override the folder ?",
Help: "Delete the existing folder and create the project.",
}
var override bool
e := survey.AskOne(prompt, &override)
if e != nil {
return e
@ -39,12 +39,12 @@ func (p *Project) New(ctx context.Context, dir string, layout string, branch str
}
fmt.Printf("🚀 Creating service %s, layout repo is %s, please wait a moment.\n\n", p.Name, layout)
repo := base.NewRepo(layout, branch)
if err := repo.CopyTo(ctx, to, p.Path, []string{".git", ".github"}); err != nil {
if err := repo.CopyTo(ctx, to, p.Name, []string{".git", ".github"}); err != nil {
return err
}
e := os.Rename(
path.Join(to, "cmd", "server"),
path.Join(to, "cmd", p.Name),
filepath.Join(to, "cmd", "server"),
filepath.Join(to, "cmd", p.Name),
)
if e != nil {
return e

@ -5,11 +5,14 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strings"
"time"
"github.com/AlecAivazis/survey/v2"
"github.com/spf13/cobra"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
)
// CmdNew represents the new command.
@ -24,6 +27,7 @@ var (
repoURL string
branch string
timeout string
nomod bool
)
func init() {
@ -34,9 +38,10 @@ func init() {
CmdNew.Flags().StringVarP(&repoURL, "repo-url", "r", repoURL, "layout repo")
CmdNew.Flags().StringVarP(&branch, "branch", "b", branch, "repo branch")
CmdNew.Flags().StringVarP(&timeout, "timeout", "t", timeout, "time out")
CmdNew.Flags().BoolVarP(&nomod, "nomod", "", nomod, "retain go mod")
}
func run(cmd *cobra.Command, args []string) {
func run(_ *cobra.Command, args []string) {
wd, err := os.Getwd()
if err != nil {
panic(err)
@ -60,21 +65,85 @@ func run(cmd *cobra.Command, args []string) {
} else {
name = args[0]
}
p := &Project{Name: path.Base(name), Path: name}
projectName, workingDir := processProjectParams(name, wd)
p := &Project{Name: projectName}
done := make(chan error, 1)
go func() {
done <- p.New(ctx, wd, repoURL, branch)
if !nomod {
done <- p.New(ctx, workingDir, repoURL, branch)
return
}
projectRoot := getgomodProjectRoot(workingDir)
if gomodIsNotExistIn(projectRoot) {
done <- fmt.Errorf("🚫 go.mod don't exists in %s", projectRoot)
return
}
p.Path, err = filepath.Rel(projectRoot, filepath.Join(workingDir, projectName))
if err != nil {
done <- fmt.Errorf("🚫 failed to get relative path: %v", err)
return
}
mod, e := base.ModulePath(filepath.Join(projectRoot, "go.mod"))
if e != nil {
done <- fmt.Errorf("🚫 failed to parse `go.mod`: %v", e)
return
}
// Get the relative path for adding a project based on Go modules
p.Path = filepath.Join(strings.TrimPrefix(workingDir, projectRoot+"/"), p.Name)
done <- p.Add(ctx, workingDir, repoURL, branch, mod)
}()
select {
case <-ctx.Done():
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
fmt.Fprint(os.Stderr, "\033[31mERROR: project creation timed out\033[m\n")
} else {
fmt.Fprintf(os.Stderr, "\033[31mERROR: failed to create project(%s)\033[m\n", ctx.Err().Error())
return
}
fmt.Fprintf(os.Stderr, "\033[31mERROR: failed to create project(%s)\033[m\n", ctx.Err().Error())
case err = <-done:
if err != nil {
fmt.Fprintf(os.Stderr, "\033[31mERROR: Failed to create project(%s)\033[m\n", err.Error())
}
}
}
func processProjectParams(projectName string, workingDir string) (projectNameResult, workingDirResult string) {
_projectDir := projectName
_workingDir := workingDir
// Process ProjectName with system variable
if strings.HasPrefix(projectName, "~") {
homeDir, err := os.UserHomeDir()
if err != nil {
// cannot get user home return fallback place dir
return _projectDir, _workingDir
}
_projectDir = filepath.Join(homeDir, projectName[2:])
}
// check path is relative
if !filepath.IsAbs(projectName) {
absPath, err := filepath.Abs(projectName)
if err != nil {
return _projectDir, _workingDir
}
_projectDir = absPath
}
return filepath.Base(_projectDir), filepath.Dir(_projectDir)
}
func getgomodProjectRoot(dir string) string {
if dir == filepath.Dir(dir) {
return dir
}
if gomodIsNotExistIn(dir) {
return getgomodProjectRoot(filepath.Dir(dir))
}
return dir
}
func gomodIsNotExistIn(dir string) bool {
_, e := os.Stat(filepath.Join(dir, "go.mod"))
return os.IsNotExist(e)
}

@ -0,0 +1,29 @@
//go:build linux
// +build linux
package project
import (
"testing"
)
func Test_processProjectParams(t *testing.T) {
type args struct {
projectName string
fallbackPlaceDir string
}
tests := []struct {
name string
args args
want string
}{
{"absLinux", args{projectName: "/home/kratos/awesome/go/demo", fallbackPlaceDir: ""}, "/home/kratos/awesome/go"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if _, got := processProjectParams(tt.args.projectName, tt.args.fallbackPlaceDir); got != tt.want {
t.Errorf("processProjectParams() = %v, want %v", got, tt.want)
}
})
}
}

@ -0,0 +1,144 @@
package project
import (
"fmt"
"go/parser"
"go/token"
"os"
"path/filepath"
"testing"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
)
// TestCmdNew tests the `kratos new` command.
func TestCmdNew(t *testing.T) {
cwd := changeCurrentDir(t)
projectName := "helloworld"
// create a new project
CmdNew.SetArgs([]string{projectName})
if err := CmdNew.Execute(); err != nil {
t.Fatalf("executing command: %v", err)
}
// check that the expected files were created
for _, file := range []string{
"go.mod",
"go.sum",
"README.md",
"cmd/helloworld/main.go",
} {
if _, err := os.Stat(filepath.Join(cwd, projectName, file)); err != nil {
t.Errorf("expected file %s to exist", file)
}
}
// check that the go.mod file contains the expected module name
assertGoMod(t, filepath.Join(cwd, projectName, "go.mod"), projectName)
assertImportsInclude(t, filepath.Join(cwd, projectName, "cmd", projectName, "wire.go"), fmt.Sprintf(`"%s/internal/biz"`, projectName))
}
// TestCmdNewNoMod tests the `kratos new` command with the --nomod flag.
func TestCmdNewNoMod(t *testing.T) {
cwd := changeCurrentDir(t)
// create a new project
CmdNew.SetArgs([]string{"project"})
if err := CmdNew.Execute(); err != nil {
t.Fatalf("executing command: %v", err)
}
// add new app with --nomod flag
CmdNew.SetArgs([]string{"--nomod", "project/app/user"})
if err := CmdNew.Execute(); err != nil {
t.Fatalf("executing command: %v", err)
}
// check that the expected files were created
for _, file := range []string{
"go.mod",
"go.sum",
"README.md",
"cmd/project/main.go",
"app/user/cmd/user/main.go",
} {
if _, err := os.Stat(filepath.Join(cwd, "project", file)); err != nil {
t.Errorf("expected file %s to exist", file)
}
}
assertImportsInclude(t, filepath.Join(cwd, "project/app/user/cmd/user/wire.go"), `"project/app/user/internal/biz"`)
}
// assertImportsInclude checks that the file at path contains the expected import.
func assertImportsInclude(t *testing.T, path, expected string) {
t.Helper()
got, err := imports(path)
if err != nil {
t.Fatalf("getting imports: %v", err)
}
for _, imp := range got {
if imp == expected {
return
}
}
t.Errorf("expected imports to include %s, got %v", expected, got)
}
// imports returns the imports in the file at path.
func imports(path string) ([]string, error) {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, path, nil, parser.ImportsOnly)
if err != nil {
return nil, err
}
imports := make([]string, 0, len(f.Imports))
for _, s := range f.Imports {
imports = append(imports, s.Path.Value)
}
return imports, nil
}
// assertGoMod checks that the go.mod file contains the expected module name.
func assertGoMod(t *testing.T, path, expected string) {
t.Helper()
got, err := base.ModulePath(path)
if err != nil {
t.Fatalf("getting module path: %v", err)
}
if got != expected {
t.Errorf("expected module name %s, got %s", expected, got)
}
}
// change the working directory to the tempdir
func changeCurrentDir(t *testing.T) string {
t.Helper()
tmp := t.TempDir()
oldCWD, err := os.Getwd()
if err != nil {
t.Fatalf("getting working directory: %v", err)
}
if err := os.Chdir(tmp); err != nil {
t.Fatalf("changing working directory: %v", err)
}
t.Cleanup(func() {
if err := os.Chdir(oldCWD); err != nil {
t.Fatalf("restoring working directory: %v", err)
}
})
return tmp
}

@ -0,0 +1,30 @@
//go:build windows
// +build windows
package project
import (
"testing"
)
func Test_processProjectParams(t *testing.T) {
type args struct {
projectName string
fallbackPlaceDir string
}
tests := []struct {
name string
args args
want string
}{
{"absWindows", args{projectName: "c:\\kratos\\awesome\\go\\demo", fallbackPlaceDir: ""}, "c:\\kratos\\awesome\\go"},
//{"relativeWindows", args{projectName: "/home/kratos/awesome/go/demo", fallbackPlaceDir: ""}, "/home/kratos/awesome/go"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if _, got := processProjectParams(tt.args.projectName, tt.args.fallbackPlaceDir); got != tt.want {
t.Errorf("getProjectPlaceDir() = %v, want %v", got, tt.want)
}
})
}
}

@ -7,18 +7,23 @@ import (
"github.com/spf13/cobra"
"golang.org/x/mod/modfile"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
// CmdAdd represents the add command.
var CmdAdd = &cobra.Command{
Use: "add",
Short: "Add a proto API template",
Long: "Add a proto API template. Example: kratos add helloworld/v1/hello.proto",
Long: "Add a proto API template. Example: kratos proto add helloworld/v1/hello.proto",
Run: run,
}
func run(cmd *cobra.Command, args []string) {
// kratos proto add helloworld/v1/helloworld.proto
func run(_ *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("Please enter the proto file or directory")
return
}
input := args[0]
n := strings.LastIndex(input, "/")
if n == -1 {
@ -63,7 +68,11 @@ func javaPackage(name string) string {
}
func serviceName(name string) string {
return export(strings.Split(name, ".")[0])
return toUpperCamelCase(strings.Split(name, ".")[0])
}
func export(s string) string { return strings.ToUpper(s[:1]) + s[1:] }
func toUpperCamelCase(s string) string {
s = strings.ReplaceAll(s, "_", " ")
s = cases.Title(language.Und, cases.NoLower).String(s)
return strings.ReplaceAll(s, " ", "")
}

@ -0,0 +1,38 @@
package add
import "testing"
func TestUnderscoreToUpperCamelCase(t *testing.T) {
tests := []struct {
name string
want string
}{
{
name: "hello_world",
want: "HelloWorld",
},
{
name: "v2_kratos_dev",
want: "V2KratosDev",
},
{
name: "www_Google_com",
want: "WwwGoogleCom",
},
{
name: "wwwBaidu_com",
want: "WwwBaiduCom",
},
{
name: "HelloWorld",
want: "HelloWorld",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := toUpperCamelCase(tt.name); got != tt.want {
t.Errorf("toUpperCamelCase() = %v, want %v", got, tt.want)
}
})
}
}

@ -3,7 +3,7 @@ package add
import (
"fmt"
"os"
"path"
"path/filepath"
)
// Proto is a proto generator.
@ -26,13 +26,13 @@ func (p *Proto) Generate() error {
if err != nil {
panic(err)
}
to := path.Join(wd, p.Path)
to := filepath.Join(wd, p.Path)
if _, err := os.Stat(to); os.IsNotExist(err) {
if err := os.MkdirAll(to, 0o700); err != nil {
return err
}
}
name := path.Join(to, p.Name)
name := filepath.Join(to, p.Name)
if _, err := os.Stat(name); !os.IsNotExist(err) {
return fmt.Errorf("%s already exists", p.Name)
}

@ -8,9 +8,9 @@ import (
"regexp"
"strings"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
"github.com/spf13/cobra"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
)
// CmdClient represents the source command.
@ -30,7 +30,7 @@ func init() {
CmdClient.Flags().StringVarP(&protoPath, "proto_path", "p", protoPath, "proto path")
}
func run(cmd *cobra.Command, args []string) {
func run(_ *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("Please enter the proto file or directory")
return
@ -39,7 +39,7 @@ func run(cmd *cobra.Command, args []string) {
err error
proto = strings.TrimSpace(args[0])
)
if err = look("protoc-gen-go", "protoc-gen-go-grpc", "protoc-gen-go-http", "protoc-gen-go-errors", "protoc-gen-validate", "protoc-gen-openapi"); err != nil {
if err = look("protoc-gen-go", "protoc-gen-go-grpc", "protoc-gen-go-http", "protoc-gen-go-errors", "protoc-gen-openapi"); err != nil {
// update the kratos plugins
cmd := exec.Command("kratos", "upgrade")
cmd.Stdout = os.Stdout

@ -1,11 +1,11 @@
package proto
import (
"github.com/spf13/cobra"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/proto/add"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/proto/client"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/proto/server"
"github.com/spf13/cobra"
)
// CmdProto represents the proto command.
@ -13,7 +13,6 @@ var CmdProto = &cobra.Command{
Use: "proto",
Short: "Generate the proto files",
Long: "Generate the proto files.",
Run: run,
}
func init() {
@ -21,6 +20,3 @@ func init() {
CmdProto.AddCommand(client.CmdClient)
CmdProto.AddCommand(server.CmdServer)
}
func run(cmd *cobra.Command, args []string) {
}

@ -4,18 +4,20 @@ import (
"fmt"
"log"
"os"
"path"
"path/filepath"
"strings"
"github.com/emicklei/proto"
"github.com/spf13/cobra"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
// CmdServer the service command.
var CmdServer = &cobra.Command{
Use: "server",
Short: "Generate the proto Server implementations",
Long: "Generate the proto Server implementations. Example: kratos proto server api/xxx.proto -target-dir=internal/service",
Short: "Generate the proto server implementations",
Long: "Generate the proto server implementations. Example: kratos proto server api/xxx.proto --target-dir=internal/service",
Run: run,
}
var targetDir string
@ -24,7 +26,7 @@ func init() {
CmdServer.Flags().StringVarP(&targetDir, "target-dir", "t", "internal/service", "generate target directory")
}
func run(cmd *cobra.Command, args []string) {
func run(_ *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "Please specify the proto file. Example: kratos proto server api/xxx.proto")
return
@ -54,26 +56,27 @@ func run(cmd *cobra.Command, args []string) {
proto.WithService(func(s *proto.Service) {
cs := &Service{
Package: pkg,
Service: s.Name,
Service: serviceName(s.Name),
}
for _, e := range s.Elements {
r, ok := e.(*proto.RPC)
if ok {
cs.Methods = append(cs.Methods, &Method{
Service: s.Name, Name: r.Name, Request: r.RequestType,
Reply: r.ReturnsType, Type: getMethodType(r.StreamsRequest, r.StreamsReturns),
})
if !ok {
continue
}
cs.Methods = append(cs.Methods, &Method{
Service: serviceName(s.Name), Name: serviceName(r.Name), Request: parametersName(r.RequestType),
Reply: parametersName(r.ReturnsType), Type: getMethodType(r.StreamsRequest, r.StreamsReturns),
})
}
res = append(res, cs)
}),
)
if _, err := os.Stat(targetDir); os.IsNotExist(err) {
fmt.Printf("Target directory: %s does not exsits\n", targetDir)
fmt.Printf("Target directory: %s does not exsit\n", targetDir)
return
}
for _, s := range res {
to := path.Join(targetDir, strings.ToLower(s.Service)+".go")
to := filepath.Join(targetDir, strings.ToLower(s.Service)+".go")
if _, err := os.Stat(to); !os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "%s already exists: %s\n", s.Service, to)
continue
@ -101,3 +104,17 @@ func getMethodType(streamsRequest, streamsReturns bool) MethodType {
}
return unaryType
}
func parametersName(name string) string {
return strings.ReplaceAll(name, ".", "_")
}
func serviceName(name string) string {
return toUpperCamelCase(strings.Split(name, ".")[0])
}
func toUpperCamelCase(s string) string {
s = strings.ReplaceAll(s, "_", " ")
s = cases.Title(language.Und, cases.NoLower).String(s)
return strings.ReplaceAll(s, " ", "")
}

@ -0,0 +1,102 @@
package server
import "testing"
func Test_serviceName(t *testing.T) {
type args struct {
str string
}
tests := []struct {
name string
args args
want string
}{
{
name: "serviceName on lowercase words",
args: args{str: "helloworld"},
want: "Helloworld",
},
{
name: "serviceName on uppercase words",
args: args{str: "HELLOWORLD"},
want: "HELLOWORLD",
},
{
name: "serviceName on lowercase words with spaces",
args: args{str: "hello world"},
want: "HelloWorld",
},
{
name: "serviceName on uppercase words with spaces",
args: args{str: "HELLO WORLD"},
want: "HELLOWORLD",
},
{
name: "serviceName on Lower Camel Case words",
args: args{str: "helloWorld"},
want: "HelloWorld",
},
{
name: "serviceName on Lower Camel Case words",
args: args{str: "helloWorld"},
want: "HelloWorld",
},
{
name: "serviceName on Upper Camel Case words",
args: args{str: "HelloWorld"},
want: "HelloWorld",
},
{
name: "serviceName on Upper Camel Case words",
args: args{str: "hello_world"},
want: "HelloWorld",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := serviceName(tt.args.str); got != tt.want {
t.Errorf("serviceName() = %v, want %v", got, tt.want)
}
})
}
}
func Test_parametersName(t *testing.T) {
type args struct {
name string
}
tests := []struct {
name string
args args
want string
}{
{
name: "parametersName on not nested",
args: args{
name: "MessageResponse",
},
want: "MessageResponse",
},
{
name: "parametersName on One layer of nesting",
args: args{
name: "Message.Response",
},
want: "Message_Response",
},
{
name: "parametersName on Two layer of nesting",
args: args{
name: "Message.Message2.Response",
},
want: "Message_Message2_Response",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parametersName(tt.args.name); got != tt.want {
t.Errorf("parametersName() = %v, want %v", got, tt.want)
}
})
}
}

@ -5,6 +5,7 @@ import (
"html/template"
)
//nolint:lll
var serviceTemplate = `
{{- /* delete empty line */ -}}
package service
@ -34,8 +35,7 @@ func New{{ .Service }}Service() *{{ .Service }}Service {
{{- $s1 := "google.protobuf.Empty" }}
{{ range .Methods }}
{{- if eq .Type 1 }}
func (s *{{ .Service }}Service) {{ .Name }}(ctx context.Context, req {{ if eq .Request $s1 }}*emptypb.Empty
{{ else }}*pb.{{ .Request }}{{ end }}) ({{ if eq .Reply $s1 }}*emptypb.Empty{{ else }}*pb.{{ .Reply }}{{ end }}, error) {
func (s *{{ .Service }}Service) {{ .Name }}(ctx context.Context, req {{ if eq .Request $s1 }}*emptypb.Empty{{ else }}*pb.{{ .Request }}{{ end }}) ({{ if eq .Reply $s1 }}*emptypb.Empty{{ else }}*pb.{{ .Reply }}{{ end }}, error) {
return {{ if eq .Reply $s1 }}&emptypb.Empty{}{{ else }}&pb.{{ .Reply }}{}{{ end }}, nil
}

@ -4,7 +4,6 @@ import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
@ -19,12 +18,18 @@ var CmdRun = &cobra.Command{
Long: "Run project. Example: kratos run",
Run: Run,
}
var targetDir string
func init() {
CmdRun.Flags().StringVarP(&targetDir, "work", "w", "", "target working directory")
}
// Run run project.
func Run(cmd *cobra.Command, args []string) {
var dir string
if len(args) > 0 {
dir = args[0]
cmdArgs, programArgs := splitArgs(cmd, args)
if len(cmdArgs) > 0 {
dir = cmdArgs[0]
}
base, err := os.Getwd()
if err != nil {
@ -38,40 +43,58 @@ func Run(cmd *cobra.Command, args []string) {
fmt.Fprintf(os.Stderr, "\033[31mERROR: %s\033[m\n", err)
return
}
if len(cmdPath) == 0 {
switch len(cmdPath) {
case 0:
fmt.Fprintf(os.Stderr, "\033[31mERROR: %s\033[m\n", "The cmd directory cannot be found in the current directory")
return
} else if len(cmdPath) == 1 {
for k, v := range cmdPath {
dir = path.Join(v, k)
case 1:
for _, v := range cmdPath {
dir = v
}
} else {
default:
var cmdPaths []string
for k := range cmdPath {
cmdPaths = append(cmdPaths, k)
}
prompt := &survey.Select{
Message: "Which directory do you want to run?",
Options: cmdPaths,
Message: "Which directory do you want to run?",
Options: cmdPaths,
PageSize: 10,
}
e := survey.AskOne(prompt, &dir)
if e != nil || dir == "" {
return
}
dir = path.Join(cmdPath[dir], dir)
dir = cmdPath[dir]
}
}
fd := exec.Command("go", "run", ".")
fd := exec.Command("go", append([]string{"run", dir}, programArgs...)...)
fd.Stdout = os.Stdout
fd.Stderr = os.Stderr
fd.Dir = dir
changeWorkingDirectory(fd, targetDir)
if err := fd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "\033[31mERROR: %s\033[m\n", err.Error())
return
}
}
func splitArgs(cmd *cobra.Command, args []string) (cmdArgs, programArgs []string) {
dashAt := cmd.ArgsLenAtDash()
if dashAt >= 0 {
return args[:dashAt], args[dashAt:]
}
return args, []string{}
}
func findCMD(base string) (map[string]string, error) {
wd, err := os.Getwd()
if err != nil {
return nil, err
}
if !strings.HasSuffix(wd, "/") {
wd += "/"
}
var root bool
next := func(dir string) (map[string]string, error) {
cmdPath := make(map[string]string)
@ -84,7 +107,8 @@ func findCMD(base string) (map[string]string, error) {
}
for _, fileInfo := range paths {
if fileInfo.IsDir() {
cmdPath[path.Join("cmd", fileInfo.Name())] = filepath.Join(walkPath, "..")
abs := filepath.Join(walkPath, fileInfo.Name())
cmdPath[strings.TrimPrefix(abs, wd)] = abs
}
}
return nil
@ -112,3 +136,10 @@ func findCMD(base string) (map[string]string, error) {
}
return map[string]string{"": base}, nil
}
func changeWorkingDirectory(cmd *exec.Cmd, targetDir string) {
targetDir = strings.TrimSpace(targetDir)
if targetDir != "" {
cmd.Dir = targetDir
}
}

@ -3,9 +3,9 @@ package upgrade
import (
"fmt"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
"github.com/spf13/cobra"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
)
// CmdUpgrade represents the upgrade command.
@ -17,16 +17,14 @@ var CmdUpgrade = &cobra.Command{
}
// Run upgrade the kratos tools.
func Run(cmd *cobra.Command, args []string) {
func Run(_ *cobra.Command, _ []string) {
err := base.GoInstall(
"github.com/go-kratos/kratos/cmd/kratos/v2",
"github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2",
"github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2",
"google.golang.org/protobuf/cmd/protoc-gen-go",
"google.golang.org/grpc/cmd/protoc-gen-go-grpc",
"github.com/envoyproxy/protoc-gen-validate",
"github.com/google/gnostic",
"github.com/google/gnostic/apps/protoc-gen-openapi",
"github.com/go-kratos/kratos/cmd/kratos/v2@latest",
"github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest",
"github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest",
"google.golang.org/protobuf/cmd/protoc-gen-go@latest",
"google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest",
"github.com/google/gnostic/cmd/protoc-gen-openapi@latest",
)
if err != nil {
fmt.Println(err)

@ -3,13 +3,13 @@ package main
import (
"log"
"github.com/spf13/cobra"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/change"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/project"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/proto"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/run"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/upgrade"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{

@ -1,4 +1,4 @@
package main
// release is the current kratos tool version.
const release = "v2.1.4"
const release = "v2.6.3"

@ -3,10 +3,15 @@ package main
import (
"fmt"
"strings"
"unicode"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2/errors"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
"github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2/errors"
)
const (
@ -14,6 +19,8 @@ const (
fmtPackage = protogen.GoImportPath("fmt")
)
var enCases = cases.Title(language.AmericanEnglish, cases.NoLower)
// generateFile generates a _errors.pb.go file containing kratos errors definitions.
func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.GeneratedFile {
if len(file.Enums) == 0 {
@ -42,8 +49,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.
g.P()
index := 0
for _, enum := range file.Enums {
skip := genErrorsReason(gen, file, g, enum)
if !skip {
if !genErrorsReason(gen, file, g, enum) {
index++
}
}
@ -53,7 +59,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.
}
}
func genErrorsReason(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, enum *protogen.Enum) bool {
func genErrorsReason(_ *protogen.Plugin, _ *protogen.File, g *protogen.GeneratedFile, enum *protogen.Enum) bool {
defaultCode := proto.GetExtension(enum.Desc.Options(), errors.E_DefaultCode)
code := 0
if ok := defaultCode.(int32); ok != 0 {
@ -77,11 +83,19 @@ func genErrorsReason(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene
if enumCode == 0 {
continue
}
comment := v.Comments.Leading.String()
if comment == "" {
comment = v.Comments.Trailing.String()
}
err := &errorInfo{
Name: string(enum.Desc.Name()),
Value: string(v.Desc.Name()),
CamelValue: case2Camel(string(v.Desc.Name())),
HTTPCode: enumCode,
Comment: comment,
HasComment: len(comment) > 0,
}
ew.Errors = append(ew.Errors, err)
}
@ -89,19 +103,33 @@ func genErrorsReason(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene
return true
}
g.P(ew.execute())
return false
}
func case2Camel(name string) string {
if !strings.Contains(name, "_") {
upperName := strings.ToUpper(name)
if upperName == name {
if name == strings.ToUpper(name) {
name = strings.ToLower(name)
}
return strings.Title(name)
return enCases.String(name)
}
strs := strings.Split(name, "_")
words := make([]string, 0, len(strs))
for _, w := range strs {
hasLower := false
for _, r := range w {
if unicode.IsLower(r) {
hasLower = true
break
}
}
if !hasLower {
w = strings.ToLower(w)
}
w = enCases.String(w)
words = append(words, w)
}
name = strings.ToLower(name)
name = strings.Replace(name, "_", " ", -1)
name = strings.Title(name)
return strings.Replace(name, " ", "", -1)
return strings.Join(words, "")
}

@ -0,0 +1,17 @@
{{ range .Errors }}
{{ if .HasComment }}{{ .Comment }}{{ end -}}
func Is{{.CamelValue}}(err error) bool {
if err == nil {
return false
}
e := errors.FromError(err)
return e.Reason == {{ .Name }}_{{ .Value }}.String() && e.Code == {{ .HTTPCode }}
}
{{ if .HasComment }}{{ .Comment }}{{ end -}}
func Error{{ .CamelValue }}(format string, args ...interface{}) *errors.Error {
return errors.New({{ .HTTPCode }}, {{ .Name }}_{{ .Value }}.String(), fmt.Sprintf(format, args...))
}
{{- end }}

@ -2,4 +2,7 @@ module github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2
go 1.16
require google.golang.org/protobuf v1.27.1
require (
golang.org/x/text v0.3.8
google.golang.org/protobuf v1.28.0
)

@ -1,8 +1,33 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=

@ -2,32 +2,20 @@ package main
import (
"bytes"
_ "embed"
"text/template"
)
var errorsTemplate = `
{{ range .Errors }}
func Is{{.CamelValue}}(err error) bool {
if err == nil {
return false
}
e := errors.FromError(err)
return e.Reason == {{.Name}}_{{.Value}}.String() && e.Code == {{.HTTPCode}}
}
func Error{{.CamelValue}}(format string, args ...interface{}) *errors.Error {
return errors.New({{.HTTPCode}}, {{.Name}}_{{.Value}}.String(), fmt.Sprintf(format, args...))
}
{{- end }}
`
//go:embed errorsTemplate.tpl
var errorsTemplate string
type errorInfo struct {
Name string
Value string
HTTPCode int
CamelValue string
Comment string
HasComment bool
}
type errorWrapper struct {

@ -1,4 +1,4 @@
package main
// release is the current protoc-gen-go-errors version.
const release = "v2.1.4"
const release = "v2.6.3"

@ -3,8 +3,6 @@ module github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2
go 1.16
require (
github.com/go-kratos/kratos/v2 v2.1.3
github.com/stretchr/testify v1.7.0
google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67
google.golang.org/protobuf v1.27.1
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd
google.golang.org/protobuf v1.28.0
)

@ -1,7 +1,6 @@
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=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
@ -9,30 +8,17 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
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/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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.9-0.20201210154907-fd9021fe5dad/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.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-kratos/aegis v0.1.1/go.mod h1:jYeSQ3Gesba478zEnujOiG5QdsyF3Xk/8owFUeKcHxw=
github.com/go-kratos/kratos/v2 v2.1.3 h1:e2uq6NVJIo24s1flI7aiUp34MyiG40Uc6lI0xv1+iDc=
github.com/go-kratos/kratos/v2 v2.1.3/go.mod h1:/SOOBnLEDEgQRXV9bVVyZsITmxKsilSCc15U8uiNzcI=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
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/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@ -47,7 +33,6 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD
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.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
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=
@ -58,47 +43,28 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
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/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/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
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/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/shirou/gopsutil/v3 v3.21.8/go.mod h1:YWp/H8Qs5fVmf17v7JNZzA0mPJ+mS2e9JdiUF9LlKzQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
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/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg=
go.opentelemetry.io/otel/sdk v1.0.0/go.mod h1:PCrDHlSy5x1kjezSdL37PhbFUMjrsLRshJ2zCzeXwbM=
go.opentelemetry.io/otel/trace v1.0.0/go.mod h1:PXTWqayeFUlJV1YDNhsJYB184+IvAH814St6o6ajzIs=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
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/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
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-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
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-20190108225652-1e06a53dbb7e/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-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -106,35 +72,24 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
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-20190423024810-112230192c58/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-20180830151530-49385e6e1522/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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/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-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/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-20210816074244-15123e1e1f71 h1:ikCpsnYR+Ew0vu99XlDp55lGgDJdIMx3f4a18jfse/s=
golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/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-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
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=
@ -144,17 +99,15 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67 h1:VmMSf20ssFK0+u1dscyTH9bU4/M4y+X/xNfkvD6kGtM=
google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48=
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd h1:e0TwkXOdbnH/1x5rc5MZ/VYyiZ4v+RdVfrGMqEwT68I=
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE=
google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A=
google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
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=
@ -166,15 +119,12 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
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/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
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.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
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=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

@ -2,13 +2,13 @@ package main
import (
"fmt"
"net/http"
"os"
"regexp"
"strings"
"google.golang.org/protobuf/reflect/protoreflect"
"github.com/go-kratos/kratos/v2"
"google.golang.org/genproto/googleapis/api/annotations"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
@ -24,7 +24,7 @@ const (
var methodSets = make(map[string]int)
// generateFile generates a _http.pb.go file containing kratos errors definitions.
func generateFile(gen *protogen.Plugin, file *protogen.File, omitempty bool) *protogen.GeneratedFile {
func generateFile(gen *protogen.Plugin, file *protogen.File, omitempty bool, omitemptyPrefix string) *protogen.GeneratedFile {
if len(file.Services) == 0 || (omitempty && !hasHTTPRule(file.Services)) {
return nil
}
@ -32,16 +32,22 @@ func generateFile(gen *protogen.Plugin, file *protogen.File, omitempty bool) *pr
g := gen.NewGeneratedFile(filename, file.GoImportPath)
g.P("// Code generated by protoc-gen-go-http. DO NOT EDIT.")
g.P("// versions:")
g.P(fmt.Sprintf("// protoc-gen-go-http %s", kratos.Release))
g.P(fmt.Sprintf("// - protoc-gen-go-http %s", release))
g.P("// - protoc ", protocVersion(gen))
if file.Proto.GetOptions().GetDeprecated() {
g.P("// ", file.Desc.Path(), " is a deprecated file.")
} else {
g.P("// source: ", file.Desc.Path())
}
g.P()
g.P("package ", file.GoPackageName)
g.P()
generateFileContent(gen, file, g, omitempty)
generateFileContent(gen, file, g, omitempty, omitemptyPrefix)
return g
}
// generateFileContent generates the kratos errors definitions, excluding the package statement.
func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, omitempty bool) {
func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, omitempty bool, omitemptyPrefix string) {
if len(file.Services) == 0 {
return
}
@ -53,11 +59,11 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.
g.P()
for _, service := range file.Services {
genService(gen, file, g, service, omitempty)
genService(gen, file, g, service, omitempty, omitemptyPrefix)
}
}
func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service, omitempty bool) {
func genService(_ *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service, omitempty bool, omitemptyPrefix string) {
if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() {
g.P("//")
g.P(deprecationComment)
@ -75,12 +81,12 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated
rule, ok := proto.GetExtension(method.Desc.Options(), annotations.E_Http).(*annotations.HttpRule)
if rule != nil && ok {
for _, bind := range rule.AdditionalBindings {
sd.Methods = append(sd.Methods, buildHTTPRule(g, method, bind))
sd.Methods = append(sd.Methods, buildHTTPRule(g, service, method, bind, omitemptyPrefix))
}
sd.Methods = append(sd.Methods, buildHTTPRule(g, method, rule))
sd.Methods = append(sd.Methods, buildHTTPRule(g, service, method, rule, omitemptyPrefix))
} else if !omitempty {
path := fmt.Sprintf("/%s/%s", service.Desc.FullName(), method.Desc.Name())
sd.Methods = append(sd.Methods, buildMethodDesc(g, method, "POST", path))
path := fmt.Sprintf("%s/%s/%s", omitemptyPrefix, service.Desc.FullName(), method.Desc.Name())
sd.Methods = append(sd.Methods, buildMethodDesc(g, method, http.MethodPost, path))
}
}
if len(sd.Methods) != 0 {
@ -103,42 +109,53 @@ func hasHTTPRule(services []*protogen.Service) bool {
return false
}
func buildHTTPRule(g *protogen.GeneratedFile, m *protogen.Method, rule *annotations.HttpRule) *methodDesc {
func buildHTTPRule(g *protogen.GeneratedFile, service *protogen.Service, m *protogen.Method, rule *annotations.HttpRule, omitemptyPrefix string) *methodDesc {
var (
path string
method string
body string
responseBody string
)
switch pattern := rule.Pattern.(type) {
case *annotations.HttpRule_Get:
path = pattern.Get
method = "GET"
method = http.MethodGet
case *annotations.HttpRule_Put:
path = pattern.Put
method = "PUT"
method = http.MethodPut
case *annotations.HttpRule_Post:
path = pattern.Post
method = "POST"
method = http.MethodPost
case *annotations.HttpRule_Delete:
path = pattern.Delete
method = "DELETE"
method = http.MethodDelete
case *annotations.HttpRule_Patch:
path = pattern.Patch
method = "PATCH"
method = http.MethodPatch
case *annotations.HttpRule_Custom:
path = pattern.Custom.Path
method = pattern.Custom.Kind
}
if method == "" {
method = http.MethodPost
}
if path == "" {
path = fmt.Sprintf("%s/%s/%s", omitemptyPrefix, service.Desc.FullName(), m.Desc.Name())
}
body = rule.Body
responseBody = rule.ResponseBody
md := buildMethodDesc(g, m, method, path)
if method == "GET" || method == "DELETE" {
if method == http.MethodGet || method == http.MethodDelete {
if body != "" {
_, _ = fmt.Fprintf(os.Stderr, "\u001B[31mWARN\u001B[m: %s %s body should not be declared.\n", method, path)
}
md.HasBody = false
} else if body == "*" {
} else {
if body == "" {
_, _ = fmt.Fprintf(os.Stderr, "\u001B[31mWARN\u001B[m: %s %s does not declare a body.\n", method, path)
}
}
if body == "*" {
md.HasBody = true
md.Body = ""
} else if body != "" {
@ -146,7 +163,6 @@ func buildHTTPRule(g *protogen.GeneratedFile, m *protogen.Method, rule *annotati
md.Body = "." + camelCaseVars(body)
} else {
md.HasBody = false
_, _ = fmt.Fprintf(os.Stderr, "\u001B[31mWARN\u001B[m: %s %s does not declare a body.\n", method, path)
}
if responseBody == "*" {
md.ResponseBody = ""
@ -160,9 +176,10 @@ func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path
defer func() { methodSets[m.GoName]++ }()
vars := buildPathVars(path)
fields := m.Input.Desc.Fields()
for v, s := range vars {
fields := m.Input.Desc.Fields()
if s != nil {
path = replacePath(v, *s, path)
}
@ -187,21 +204,30 @@ func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path
}
}
}
comment := m.Comments.Leading.String() + m.Comments.Trailing.String()
if comment != "" {
comment = "// " + m.GoName + strings.TrimPrefix(strings.TrimSuffix(comment, "\n"), "//")
}
return &methodDesc{
Name: m.GoName,
Num: methodSets[m.GoName],
Request: g.QualifiedGoIdent(m.Input.GoIdent),
Reply: g.QualifiedGoIdent(m.Output.GoIdent),
Path: path,
Method: method,
HasVars: len(vars) > 0,
Name: m.GoName,
OriginalName: string(m.Desc.Name()),
Num: methodSets[m.GoName],
Request: g.QualifiedGoIdent(m.Input.GoIdent),
Reply: g.QualifiedGoIdent(m.Output.GoIdent),
Comment: comment,
Path: path,
Method: method,
HasVars: len(vars) > 0,
}
}
func buildPathVars(path string) (res map[string]*string) {
res = make(map[string]*string)
pattern := regexp.MustCompile(`(?i){([a-z\.0-9_\s]*)=?([^{}]*)}`)
if strings.HasSuffix(path, "/") {
fmt.Fprintf(os.Stderr, "\u001B[31mWARN\u001B[m: Path %s should not end with \"/\" \n", path)
}
pattern := regexp.MustCompile(`(?i){([a-z.0-9_\s]*)=?([^{}]*)}`)
matches := pattern.FindAllStringSubmatch(path, -1)
res = make(map[string]*string, len(matches))
for _, m := range matches {
name := strings.TrimSpace(m[1])
if len(name) > 1 && len(m[2]) > 0 {
@ -228,8 +254,8 @@ func replacePath(name string, value string, path string) string {
}
func camelCaseVars(s string) string {
vars := make([]string, 0)
subs := strings.Split(s, ".")
vars := make([]string, 0, len(subs))
for _, sub := range subs {
vars = append(vars, camelCase(sub))
}
@ -241,8 +267,8 @@ func camelCaseVars(s string) string {
// drop the underscore and convert the letter to upper case.
// There is a remote possibility of this rewrite causing a name collision,
// but it's so remote we're prepared to pretend it's nonexistent - since the
// C++ generator lowercases names, it's extremely unlikely to have two fields
// with different capitalizations.
// C++ generator lowercase names, it's extremely unlikely to have two fields
// with different capitalization.
// In short, _my_field_name_2 becomes XMyFieldName_2.
func camelCase(s string) string {
if s == "" {
@ -293,4 +319,16 @@ func isASCIIDigit(c byte) bool {
return '0' <= c && c <= '9'
}
func protocVersion(gen *protogen.Plugin) string {
v := gen.Request.GetCompilerVersion()
if v == nil {
return "(unknown)"
}
var suffix string
if s := v.GetSuffix(); s != "" {
suffix = "-" + s
}
return fmt.Sprintf("v%d.%d.%d%s", v.GetMajor(), v.GetMinor(), v.GetPatch(), suffix)
}
const deprecationComment = "// Deprecated: Do not use."

@ -0,0 +1,93 @@
{{$svrType := .ServiceType}}
{{$svrName := .ServiceName}}
{{- range .MethodSets}}
const Operation{{$svrType}}{{.OriginalName}} = "/{{$svrName}}/{{.OriginalName}}"
{{- end}}
type {{.ServiceType}}HTTPServer interface {
{{- range .MethodSets}}
{{- if ne .Comment ""}}
{{.Comment}}
{{- end}}
{{.Name}}(context.Context, *{{.Request}}) (*{{.Reply}}, error)
{{- end}}
}
func Register{{.ServiceType}}HTTPServer(s *http.Server, srv {{.ServiceType}}HTTPServer) {
r := s.Route("/")
{{- range .Methods}}
r.{{.Method}}("{{.Path}}", _{{$svrType}}_{{.Name}}{{.Num}}_HTTP_Handler(srv))
{{- end}}
}
{{range .Methods}}
func _{{$svrType}}_{{.Name}}{{.Num}}_HTTP_Handler(srv {{$svrType}}HTTPServer) func(ctx http.Context) error {
return func(ctx http.Context) error {
var in {{.Request}}
{{- if .HasBody}}
if err := ctx.Bind(&in{{.Body}}); err != nil {
return err
}
{{- if not (eq .Body "")}}
if err := ctx.BindQuery(&in); err != nil {
return err
}
{{- end}}
{{- else}}
if err := ctx.BindQuery(&in{{.Body}}); err != nil {
return err
}
{{- end}}
{{- if .HasVars}}
if err := ctx.BindVars(&in); err != nil {
return err
}
{{- end}}
http.SetOperation(ctx,Operation{{$svrType}}{{.OriginalName}})
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.{{.Name}}(ctx, req.(*{{.Request}}))
})
out, err := h(ctx, &in)
if err != nil {
return err
}
reply := out.(*{{.Reply}})
return ctx.Result(200, reply{{.ResponseBody}})
}
}
{{end}}
type {{.ServiceType}}HTTPClient interface {
{{- range .MethodSets}}
{{.Name}}(ctx context.Context, req *{{.Request}}, opts ...http.CallOption) (rsp *{{.Reply}}, err error)
{{- end}}
}
type {{.ServiceType}}HTTPClientImpl struct{
cc *http.Client
}
func New{{.ServiceType}}HTTPClient (client *http.Client) {{.ServiceType}}HTTPClient {
return &{{.ServiceType}}HTTPClientImpl{client}
}
{{range .MethodSets}}
func (c *{{$svrType}}HTTPClientImpl) {{.Name}}(ctx context.Context, in *{{.Request}}, opts ...http.CallOption) (*{{.Reply}}, error) {
var out {{.Reply}}
pattern := "{{.Path}}"
path := binding.EncodeURL(pattern, in, {{not .HasBody}})
opts = append(opts, http.Operation(Operation{{$svrType}}{{.OriginalName}}))
opts = append(opts, http.PathTemplate(pattern))
{{if .HasBody -}}
err := c.cc.Invoke(ctx, "{{.Method}}", path, in{{.Body}}, &out{{.ResponseBody}}, opts...)
{{else -}}
err := c.cc.Invoke(ctx, "{{.Method}}", path, nil, &out{{.ResponseBody}}, opts...)
{{end -}}
if err != nil {
return nil, err
}
return &out, err
}
{{end}}

@ -1,45 +1,63 @@
package main
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNoParameters(t *testing.T) {
path := "/test/noparams"
m := buildPathVars(path)
assert.Emptyf(t, m, "Map should be empty")
if !reflect.DeepEqual(m, map[string]*string{}) {
t.Fatalf("Map should be empty")
}
}
func TestSingleParam(t *testing.T) {
path := "/test/{message.id}"
m := buildPathVars(path)
assert.Len(t, m, 1)
assert.Empty(t, m["message.id"])
if !reflect.DeepEqual(len(m), 1) {
t.Fatalf("len(m) not is 1")
}
if m["message.id"] != nil {
t.Fatalf(`m["message.id"] should be empty`)
}
}
func TestTwoParametersReplacement(t *testing.T) {
path := "/test/{message.id}/{message.name=messages/*}"
m := buildPathVars(path)
assert.Len(t, m, 2)
assert.Empty(t, m["message.id"])
assert.NotEmpty(t, m["message.name"])
assert.Equal(t, *m["message.name"], "messages/*")
if len(m) != 2 {
t.Fatal("len(m) should be 2")
}
if m["message.id"] != nil {
t.Fatal(`m["message.id"] should be nil`)
}
if m["message.name"] == nil {
t.Fatal(`m["message.name"] should not be nil`)
}
if *m["message.name"] != "messages/*" {
t.Fatal(`m["message.name"] should be "messages/*"`)
}
}
func TestNoReplacePath(t *testing.T) {
path := "/test/{message.id=test}"
assert.Equal(t, "/test/{message.id:test}", replacePath("message.id", "test", path))
if !reflect.DeepEqual(replacePath("message.id", "test", path), "/test/{message.id:test}") {
t.Fatal(`replacePath("message.id", "test", path) should be "/test/{message.id:test}"`)
}
path = "/test/{message.id=test/*}"
assert.Equal(t, "/test/{message.id:test/.*}", replacePath("message.id", "test/*", path))
if !reflect.DeepEqual(replacePath("message.id", "test/*", path), "/test/{message.id:test/.*}") {
t.Fatal(`replacePath("message.id", "test/*", path) should be "/test/{message.id:test/.*}"`)
}
}
func TestReplacePath(t *testing.T) {
path := "/test/{message.id}/{message.name=messages/*}"
newPath := replacePath("message.name", "messages/*", path)
assert.Equal(t, "/test/{message.id}/{message.name:messages/.*}", newPath)
if !reflect.DeepEqual("/test/{message.id}/{message.name:messages/.*}", newPath) {
t.Fatal(`replacePath("message.name", "messages/*", path) should be "/test/{message.id}/{message.name:messages/.*}"`)
}
}
func TestIteration(t *testing.T) {
@ -50,7 +68,9 @@ func TestIteration(t *testing.T) {
path = replacePath(v, *s, path)
}
}
assert.Equal(t, "/test/{message.id}/{message.name:messages/.*}", path)
if !reflect.DeepEqual("/test/{message.id}/{message.name:messages/.*}", path) {
t.Fatal(`replacePath("message.name", "messages/*", path) should be "/test/{message.id}/{message.name:messages/.*}"`)
}
}
func TestIterationMiddle(t *testing.T) {
@ -61,5 +81,7 @@ func TestIterationMiddle(t *testing.T) {
path = replacePath(v, *s, path)
}
}
assert.Equal(t, "/test/{message.name:messages/.*}/books", path)
if !reflect.DeepEqual("/test/{message.name:messages/.*}/books", path) {
t.Fatal(`replacePath("message.name", "messages/*", path) should be "/test/{message.name:messages/.*}/books"`)
}
}

@ -9,8 +9,9 @@ import (
)
var (
showVersion = flag.Bool("version", false, "print the version and exit")
omitempty = flag.Bool("omitempty", true, "omit if google.api is empty")
showVersion = flag.Bool("version", false, "print the version and exit")
omitempty = flag.Bool("omitempty", true, "omit if google.api is empty")
omitemptyPrefix = flag.String("omitempty_prefix", "", "omit if google.api is empty")
)
func main() {
@ -27,7 +28,7 @@ func main() {
if !f.Generate {
continue
}
generateFile(gen, f, *omitempty)
generateFile(gen, f, *omitempty, *omitemptyPrefix)
}
return nil
})

@ -2,97 +2,13 @@ package main
import (
"bytes"
_ "embed"
"strings"
"text/template"
)
var httpTemplate = `
{{$svrType := .ServiceType}}
{{$svrName := .ServiceName}}
type {{.ServiceType}}HTTPServer interface {
{{- range .MethodSets}}
{{.Name}}(context.Context, *{{.Request}}) (*{{.Reply}}, error)
{{- end}}
}
func Register{{.ServiceType}}HTTPServer(s *http.Server, srv {{.ServiceType}}HTTPServer) {
r := s.Route("/")
{{- range .Methods}}
r.{{.Method}}("{{.Path}}", _{{$svrType}}_{{.Name}}{{.Num}}_HTTP_Handler(srv))
{{- end}}
}
{{range .Methods}}
func _{{$svrType}}_{{.Name}}{{.Num}}_HTTP_Handler(srv {{$svrType}}HTTPServer) func(ctx http.Context) error {
return func(ctx http.Context) error {
var in {{.Request}}
{{- if .HasBody}}
if err := ctx.Bind(&in{{.Body}}); err != nil {
return err
}
{{- if not (eq .Body "")}}
if err := ctx.BindQuery(&in); err != nil {
return err
}
{{- end}}
{{- else}}
if err := ctx.BindQuery(&in{{.Body}}); err != nil {
return err
}
{{- end}}
{{- if .HasVars}}
if err := ctx.BindVars(&in); err != nil {
return err
}
{{- end}}
http.SetOperation(ctx,"/{{$svrName}}/{{.Name}}")
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.{{.Name}}(ctx, req.(*{{.Request}}))
})
out, err := h(ctx, &in)
if err != nil {
return err
}
reply := out.(*{{.Reply}})
return ctx.Result(200, reply{{.ResponseBody}})
}
}
{{end}}
type {{.ServiceType}}HTTPClient interface {
{{- range .MethodSets}}
{{.Name}}(ctx context.Context, req *{{.Request}}, opts ...http.CallOption) (rsp *{{.Reply}}, err error)
{{- end}}
}
type {{.ServiceType}}HTTPClientImpl struct{
cc *http.Client
}
func New{{.ServiceType}}HTTPClient (client *http.Client) {{.ServiceType}}HTTPClient {
return &{{.ServiceType}}HTTPClientImpl{client}
}
{{range .MethodSets}}
func (c *{{$svrType}}HTTPClientImpl) {{.Name}}(ctx context.Context, in *{{.Request}}, opts ...http.CallOption) (*{{.Reply}}, error) {
var out {{.Reply}}
pattern := "{{.Path}}"
path := binding.EncodeURL(pattern, in, {{not .HasBody}})
opts = append(opts, http.Operation("/{{$svrName}}/{{.Name}}"))
opts = append(opts, http.PathTemplate(pattern))
{{if .HasBody -}}
err := c.cc.Invoke(ctx, "{{.Method}}", path, in{{.Body}}, &out{{.ResponseBody}}, opts...)
{{else -}}
err := c.cc.Invoke(ctx, "{{.Method}}", path, nil, &out{{.ResponseBody}}, opts...)
{{end -}}
if err != nil {
return nil, err
}
return &out, err
}
{{end}}
`
//go:embed httpTemplate.tpl
var httpTemplate string
type serviceDesc struct {
ServiceType string // Greeter
@ -104,10 +20,12 @@ type serviceDesc struct {
type methodDesc struct {
// method
Name string
Num int
Request string
Reply string
Name string
OriginalName string // The parsed original name
Num int
Request string
Reply string
Comment string
// http_rule
Path string
Method string

@ -1,4 +1,4 @@
package main
// release is the current protoc-gen-go-http version.
const release = "v2.1.4"
const release = "v2.6.3"

@ -7,22 +7,21 @@ import (
"sync"
"time"
"github.com/go-kratos/kratos/v2/log"
// init encoding
_ "github.com/go-kratos/kratos/v2/encoding/json"
_ "github.com/go-kratos/kratos/v2/encoding/proto"
_ "github.com/go-kratos/kratos/v2/encoding/xml"
_ "github.com/go-kratos/kratos/v2/encoding/yaml"
"github.com/go-kratos/kratos/v2/log"
)
var _ Config = (*config)(nil)
var (
// ErrNotFound is key not found.
ErrNotFound = errors.New("key not found")
// ErrTypeAssert is type assert error.
ErrTypeAssert = errors.New("type assert error")
_ Config = (*config)(nil)
)
// Observer is config observer.
@ -43,13 +42,11 @@ type config struct {
cached sync.Map
observers sync.Map
watchers []Watcher
log *log.Helper
}
// New new a config with options.
// New a config with options.
func New(opts ...Option) Config {
o := options{
logger: log.DefaultLogger,
decoder: defaultDecoder,
resolver: defaultResolver,
}
@ -59,34 +56,33 @@ func New(opts ...Option) Config {
return &config{
opts: o,
reader: newReader(o),
log: log.NewHelper(o.logger),
}
}
func (c *config) watch(w Watcher) {
for {
kvs, err := w.Next()
if errors.Is(err, context.Canceled) {
c.log.Infof("watcher's ctx cancel : %v", err)
return
}
if err != nil {
if errors.Is(err, context.Canceled) {
log.Infof("watcher's ctx cancel : %v", err)
return
}
time.Sleep(time.Second)
c.log.Errorf("failed to watch next config: %v", err)
log.Errorf("failed to watch next config: %v", err)
continue
}
if err := c.reader.Merge(kvs...); err != nil {
c.log.Errorf("failed to merge next config: %v", err)
log.Errorf("failed to merge next config: %v", err)
continue
}
if err := c.reader.Resolve(); err != nil {
c.log.Errorf("failed to resolve next config: %v", err)
log.Errorf("failed to resolve next config: %v", err)
continue
}
c.cached.Range(func(key, value interface{}) bool {
k := key.(string)
v := value.(Value)
if n, ok := c.reader.Value(k); ok && !reflect.DeepEqual(n.Load(), v.Load()) {
if n, ok := c.reader.Value(k); ok && reflect.TypeOf(n.Load()) == reflect.TypeOf(v.Load()) && !reflect.DeepEqual(n.Load(), v.Load()) {
v.Store(n.Load())
if o, ok := c.observers.Load(k); ok {
o.(Observer)(k, v)
@ -104,22 +100,22 @@ func (c *config) Load() error {
return err
}
for _, v := range kvs {
c.log.Infof("config loaded: %s format: %s", v.Key, v.Format)
log.Debugf("config loaded: %s format: %s", v.Key, v.Format)
}
if err = c.reader.Merge(kvs...); err != nil {
c.log.Errorf("failed to merge config source: %v", err)
log.Errorf("failed to merge config source: %v", err)
return err
}
w, err := src.Watch()
if err != nil {
c.log.Errorf("failed to watch config source: %v", err)
log.Errorf("failed to watch config source: %v", err)
return err
}
c.watchers = append(c.watchers, w)
go c.watch(w)
}
if err := c.reader.Resolve(); err != nil {
c.log.Errorf("failed to resolve config source: %v", err)
log.Errorf("failed to resolve config source: %v", err)
return err
}
return nil

@ -3,9 +3,6 @@ package config
import (
"errors"
"testing"
"github.com/go-kratos/kratos/v2/log"
"github.com/stretchr/testify/assert"
)
const (
@ -123,44 +120,65 @@ func TestConfig(t *testing.T) {
WithSource(newTestJSONSource(_testJSON)),
WithDecoder(defaultDecoder),
WithResolver(defaultResolver),
WithLogger(log.DefaultLogger),
)
err = c.Close()
assert.Nil(t, err)
if err != nil {
t.Fatal(err)
}
jSource := newTestJSONSource(_testJSON)
opts := options{
sources: []Source{jSource},
decoder: defaultDecoder,
resolver: defaultResolver,
logger: log.DefaultLogger,
}
cf := &config{}
cf.opts = opts
cf.reader = newReader(opts)
cf.log = log.NewHelper(opts.logger)
err = cf.Load()
assert.Nil(t, err)
if err != nil {
t.Fatal(err)
}
val, err := cf.Value("data.database.driver").String()
assert.Nil(t, err)
assert.Equal(t, databaseDriver, val)
driver, err := cf.Value("data.database.driver").String()
if err != nil {
t.Fatal(err)
}
if databaseDriver != driver {
t.Fatal("databaseDriver is not equal to val")
}
err = cf.Watch("endpoints", func(key string, value Value) {
})
assert.Nil(t, err)
if err != nil {
t.Fatal(err)
}
jSource.sig <- struct{}{}
jSource.err <- struct{}{}
var testConf testConfigStruct
err = cf.Scan(&testConf)
assert.Nil(t, err)
assert.Equal(t, httpAddr, testConf.Server.HTTP.Addr)
assert.Equal(t, httpTimeout, testConf.Server.HTTP.Timeout)
assert.Equal(t, true, testConf.Server.HTTP.EnableSSL)
assert.Equal(t, grpcPort, testConf.Server.GRPC.Port)
assert.Equal(t, endpoint1, testConf.Endpoints[0])
assert.Equal(t, 2, len(testConf.Endpoints))
if err != nil {
t.Fatal(err)
}
if httpAddr != testConf.Server.HTTP.Addr {
t.Errorf("testConf.Server.HTTP.Addr want: %s, got: %s", httpAddr, testConf.Server.HTTP.Addr)
}
if httpTimeout != testConf.Server.HTTP.Timeout {
t.Errorf("testConf.Server.HTTP.Timeout want: %.1f, got: %.1f", httpTimeout, testConf.Server.HTTP.Timeout)
}
if !testConf.Server.HTTP.EnableSSL {
t.Error("testConf.Server.HTTP.EnableSSL is not equal to true")
}
if grpcPort != testConf.Server.GRPC.Port {
t.Errorf("testConf.Server.GRPC.Port want: %d, got: %d", grpcPort, testConf.Server.GRPC.Port)
}
if endpoint1 != testConf.Endpoints[0] {
t.Errorf("testConf.Endpoints[0] want: %s, got: %s", endpoint1, testConf.Endpoints[0])
}
if len(testConf.Endpoints) != 2 {
t.Error("len(testConf.Endpoints) is not equal to 2")
}
}

16
config/env/env.go vendored

@ -8,29 +8,29 @@ import (
)
type env struct {
prefixs []string
prefixes []string
}
func NewSource(prefixs ...string) config.Source {
return &env{prefixs: prefixs}
func NewSource(prefixes ...string) config.Source {
return &env{prefixes: prefixes}
}
func (e *env) Load() (kv []*config.KeyValue, err error) {
return e.load(os.Environ()), nil
}
func (e *env) load(envStrings []string) []*config.KeyValue {
func (e *env) load(envs []string) []*config.KeyValue {
var kv []*config.KeyValue
for _, envstr := range envStrings {
for _, env := range envs {
var k, v string
subs := strings.SplitN(envstr, "=", 2) //nolint:gomnd
subs := strings.SplitN(env, "=", 2) //nolint:gomnd
k = subs[0]
if len(subs) > 1 {
v = subs[1]
}
if len(e.prefixs) > 0 {
p, ok := matchPrefix(e.prefixs, k)
if len(e.prefixes) > 0 {
p, ok := matchPrefix(e.prefixes, k)
if !ok || len(p) == len(k) {
continue
}

@ -8,7 +8,6 @@ import (
"github.com/go-kratos/kratos/v2/config"
"github.com/go-kratos/kratos/v2/config/file"
"github.com/stretchr/testify/assert"
)
const _testJSON = `
@ -107,19 +106,27 @@ func TestEnvWithPrefix(t *testing.T) {
switch test.expect.(type) {
case int:
if actual, err = v.Int(); err == nil {
assert.Equal(t, test.expect, int(actual.(int64)), "int value should be equal")
if !reflect.DeepEqual(test.expect.(int), int(actual.(int64))) {
t.Errorf("expect %v, actual %v", test.expect, actual)
}
}
case string:
if actual, err = v.String(); err == nil {
assert.Equal(t, test.expect, actual, "string value should be equal")
if !reflect.DeepEqual(test.expect.(string), actual.(string)) {
t.Errorf(`expect %v, actual %v`, test.expect, actual)
}
}
case bool:
if actual, err = v.Bool(); err == nil {
assert.Equal(t, test.expect, actual, "bool value should be equal")
if !reflect.DeepEqual(test.expect.(bool), actual.(bool)) {
t.Errorf(`expect %v, actual %v`, test.expect, actual)
}
}
case float64:
if actual, err = v.Float(); err == nil {
assert.Equal(t, test.expect, actual, "float64 value should be equal")
if !reflect.DeepEqual(test.expect.(float64), actual.(float64)) {
t.Errorf(`expect %v, actual %v`, test.expect, actual)
}
}
default:
actual = v.Load()
@ -213,19 +220,27 @@ func TestEnvWithoutPrefix(t *testing.T) {
switch test.expect.(type) {
case int:
if actual, err = v.Int(); err == nil {
assert.Equal(t, test.expect, int(actual.(int64)), "int value should be equal")
if !reflect.DeepEqual(test.expect.(int), int(actual.(int64))) {
t.Errorf("expect %v, actual %v", test.expect, actual)
}
}
case string:
if actual, err = v.String(); err == nil {
assert.Equal(t, test.expect, actual, "string value should be equal")
if !reflect.DeepEqual(test.expect.(string), actual.(string)) {
t.Errorf(`expect %v, actual %v`, test.expect, actual)
}
}
case bool:
if actual, err = v.Bool(); err == nil {
assert.Equal(t, test.expect, actual, "bool value should be equal")
if !reflect.DeepEqual(test.expect.(bool), actual.(bool)) {
t.Errorf(`expect %v, actual %v`, test.expect, actual)
}
}
case float64:
if actual, err = v.Float(); err == nil {
assert.Equal(t, test.expect, actual, "float64 value should be equal")
if !reflect.DeepEqual(test.expect.(float64), actual.(float64)) {
t.Errorf(`expect %v, actual %v`, test.expect, actual)
}
}
default:
actual = v.Load()
@ -246,7 +261,7 @@ func TestEnvWithoutPrefix(t *testing.T) {
func Test_env_load(t *testing.T) {
type fields struct {
prefixs []string
prefixes []string
}
type args struct {
envStrings []string
@ -260,7 +275,7 @@ func Test_env_load(t *testing.T) {
{
name: "without prefixes",
fields: fields{
prefixs: nil,
prefixes: nil,
},
args: args{
envStrings: []string{
@ -279,7 +294,7 @@ func Test_env_load(t *testing.T) {
{
name: "empty prefix",
fields: fields{
prefixs: []string{""},
prefixes: []string{""},
},
args: args{
envStrings: []string{
@ -298,7 +313,7 @@ func Test_env_load(t *testing.T) {
{
name: "underscore prefix",
fields: fields{
prefixs: []string{"_"},
prefixes: []string{"_"},
},
args: args{
envStrings: []string{
@ -317,7 +332,7 @@ func Test_env_load(t *testing.T) {
{
name: "with prefixes",
fields: fields{
prefixs: []string{"KRATOS_", "FOO"},
prefixes: []string{"KRATOS_", "FOO"},
},
args: args{
envStrings: []string{
@ -336,7 +351,7 @@ func Test_env_load(t *testing.T) {
{
name: "should not panic #1",
fields: fields{
prefixs: []string{"FOO"},
prefixes: []string{"FOO"},
},
args: args{
envStrings: []string{
@ -349,7 +364,7 @@ func Test_env_load(t *testing.T) {
{
name: "should not panic #2",
fields: fields{
prefixs: []string{"FOO=1"},
prefixes: []string{"FOO=1"},
},
args: args{
envStrings: []string{
@ -362,7 +377,7 @@ func Test_env_load(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := &env{
prefixs: tt.fields.prefixs,
prefixes: tt.fields.prefixes,
}
got := e.load(tt.args.envStrings)
if !reflect.DeepEqual(tt.want, got) {
@ -402,3 +417,13 @@ func Test_matchPrefix(t *testing.T) {
})
}
}
func Test_env_watch(t *testing.T) {
prefixes := []string{"BAR", "FOO"}
source := NewSource(prefixes...)
w, err := source.Watch()
if err != nil {
t.Errorf("expect no err, got %v", err)
}
_ = w.Stop()
}

@ -6,13 +6,13 @@ import (
"github.com/go-kratos/kratos/v2/config"
)
var _ config.Watcher = (*watcher)(nil)
type watcher struct {
ctx context.Context
cancel context.CancelFunc
}
var _ config.Watcher = (*watcher)(nil)
func NewWatcher() (config.Watcher, error) {
ctx, cancel := context.WithCancel(context.Background())
return &watcher{ctx: ctx, cancel: cancel}, nil

@ -2,26 +2,29 @@ package env
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_watcher_next(t *testing.T) {
t.Run("next after stop should return err", func(t *testing.T) {
w, err := NewWatcher()
require.NoError(t, err)
if err != nil {
t.Errorf("expect no error, got %v", err)
}
_ = w.Stop()
_, err = w.Next()
assert.Error(t, err)
if err == nil {
t.Error("expect error, actual nil")
}
})
}
func Test_watcher_stop(t *testing.T) {
t.Run("stop multiple times should not panic", func(t *testing.T) {
w, err := NewWatcher()
require.NoError(t, err)
if err != nil {
t.Errorf("expect no error, got %v", err)
}
_ = w.Stop()
_ = w.Stop()

@ -42,7 +42,7 @@ func (f *file) loadFile(path string) (*config.KeyValue, error) {
}
func (f *file) loadDir(path string) (kvs []*config.KeyValue, err error) {
files, err := os.ReadDir(f.path)
files, err := os.ReadDir(path)
if err != nil {
return nil, err
}
@ -51,7 +51,7 @@ func (f *file) loadDir(path string) (kvs []*config.KeyValue, err error) {
if file.IsDir() || strings.HasPrefix(file.Name(), ".") {
continue
}
kv, err := f.loadFile(filepath.Join(f.path, file.Name()))
kv, err := f.loadFile(filepath.Join(path, file.Name()))
if err != nil {
return nil, err
}

@ -4,12 +4,12 @@ import (
"errors"
"os"
"path/filepath"
"reflect"
"sync"
"testing"
"time"
"github.com/go-kratos/kratos/v2/config"
"github.com/stretchr/testify/assert"
)
const (
@ -120,19 +120,29 @@ func testWatchFile(t *testing.T, path string) {
t.Error(err)
}
kvs, err := watch.Next()
assert.Nil(t, err)
assert.Equal(t, string(kvs[0].Value), _testJSONUpdate)
if err != nil {
t.Errorf("watch.Next() error(%v)", err)
}
if !reflect.DeepEqual(string(kvs[0].Value), _testJSONUpdate) {
t.Errorf("string(kvs[0].Value(%v) is not equal to _testJSONUpdate(%v)", kvs[0].Value, _testJSONUpdate)
}
newFilepath := filepath.Join(filepath.Dir(path), "test1.json")
if err = os.Rename(path, newFilepath); err != nil {
t.Error(err)
}
kvs, err = watch.Next()
assert.NotNil(t, err)
assert.Nil(t, kvs)
if err == nil {
t.Errorf("watch.Next() error(%v)", err)
}
if kvs != nil {
t.Errorf("watch.Next() error(%v)", err)
}
err = watch.Stop()
assert.Nil(t, err)
if err != nil {
t.Errorf("watch.Stop() error(%v)", err)
}
if err := os.Rename(newFilepath, path); err != nil {
t.Error(err)
@ -160,8 +170,12 @@ func testWatchDir(t *testing.T, path, file string) {
}
kvs, err := watch.Next()
assert.Nil(t, err)
assert.Equal(t, string(kvs[0].Value), _testJSONUpdate)
if err != nil {
t.Errorf("watch.Next() error(%v)", err)
}
if !reflect.DeepEqual(string(kvs[0].Value), _testJSONUpdate) {
t.Errorf("string(kvs[0].Value(%s) is not equal to _testJSONUpdate(%v)", kvs[0].Value, _testJSONUpdate)
}
}
func testSource(t *testing.T, path string, data []byte) {
@ -194,7 +208,7 @@ func TestConfig(t *testing.T) {
func testConfig(t *testing.T, c config.Config) {
expected := map[string]interface{}{
"test.settings.int_key": int64(1000),
"test.settings.float_key": float64(1000.1),
"test.settings.float_key": 1000.1,
"test.settings.string_key": "string_value",
"test.settings.duration_key": time.Duration(10000),
"test.server.addr": "127.0.0.1",

@ -0,0 +1,43 @@
package file
import (
"testing"
)
func TestFormat(t *testing.T) {
tests := []struct {
input string
expect string
}{
{
input: "",
expect: "",
},
{
input: " ",
expect: "",
},
{
input: ".",
expect: "",
},
{
input: "a.",
expect: "",
},
{
input: ".b",
expect: "b",
},
{
input: "a.b",
expect: "b",
},
}
for _, v := range tests {
content := format(v.input)
if got, want := content, v.expect; got != want {
t.Errorf("expect %v,got %v", want, got)
}
}
}

@ -6,9 +6,12 @@ import (
"path/filepath"
"github.com/fsnotify/fsnotify"
"github.com/go-kratos/kratos/v2/config"
)
var _ config.Watcher = (*watcher)(nil)
type watcher struct {
f *file
fw *fsnotify.Watcher
@ -17,8 +20,6 @@ type watcher struct {
cancel context.CancelFunc
}
var _ config.Watcher = (*watcher)(nil)
func newWatcher(f *file) (config.Watcher, error) {
fw, err := fsnotify.NewWatcher()
if err != nil {

@ -22,7 +22,6 @@ type options struct {
sources []Source
decoder Decoder
resolver Resolver
logger log.Logger
}
// WithSource with config source.
@ -51,10 +50,9 @@ func WithResolver(r Resolver) Option {
}
// WithLogger with config logger.
func WithLogger(l log.Logger) Option {
return func(o *options) {
o.logger = l
}
// Deprecated: use global logger instead.
func WithLogger(_ log.Logger) Option {
return func(o *options) {}
}
// defaultDecoder decode config from source KeyValue

@ -2,9 +2,8 @@ package config
import (
"reflect"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDefaultDecoder(t *testing.T) {
@ -15,10 +14,12 @@ func TestDefaultDecoder(t *testing.T) {
}
target := make(map[string]interface{})
err := defaultDecoder(src, target)
assert.Nil(t, err)
assert.Equal(t, map[string]interface{}{
"service": []byte("config"),
}, target)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(target, map[string]interface{}{"service": []byte("config")}) {
t.Fatal(`target is not equal to map[string]interface{}{"service": "config"}`)
}
src = &KeyValue{
Key: "service.name.alias",
@ -27,14 +28,18 @@ func TestDefaultDecoder(t *testing.T) {
}
target = make(map[string]interface{})
err = defaultDecoder(src, target)
assert.Nil(t, err)
assert.Equal(t, map[string]interface{}{
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(map[string]interface{}{
"service": map[string]interface{}{
"name": map[string]interface{}{
"alias": []byte("2233"),
},
},
}, target)
}, target) {
t.Fatal(`target is not equal to map[string]interface{}{"service": map[string]interface{}{"name": map[string]interface{}{"alias": []byte("2233")}}}`)
}
}
func TestDefaultResolver(t *testing.T) {
@ -144,7 +149,9 @@ func TestDefaultResolver(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := defaultResolver(data)
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}
rd := reader{
values: data,
}
@ -153,19 +160,27 @@ func TestDefaultResolver(t *testing.T) {
switch test.expect.(type) {
case int:
if actual, err = v.Int(); err == nil {
assert.Equal(t, test.expect, int(actual.(int64)), "int value should be equal")
if !reflect.DeepEqual(test.expect.(int), int(actual.(int64))) {
t.Fatal("expect is not equal to actual")
}
}
case string:
if actual, err = v.String(); err == nil {
assert.Equal(t, test.expect, actual, "string value should be equal")
if !reflect.DeepEqual(test.expect, actual) {
t.Fatal("expect is not equal to actual")
}
}
case bool:
if actual, err = v.Bool(); err == nil {
assert.Equal(t, test.expect, actual, "bool value should be equal")
if !reflect.DeepEqual(test.expect, actual) {
t.Fatal("expect is not equal to actual")
}
}
case float64:
if actual, err = v.Float(); err == nil {
assert.Equal(t, test.expect, actual, "float64 value should be equal")
if !reflect.DeepEqual(test.expect, actual) {
t.Fatal("expect is not equal to actual")
}
}
default:
actual = v.Load()
@ -183,3 +198,31 @@ func TestDefaultResolver(t *testing.T) {
})
}
}
func TestExpand(t *testing.T) {
tests := []struct {
input string
mapping func(string) string
want string
}{
{
input: "${a}",
mapping: func(s string) string {
return strings.ToUpper(s)
},
want: "A",
},
{
input: "a",
mapping: func(s string) string {
return strings.ToUpper(s)
},
want: "a",
},
}
for _, tt := range tests {
if got := expand(tt.input, tt.mapping); got != tt.want {
t.Errorf("expand() want: %s, got: %s", tt.want, got)
}
}
}

@ -11,6 +11,8 @@ import (
"github.com/imdario/mergo"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"github.com/go-kratos/kratos/v2/log"
)
// Reader is config reader.
@ -36,18 +38,18 @@ func newReader(opts options) Reader {
}
func (r *reader) Merge(kvs ...*KeyValue) error {
r.lock.Lock()
merged, err := cloneMap(r.values)
r.lock.Unlock()
merged, err := r.cloneMap()
if err != nil {
return err
}
for _, kv := range kvs {
next := make(map[string]interface{})
if err := r.opts.decoder(kv, next); err != nil {
log.Errorf("Failed to config decode error: %v key: %s value: %s", err, kv.Key, string(kv.Value))
return err
}
if err := mergo.Map(&merged, convertMap(next), mergo.WithOverride); err != nil {
log.Errorf("Failed to config merge error: %v key: %s value: %s", err, kv.Key, string(kv.Value))
return err
}
}
@ -75,6 +77,12 @@ func (r *reader) Resolve() error {
return r.opts.resolver(r.values)
}
func (r *reader) cloneMap() (map[string]interface{}, error) {
r.lock.Lock()
defer r.lock.Unlock()
return cloneMap(r.values)
}
func cloneMap(src map[string]interface{}) (map[string]interface{}, error) {
// https://gist.github.com/soroushjp/0ec92102641ddfc3ad5515ca76405f4d
var buf bytes.Buffer
@ -86,12 +94,12 @@ func cloneMap(src map[string]interface{}) (map[string]interface{}, error) {
if err != nil {
return nil, err
}
var copy map[string]interface{}
err = dec.Decode(&copy)
var clone map[string]interface{}
err = dec.Decode(&clone)
if err != nil {
return nil, err
}
return copy, nil
return clone, nil
}
func convertMap(src interface{}) interface{} {

@ -2,10 +2,10 @@ package config
import (
"fmt"
"reflect"
"testing"
"github.com/go-kratos/kratos/v2/encoding"
"github.com/stretchr/testify/assert"
)
func TestReader_Merge(t *testing.T) {
@ -28,31 +28,49 @@ func TestReader_Merge(t *testing.T) {
Value: []byte("bad"),
Format: "json",
})
assert.Error(t, err)
if err == nil {
t.Fatal("err is nil")
}
err = r.Merge(&KeyValue{
Key: "b",
Value: []byte(`{"nice": "boat", "x": 1}`),
Format: "json",
})
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}
vv, ok := r.Value("nice")
assert.True(t, ok)
if !ok {
t.Fatal("ok is false")
}
vvv, err := vv.String()
assert.NoError(t, err)
assert.Equal(t, "boat", vvv)
if err != nil {
t.Fatal(err)
}
if vvv != "boat" {
t.Fatal(`vvv is not equal to "boat"`)
}
err = r.Merge(&KeyValue{
Key: "b",
Value: []byte(`{"x": 2}`),
Format: "json",
})
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}
vv, ok = r.Value("x")
assert.True(t, ok)
if !ok {
t.Fatal("ok is false")
}
vvx, err := vv.Int()
assert.NoError(t, err)
assert.Equal(t, int64(2), vvx)
if err != nil {
t.Fatal(err)
}
if vvx != 2 {
t.Fatal("vvx is not equal to 2")
}
}
func TestReader_Value(t *testing.T) {
@ -99,35 +117,59 @@ a:
t.Run(test.name, func(t *testing.T) {
r := newReader(opts)
err := r.Merge(&test.kv)
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}
vv, ok := r.Value("a.b.X")
assert.True(t, ok)
if !ok {
t.Fatal("ok is false")
}
vvv, err := vv.Int()
assert.NoError(t, err)
assert.Equal(t, int64(1), vvv)
if err != nil {
t.Fatal(err)
}
if int64(1) != vvv {
t.Fatal("vvv is not equal to 1")
}
assert.NoError(t, err)
vv, ok = r.Value("a.b.Y")
assert.True(t, ok)
if !ok {
t.Fatal("ok is false")
}
vvy, err := vv.String()
assert.NoError(t, err)
assert.Equal(t, "lol", vvy)
if err != nil {
t.Fatal(err)
}
if vvy != "lol" {
t.Fatal(`vvy is not equal to "lol"`)
}
assert.NoError(t, err)
vv, ok = r.Value("a.b.z")
assert.True(t, ok)
if !ok {
t.Fatal("ok is false")
}
vvz, err := vv.Bool()
assert.NoError(t, err)
assert.Equal(t, true, vvz)
if err != nil {
t.Fatal(err)
}
if !vvz {
t.Fatal("vvz is not equal to true")
}
_, ok = r.Value("aasasdg=234l.asdfk,")
assert.False(t, ok)
if ok {
t.Fatal("ok is true")
}
_, ok = r.Value("aas......asdg=234l.asdfk,")
assert.False(t, ok)
if ok {
t.Fatal("ok is true")
}
_, ok = r.Value("a.b.Y.")
assert.False(t, ok)
if ok {
t.Fatal("ok is true")
}
})
}
}
@ -149,8 +191,129 @@ func TestReader_Source(t *testing.T) {
Value: []byte(`{"a": {"b": {"X": 1}}}`),
Format: "json",
})
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}
b, err := r.Source()
assert.NoError(t, err)
assert.Equal(t, []byte(`{"a":{"b":{"X":1}}}`), b)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual([]byte(`{"a":{"b":{"X":1}}}`), b) {
t.Fatal("[]byte(`{\"a\":{\"b\":{\"X\":1}}}`) is not equal to b")
}
}
func TestCloneMap(t *testing.T) {
tests := []struct {
input map[string]interface{}
want map[string]interface{}
}{
{
input: map[string]interface{}{
"a": 1,
"b": "2",
"c": true,
},
want: map[string]interface{}{
"a": 1,
"b": "2",
"c": true,
},
},
{
input: map[string]interface{}{},
want: map[string]interface{}{},
},
{
input: nil,
want: map[string]interface{}{},
},
}
for _, tt := range tests {
if got, err := cloneMap(tt.input); err != nil {
t.Errorf("expect no err, got %v", err)
} else if !reflect.DeepEqual(got, tt.want) {
t.Errorf("cloneMap(%v) = %v, want %v", tt.input, got, tt.want)
}
}
}
func TestConvertMap(t *testing.T) {
tests := []struct {
input interface{}
want interface{}
}{
{
input: map[string]interface{}{
"a": 1,
"b": "2",
"c": true,
"d": []byte{65, 66, 67},
},
want: map[string]interface{}{
"a": 1,
"b": "2",
"c": true,
"d": "ABC",
},
},
{
input: []interface{}{1, 2.0, "3", true, nil, []interface{}{1, 2.0, "3", true, nil}},
want: []interface{}{1, 2.0, "3", true, nil, []interface{}{1, 2.0, "3", true, nil}},
},
{
input: []byte{65, 66, 67},
want: "ABC",
},
}
for _, tt := range tests {
if got := convertMap(tt.input); !reflect.DeepEqual(got, tt.want) {
t.Errorf("convertMap(%v) = %v, want %v", tt.input, got, tt.want)
}
}
}
func TestReadValue(t *testing.T) {
m := map[string]interface{}{
"a": 1,
"b": map[string]interface{}{
"c": "3",
"d": map[string]interface{}{
"e": true,
},
},
}
va := atomicValue{}
va.Store(1)
vbc := atomicValue{}
vbc.Store("3")
vbde := atomicValue{}
vbde.Store(true)
tests := []struct {
path string
want atomicValue
}{
{
path: "a",
want: va,
},
{
path: "b.c",
want: vbc,
},
{
path: "b.d.e",
want: vbde,
},
}
for _, tt := range tests {
if got, found := readValue(m, tt.path); !found {
t.Errorf("expect found %v in %v, but not.", tt.path, m)
} else if got.Load() != tt.want.Load() {
t.Errorf("readValue(%v, %v) = %v, want %v", m, tt.path, got, tt.want)
}
}
}

@ -8,8 +8,9 @@ import (
"sync/atomic"
"time"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
kratosjson "github.com/go-kratos/kratos/v2/encoding/json"
)
var (
@ -35,88 +36,124 @@ type atomicValue struct {
atomic.Value
}
func (v *atomicValue) typeAssertError() error {
return fmt.Errorf("type assert to %v failed", reflect.TypeOf(v.Load()))
}
func (v *atomicValue) Bool() (bool, error) {
switch val := v.Load().(type) {
case bool:
return val, nil
case int, int32, int64, float64, string:
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, string:
return strconv.ParseBool(fmt.Sprint(val))
}
return false, fmt.Errorf("type assert to %v failed", reflect.TypeOf(v.Load()))
return false, v.typeAssertError()
}
func (v *atomicValue) Int() (int64, error) {
switch val := v.Load().(type) {
case int:
return int64(val), nil
case int8:
return int64(val), nil
case int16:
return int64(val), nil
case int32:
return int64(val), nil
case int64:
return val, nil
case uint:
return int64(val), nil
case uint8:
return int64(val), nil
case uint16:
return int64(val), nil
case uint32:
return int64(val), nil
case uint64:
return int64(val), nil
case float32:
return int64(val), nil
case float64:
return int64(val), nil
case string:
return strconv.ParseInt(val, 10, 64) //nolint:gomnd
return strconv.ParseInt(val, 10, 64)
}
return 0, fmt.Errorf("type assert to %v failed", reflect.TypeOf(v.Load()))
return 0, v.typeAssertError()
}
func (v *atomicValue) Slice() ([]Value, error) {
if vals, ok := v.Load().([]interface{}); ok {
var slices []Value
for _, val := range vals {
a := &atomicValue{}
a.Store(val)
slices = append(slices, a)
}
return slices, nil
vals, ok := v.Load().([]interface{})
if !ok {
return nil, v.typeAssertError()
}
slices := make([]Value, 0, len(vals))
for _, val := range vals {
a := new(atomicValue)
a.Store(val)
slices = append(slices, a)
}
return nil, fmt.Errorf("type assert to %v failed", reflect.TypeOf(v.Load()))
return slices, nil
}
func (v *atomicValue) Map() (map[string]Value, error) {
if vals, ok := v.Load().(map[string]interface{}); ok {
m := make(map[string]Value)
for key, val := range vals {
a := &atomicValue{}
a.Store(val)
m[key] = a
}
return m, nil
vals, ok := v.Load().(map[string]interface{})
if !ok {
return nil, v.typeAssertError()
}
m := make(map[string]Value, len(vals))
for key, val := range vals {
a := new(atomicValue)
a.Store(val)
m[key] = a
}
return nil, fmt.Errorf("type assert to %v failed", reflect.TypeOf(v.Load()))
return m, nil
}
func (v *atomicValue) Float() (float64, error) {
switch val := v.Load().(type) {
case float64:
return val, nil
case int:
return float64(val), nil
case int8:
return float64(val), nil
case int16:
return float64(val), nil
case int32:
return float64(val), nil
case int64:
return float64(val), nil
case uint:
return float64(val), nil
case uint8:
return float64(val), nil
case uint16:
return float64(val), nil
case uint32:
return float64(val), nil
case uint64:
return float64(val), nil
case float32:
return float64(val), nil
case float64:
return val, nil
case string:
return strconv.ParseFloat(val, 64) //nolint:gomnd
return strconv.ParseFloat(val, 64)
}
return 0.0, fmt.Errorf("type assert to %v failed", reflect.TypeOf(v.Load()))
return 0.0, v.typeAssertError()
}
func (v *atomicValue) String() (string, error) {
switch val := v.Load().(type) {
case string:
return val, nil
case bool, int, int32, int64, float64:
case bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64:
return fmt.Sprint(val), nil
case []byte:
return string(val), nil
default:
if s, ok := val.(fmt.Stringer); ok {
return s.String(), nil
}
case fmt.Stringer:
return val.String(), nil
}
return "", fmt.Errorf("type assert to %v failed", reflect.TypeOf(v.Load()))
return "", v.typeAssertError()
}
func (v *atomicValue) Duration() (time.Duration, error) {
@ -133,7 +170,7 @@ func (v *atomicValue) Scan(obj interface{}) error {
return err
}
if pb, ok := obj.(proto.Message); ok {
return protojson.Unmarshal(data, pb)
return kratosjson.UnmarshalOptions.Unmarshal(data, pb)
}
return json.Unmarshal(data, obj)
}

@ -4,18 +4,20 @@ import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func Test_atomicValue_Bool(t *testing.T) {
func TestAtomicValue_Bool(t *testing.T) {
vlist := []interface{}{"1", "t", "T", "true", "TRUE", "True", true, 1, int32(1)}
for _, x := range vlist {
v := atomicValue{}
v.Store(x)
b, err := v.Bool()
assert.NoError(t, err, b)
assert.True(t, b, b)
if err != nil {
t.Fatal(err)
}
if !b {
t.Fatal("b is not equal to true")
}
}
vlist = []interface{}{"0", "f", "F", "false", "FALSE", "False", false, 0, int32(0)}
@ -23,54 +25,72 @@ func Test_atomicValue_Bool(t *testing.T) {
v := atomicValue{}
v.Store(x)
b, err := v.Bool()
assert.NoError(t, err, b)
assert.False(t, b, b)
if err != nil {
t.Fatal(err)
}
if b {
t.Fatal("b is not equal to false")
}
}
vlist = []interface{}{uint16(1), "bbb", "-1"}
vlist = []interface{}{"bbb", "-1"}
for _, x := range vlist {
v := atomicValue{}
v.Store(x)
b, err := v.Bool()
assert.Error(t, err, b)
_, err := v.Bool()
if err == nil {
t.Fatal("err is nil")
}
}
}
func Test_atomicValue_Int(t *testing.T) {
func TestAtomicValue_Int(t *testing.T) {
vlist := []interface{}{"123123", float64(123123), int64(123123), int32(123123), 123123}
for _, x := range vlist {
v := atomicValue{}
v.Store(x)
b, err := v.Int()
assert.NoError(t, err, b)
assert.Equal(t, int64(123123), b, b)
if err != nil {
t.Fatal(err)
}
if b != 123123 {
t.Fatal("b is not equal to 123123")
}
}
vlist = []interface{}{uint16(1), "bbb", "-x1", true}
vlist = []interface{}{"bbb", "-x1", true}
for _, x := range vlist {
v := atomicValue{}
v.Store(x)
b, err := v.Int()
assert.Error(t, err, b)
_, err := v.Int()
if err == nil {
t.Fatal("err is nil")
}
}
}
func Test_atomicValue_Float(t *testing.T) {
vlist := []interface{}{"123123.1", float64(123123.1)}
func TestAtomicValue_Float(t *testing.T) {
vlist := []interface{}{"123123.1", 123123.1}
for _, x := range vlist {
v := atomicValue{}
v.Store(x)
b, err := v.Float()
assert.NoError(t, err, b)
assert.Equal(t, float64(123123.1), b, b)
if err != nil {
t.Fatal(err)
}
if b != 123123.1 {
t.Fatal("b is not equal to 123123.1")
}
}
vlist = []interface{}{float32(1123123), uint16(1), "bbb", "-x1"}
vlist = []interface{}{"bbb", "-x1"}
for _, x := range vlist {
v := atomicValue{}
v.Store(x)
b, err := v.Float()
assert.Error(t, err, b)
_, err := v.Float()
if err == nil {
t.Fatal("err is nil")
}
}
}
@ -83,21 +103,29 @@ func (t ts) String() string {
return fmt.Sprintf("%s%d", t.Name, t.Age)
}
func Test_atomicValue_String(t *testing.T) {
func TestAtomicValue_String(t *testing.T) {
vlist := []interface{}{"1", float64(1), int64(1), 1, int64(1)}
for _, x := range vlist {
v := atomicValue{}
v.Store(x)
b, err := v.String()
assert.NoError(t, err, b)
assert.Equal(t, "1", b, b)
if err != nil {
t.Fatal(err)
}
if b != "1" {
t.Fatal("b is not equal to 1")
}
}
v := atomicValue{}
v.Store(true)
b, err := v.String()
assert.NoError(t, err, b)
assert.Equal(t, "true", b, b)
if err != nil {
t.Fatal(err)
}
if b != "true" {
t.Fatal(`b is not equal to "true"`)
}
v = atomicValue{}
v.Store(ts{
@ -105,65 +133,92 @@ func Test_atomicValue_String(t *testing.T) {
Age: 10,
})
b, err = v.String()
assert.NoError(t, err, b)
assert.Equal(t, "test10", b, "test Stringer should be equal")
if err != nil {
t.Fatal(err)
}
if b != "test10" {
t.Fatal(`b is not equal to "test10"`)
}
}
func Test_atomicValue_Duration(t *testing.T) {
func TestAtomicValue_Duration(t *testing.T) {
vlist := []interface{}{int64(5)}
for _, x := range vlist {
v := atomicValue{}
v.Store(x)
b, err := v.Duration()
assert.NoError(t, err)
assert.Equal(t, time.Duration(5), b)
if err != nil {
t.Fatal(err)
}
if b != time.Duration(5) {
t.Fatal("b is not equal to time.Duration(5)")
}
}
}
func Test_atomicValue_Slice(t *testing.T) {
func TestAtomicValue_Slice(t *testing.T) {
vlist := []interface{}{int64(5)}
v := atomicValue{}
v.Store(vlist)
slices, err := v.Slice()
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}
for _, v := range slices {
b, err := v.Duration()
assert.NoError(t, err)
assert.Equal(t, time.Duration(5), b)
if err != nil {
t.Fatal(err)
}
if b != time.Duration(5) {
t.Fatal("b is not equal to time.Duration(5)")
}
}
}
func Test_atomicValue_Map(t *testing.T) {
func TestAtomicValue_Map(t *testing.T) {
vlist := make(map[string]interface{})
vlist["5"] = int64(5)
vlist["text"] = "text"
v := atomicValue{}
v.Store(vlist)
m, err := v.Map()
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}
for k, v := range m {
if k == "5" {
b, err := v.Duration()
assert.NoError(t, err)
assert.Equal(t, time.Duration(5), b)
if err != nil {
t.Fatal(err)
}
if b != time.Duration(5) {
t.Fatal("b is not equal to time.Duration(5)")
}
} else {
b, err := v.String()
assert.NoError(t, err)
assert.Equal(t, "text", b)
if err != nil {
t.Fatal(err)
}
if b != "text" {
t.Fatal(`b is not equal to "text"`)
}
}
}
}
func Test_atomicValue_Scan(t *testing.T) {
var err error
func TestAtomicValue_Scan(t *testing.T) {
v := atomicValue{}
err = v.Scan(&struct {
err := v.Scan(&struct {
A string `json:"a"`
}{"a"})
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}
err = v.Scan(&struct {
A string `json:"a"`
}{"a"})
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}
}

@ -1,65 +0,0 @@
package group
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGroupGet(t *testing.T) {
count := 0
g := NewGroup(func() interface{} {
count++
return count
})
v := g.Get("key_0")
assert.Equal(t, 1, v.(int))
v = g.Get("key_1")
assert.Equal(t, 2, v.(int))
v = g.Get("key_0")
assert.Equal(t, 1, v.(int))
assert.Equal(t, 2, count)
}
func TestGroupReset(t *testing.T) {
g := NewGroup(func() interface{} {
return 1
})
g.Get("key")
call := false
g.Reset(func() interface{} {
call = true
return 1
})
length := 0
for range g.vals {
length++
}
assert.Equal(t, 0, length)
g.Get("key")
assert.Equal(t, true, call)
}
func TestGroupClear(t *testing.T) {
g := NewGroup(func() interface{} {
return 1
})
g.Get("key")
length := 0
for range g.vals {
length++
}
assert.Equal(t, 1, length)
g.Clear()
length = 0
for range g.vals {
length++
}
assert.Equal(t, 0, length)
}

@ -55,9 +55,6 @@ func WithEnableBackup() Option
// specify apollo endpoint, such as http://localhost:8080
func WithEndpoint(endpoint string) Option
// inject a logger to debug
func WithLogger(logger log.Logger) Option
// namespaces to load, comma to separate.
func WithNamespace(name string) Option
@ -100,5 +97,4 @@ config := map[string]interface{}{
}
}
}
_ = config
```
```

@ -1,22 +1,32 @@
package apollo
import (
"fmt"
"strings"
"github.com/apolloconfig/agollo/v4"
"github.com/apolloconfig/agollo/v4/constant"
apolloconfig "github.com/apolloconfig/agollo/v4/env/config"
"github.com/apolloconfig/agollo/v4/extension"
"github.com/go-kratos/kratos/v2/config"
"github.com/go-kratos/kratos/v2/encoding"
"github.com/go-kratos/kratos/v2/log"
"github.com/apolloconfig/agollo/v4"
apolloConfig "github.com/apolloconfig/agollo/v4/env/config"
)
type apollo struct {
client *agollo.Client
client agollo.Client
opt *options
}
const (
yaml = "yaml"
yml = "yml"
json = "json"
properties = "properties"
)
var formats map[string]struct{}
// Option is apollo option
type Option func(*options)
@ -28,8 +38,7 @@ type options struct {
namespace string
isBackupConfig bool
backupPath string
logger log.Logger
originConfig bool
}
// WithAppID with apollo config app id
@ -88,24 +97,23 @@ func WithBackupPath(backupPath string) Option {
}
}
// WithLogger use custom logger to replace default logger.
func WithLogger(logger log.Logger) Option {
// WithOriginalConfig use the original configuration file without parse processing
func WithOriginalConfig() Option {
return func(o *options) {
if logger != nil {
o.logger = logger
}
extension.AddFormatParser(constant.JSON, &jsonExtParser{})
extension.AddFormatParser(constant.YAML, &yamlExtParser{})
extension.AddFormatParser(constant.YML, &yamlExtParser{})
o.originConfig = true
}
}
func NewSource(opts ...Option) config.Source {
op := options{
logger: log.DefaultLogger,
}
op := options{}
for _, o := range opts {
o(&op)
}
client, err := agollo.StartWithConfig(func() (*apolloConfig.AppConfig, error) {
return &apolloConfig.AppConfig{
client, err := agollo.StartWithConfig(func() (*apolloconfig.AppConfig, error) {
return &apolloconfig.AppConfig{
AppID: op.appid,
Cluster: op.cluster,
NamespaceName: op.namespace,
@ -118,26 +126,100 @@ func NewSource(opts ...Option) config.Source {
if err != nil {
panic(err)
}
return &apollo{client: client, opt: &op}
}
// genKey got the key of config.KeyValue pair.
// eg: namespace.ext with subKey got namespace.subKey
func genKey(ns, sub string) string {
func format(ns string) string {
arr := strings.Split(ns, ".")
if len(arr) < 1 {
return sub
suffix := arr[len(arr)-1]
if len(arr) <= 1 || suffix == properties {
return json
}
if _, ok := formats[suffix]; !ok {
// fallback
return json
}
if len(arr) == 1 {
if ns == "" {
return sub
return suffix
}
func (e *apollo) load() []*config.KeyValue {
kvs := make([]*config.KeyValue, 0)
namespaces := strings.Split(e.opt.namespace, ",")
for _, ns := range namespaces {
if !e.opt.originConfig {
kv, err := e.getConfig(ns)
if err != nil {
log.Errorf("apollo get config failed,err:%v", err)
continue
}
kvs = append(kvs, kv)
continue
}
return ns + "." + sub
if strings.Contains(ns, ".") && !strings.HasSuffix(ns, "."+properties) &&
(format(ns) == yaml || format(ns) == yml || format(ns) == json) {
kv, err := e.getOriginConfig(ns)
if err != nil {
log.Errorf("apollo get config failed,err:%v", err)
continue
}
kvs = append(kvs, kv)
continue
}
kv, err := e.getConfig(ns)
if err != nil {
log.Errorf("apollo get config failed,err:%v", err)
continue
}
kvs = append(kvs, kv)
}
return kvs
}
return strings.Join(arr[:len(arr)-1], ".") + "." + sub
func (e *apollo) getConfig(ns string) (*config.KeyValue, error) {
next := map[string]interface{}{}
e.client.GetConfigCache(ns).Range(func(key, value interface{}) bool {
// all values are out properties format
resolve(genKey(ns, key.(string)), value, next)
return true
})
f := format(ns)
codec := encoding.GetCodec(f)
val, err := codec.Marshal(next)
if err != nil {
return nil, err
}
return &config.KeyValue{
Key: ns,
Value: val,
Format: f,
}, nil
}
func (e apollo) getOriginConfig(ns string) (*config.KeyValue, error) {
value, err := e.client.GetConfigCache(ns).Get("content")
if err != nil {
return nil, err
}
// serialize the namespace content KeyValue into bytes.
return &config.KeyValue{
Key: ns,
Value: []byte(value.(string)),
Format: format(ns),
}, nil
}
func (e *apollo) Load() (kv []*config.KeyValue, err error) {
return e.load(), nil
}
func (e *apollo) Watch() (config.Watcher, error) {
w, err := newWatcher(e)
if err != nil {
return nil, err
}
return w, nil
}
// resolve convert kv pair into one map[string]interface{} by split key into different
@ -167,66 +249,38 @@ func resolve(key string, value interface{}, target map[string]interface{}) {
// current exists, then check existing value type, if it's not map
// that means duplicate keys, and at least one is not map instance.
if cursor, ok = v.(map[string]interface{}); !ok {
_ = log.DefaultLogger.Log(log.LevelWarn,
"msg",
fmt.Sprintf("duplicate key: %v\n", strings.Join(keys[:i+1], ".")),
)
log.Warnf("duplicate key: %v\n", strings.Join(keys[:i+1], "."))
break
}
}
}
func format(ns string) string {
// genKey got the key of config.KeyValue pair.
// eg: namespace.ext with subKey got namespace.subKey
func genKey(ns, sub string) string {
arr := strings.Split(ns, ".")
if len(arr) <= 1 {
return "json"
}
return arr[len(arr)-1]
}
func (e *apollo) load() []*config.KeyValue {
kv := make([]*config.KeyValue, 0)
namespaces := strings.Split(e.opt.namespace, ",")
for _, ns := range namespaces {
next := map[string]interface{}{}
e.client.GetConfigCache(ns).Range(func(key, value interface{}) bool {
// all values are out properties format
resolve(genKey(ns, key.(string)), value, next)
return true
})
// serialize the namespace content KeyValue into bytes.
f := format(ns)
codec := encoding.GetCodec(f)
val, err := codec.Marshal(next)
if err != nil {
_ = e.opt.logger.Log(log.LevelWarn,
"msg",
fmt.Sprintf("apollo could not handle namespace %s: %v", ns, err),
)
continue
if len(arr) == 1 {
if ns == "" {
return sub
}
kv = append(kv, &config.KeyValue{
Key: ns,
Value: val,
Format: f,
})
return ns + "." + sub
}
suffix := arr[len(arr)-1]
_, ok := formats[suffix]
if ok {
return strings.Join(arr[:len(arr)-1], ".") + "." + sub
}
return kv
return ns + "." + sub
}
func (e *apollo) Load() (kv []*config.KeyValue, err error) {
return e.load(), nil
}
func init() {
formats = make(map[string]struct{})
func (e *apollo) Watch() (config.Watcher, error) {
w, err := newWatcher(e, e.opt.logger)
if err != nil {
return nil, err
}
return w, nil
formats[yaml] = struct{}{}
formats[yml] = struct{}{}
formats[json] = struct{}{}
formats[properties] = struct{}{}
}

@ -2,8 +2,6 @@ package apollo
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_genKey(t *testing.T) {
@ -17,44 +15,28 @@ func Test_genKey(t *testing.T) {
want string
}{
{
name: "case 1",
name: "blank namespace",
args: args{
ns: "",
sub: "has_no_ns",
sub: "x.y",
},
want: "has_no_ns",
want: "x.y",
},
{
name: "case 2",
name: "properties namespace",
args: args{
ns: "ns.ext",
sub: "sub",
ns: "application",
sub: "x.y",
},
want: "ns.sub",
want: "application.x.y",
},
{
name: "case 3",
name: "namespace with format",
args: args{
ns: "",
sub: "",
ns: "app.yaml",
sub: "x.y",
},
want: "",
},
{
name: "case 4",
args: args{
ns: "ns.ext",
sub: "sub.sub2.sub3",
},
want: "ns.sub.sub2.sub3",
},
{
name: "case 5",
args: args{
ns: "ns.more.ext",
sub: "sub.sub2.sub3",
},
want: "ns.more.sub.sub2.sub3",
want: "app.x.y",
},
}
for _, tt := range tests {
@ -67,106 +49,42 @@ func Test_genKey(t *testing.T) {
}
func Test_format(t *testing.T) {
type args struct {
ns string
}
tests := []struct {
name string
args args
want string
name string
namespace string
want string
}{
{
name: "case 0",
args: args{
ns: "ns.yaml",
},
want: "yaml",
name: "properties namespace",
namespace: "application",
want: "json",
},
{
name: "case 1",
args: args{
ns: "ns",
},
want: "json",
name: "properties namespace #1",
namespace: "app.setting",
want: "json",
},
{
name: "case 2",
args: args{
ns: "ns.more.json",
},
want: "json",
name: "namespace with format[yaml]",
namespace: "app.yaml",
want: "yaml",
},
{
name: "case 3",
args: args{
ns: "",
},
want: "json",
name: "namespace with format[yml]",
namespace: "app.yml",
want: "yml",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := format(tt.args.ns); got != tt.want {
t.Errorf("format() = %v, want %v", got, tt.want)
}
})
}
}
func Test_convertProperties(t *testing.T) {
type args struct {
key string
value interface{}
target map[string]interface{}
}
tests := []struct {
name string
args args
want map[string]interface{}
}{
{
name: "case 0",
args: args{
key: "application.name",
value: "app name",
target: map[string]interface{}{},
},
want: map[string]interface{}{
"application": map[string]interface{}{
"name": "app name",
},
},
},
{
name: "case 1",
args: args{
key: "application",
value: []string{"1", "2", "3"},
target: map[string]interface{}{},
},
want: map[string]interface{}{
"application": []string{"1", "2", "3"},
},
name: "namespace with format[json]",
namespace: "app.json",
want: "json",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resolve(tt.args.key, tt.args.value, tt.args.target)
assert.Equal(t, tt.want, tt.args.target)
if got := format(tt.namespace); got != tt.want {
t.Errorf("format() = %v, want %v", got, tt.want)
}
})
}
}
func Test_convertProperties_duplicate(t *testing.T) {
target := map[string]interface{}{}
resolve("application.name", "name", target)
assert.Contains(t, target, "application")
assert.Contains(t, target["application"], "name")
assert.Equal(t, "name", target["application"].(map[string]interface{})["name"])
// cause duplicate, the oldest value will be kept
resolve("application.name.first", "first name", target)
assert.Contains(t, target, "application")
assert.Contains(t, target["application"], "name")
assert.Equal(t, "name", target["application"].(map[string]interface{})["name"])
}

@ -3,9 +3,10 @@ module github.com/go-kratos/kratos/contrib/config/apollo/v2
go 1.16
require (
github.com/apolloconfig/agollo/v4 v4.0.8
github.com/go-kratos/kratos/v2 v2.1.4
github.com/stretchr/testify v1.7.0
github.com/apolloconfig/agollo/v4 v4.3.0
github.com/go-kratos/kratos/v2 v2.6.3
)
require github.com/spf13/viper v1.11.0 // indirect
replace github.com/go-kratos/kratos/v2 => ../../../

File diff suppressed because it is too large Load Diff

@ -1,25 +0,0 @@
package apollo
import (
"encoding/json"
"github.com/apolloconfig/agollo/v4/constant"
"github.com/apolloconfig/agollo/v4/extension"
)
type jsonExtParser struct{}
func (j jsonExtParser) Parse(configContent interface{}) (map[string]interface{}, error) {
v, ok := configContent.(string)
if !ok {
return nil, nil
}
out := make(map[string]interface{}, 4)
err := json.Unmarshal([]byte(v), &out)
return out, err
}
func init() {
// add json format
extension.AddFormatParser(constant.JSON, &jsonExtParser{})
}

@ -0,0 +1,13 @@
package apollo
type jsonExtParser struct{}
func (parser jsonExtParser) Parse(configContent interface{}) (map[string]interface{}, error) {
return map[string]interface{}{"content": configContent}, nil
}
type yamlExtParser struct{}
func (parser yamlExtParser) Parse(configContent interface{}) (map[string]interface{}, error) {
return map[string]interface{}{"content": configContent}, nil
}

@ -2,29 +2,45 @@ package apollo
import (
"context"
"fmt"
"strings"
"github.com/apolloconfig/agollo/v4/storage"
"github.com/go-kratos/kratos/v2/config"
"github.com/go-kratos/kratos/v2/encoding"
"github.com/go-kratos/kratos/v2/log"
"github.com/apolloconfig/agollo/v4/storage"
)
type watcher struct {
out <-chan []*config.KeyValue
out <-chan []*config.KeyValue
ctx context.Context
cancelFn func()
}
type customChangeListener struct {
in chan<- []*config.KeyValue
logger log.Logger
apollo *apollo
}
func (c *customChangeListener) onChange(
namespace string, changes map[string]*storage.ConfigChange) []*config.KeyValue {
func (c *customChangeListener) onChange(namespace string, changes map[string]*storage.ConfigChange) []*config.KeyValue {
kv := make([]*config.KeyValue, 0, 2)
if strings.Contains(namespace, ".") && !strings.HasSuffix(namespace, "."+properties) &&
(format(namespace) == yaml || format(namespace) == yml || format(namespace) == json) {
value, err := c.apollo.client.GetConfigCache(namespace).Get("content")
if err != nil {
log.Warnw("apollo get config failed", "err", err)
return nil
}
kv = append(kv, &config.KeyValue{
Key: namespace,
Value: []byte(value.(string)),
Format: format(namespace),
})
return kv
}
next := make(map[string]interface{})
for key, change := range changes {
@ -35,10 +51,7 @@ func (c *customChangeListener) onChange(
codec := encoding.GetCodec(f)
val, err := codec.Marshal(next)
if err != nil {
_ = c.logger.Log(log.LevelWarn,
"msg",
fmt.Sprintf("apollo could not handle namespace %s: %v", namespace, err),
)
log.Warnf("apollo could not handle namespace %s: %v", namespace, err)
return nil
}
kv = append(kv, &config.KeyValue{
@ -59,39 +72,38 @@ func (c *customChangeListener) OnChange(changeEvent *storage.ChangeEvent) {
c.in <- change
}
func (c *customChangeListener) OnNewestChange(changeEvent *storage.FullChangeEvent) {}
func newWatcher(a *apollo, logger log.Logger) (config.Watcher, error) {
if logger == nil {
logger = log.DefaultLogger
}
func (c *customChangeListener) OnNewestChange(_ *storage.FullChangeEvent) {}
func newWatcher(a *apollo) (config.Watcher, error) {
changeCh := make(chan []*config.KeyValue)
listener := &customChangeListener{in: changeCh, logger: logger}
listener := &customChangeListener{in: changeCh, apollo: a}
a.client.AddChangeListener(listener)
ctx, cancel := context.WithCancel(context.Background())
return &watcher{
out: changeCh,
ctx: ctx,
cancelFn: func() {
a.client.RemoveChangeListener(listener)
close(changeCh)
cancel()
},
}, nil
}
// Next will be blocked until the Stop method is called
func (w *watcher) Next() ([]*config.KeyValue, error) {
kv, ok := <-w.out
if !ok {
return nil, context.Canceled
select {
case kv := <-w.out:
return kv, nil
case <-w.ctx.Done():
return nil, w.ctx.Err()
}
return kv, nil
}
func (w *watcher) Stop() error {
if w.cancelFn != nil {
w.cancelFn()
}
return nil
}

@ -2,35 +2,24 @@
```go
import (
kconfig "github.com/go-kratos/kratos/v2/config"
"github.com/nacos-group/nacos-sdk-go/clients"
"github.com/nacos-group/nacos-sdk-go/common/constant"
)
sc := []constant.ServerConfig{
*constant.NewServerConfig("127.0.0.1", 8848),
}
"github.com/hashicorp/consul/api"
cc := &constant.ClientConfig{
NamespaceId: "public", //namespace id
TimeoutMs: 5000,
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
RotateTime: "1h",
MaxAge: 3,
LogLevel: "debug",
}
// a more graceful way to create naming client
client, err := clients.NewNamingClient(
vo.NacosClientParam{
ClientConfig: cc,
ServerConfigs: sc,
},
"github.com/go-kratos/kratos/contrib/config/consul/v2"
)
if err != nil {
log.Panic(err)
func main() {
consulClient, err := api.NewClient(&api.Config{
Address: "127.0.0.1:8500",
})
if err != nil {
panic(err)
}
cs, err := consul.New(consulClient, consul.WithPath("app/cart/configs/"))
// consul中需要标注文件后缀,kratos读取配置需要适配文件后缀
// The file suffix needs to be marked, and kratos needs to adapt the file suffix to read the configuration.
if err != nil {
panic(err)
}
c := config.New(config.WithSource(cs))
}
```

@ -6,8 +6,9 @@ import (
"path/filepath"
"strings"
"github.com/go-kratos/kratos/v2/config"
"github.com/hashicorp/consul/api"
"github.com/go-kratos/kratos/v2/config"
)
// Option is etcd config option.
@ -18,18 +19,18 @@ type options struct {
path string
}
// WithContext with registry context.
// WithContext with registry context.
func WithContext(ctx context.Context) Option {
return Option(func(o *options) {
return func(o *options) {
o.ctx = ctx
})
}
}
// WithPath is config path
func WithPath(p string) Option {
return Option(func(o *options) {
return func(o *options) {
o.path = p
})
}
}
type source struct {
@ -71,6 +72,9 @@ func (s *source) Load() ([]*config.KeyValue, error) {
kvs := make([]*config.KeyValue, 0)
for _, item := range kv {
k := strings.TrimPrefix(item.Key, pathPrefix)
if k == "" {
continue
}
kvs = append(kvs, &config.KeyValue{
Key: k,
Value: item.Value,

@ -1,10 +1,13 @@
package consul
import (
"reflect"
"testing"
"time"
"github.com/hashicorp/consul/api"
"github.com/stretchr/testify/assert"
"github.com/go-kratos/kratos/v2/config"
)
const testPath = "kratos/test/config"
@ -86,9 +89,171 @@ func TestExtToFormat(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(len(kvs), 1) {
t.Errorf("len(kvs) is %d", len(kvs))
}
if !reflect.DeepEqual(tn, kvs[0].Key) {
t.Errorf("kvs[0].Key is %s", kvs[0].Key)
}
if !reflect.DeepEqual(tc, string(kvs[0].Value)) {
t.Errorf("kvs[0].Value is %s", kvs[0].Value)
}
if !reflect.DeepEqual("json", kvs[0].Format) {
t.Errorf("kvs[0].Format is %s", kvs[0].Format)
}
}
func Test_source_Watch(t *testing.T) {
client, err := api.NewClient(&api.Config{
Address: "127.0.0.1:8500",
})
if err != nil {
t.Fatal(err)
}
source, err := New(client, WithPath(testPath))
if err != nil {
t.Fatal(err)
}
type fields struct {
source config.Source
}
type args struct {
key string
value string
}
tests := []struct {
name string
fields fields
args args
want string
wantErr bool
deferFunc func(t *testing.T)
}{
{
name: "normal",
fields: fields{source: source},
args: args{
key: testKey,
value: "test value",
},
want: "test value",
wantErr: false,
deferFunc: func(t *testing.T) {
_, err := client.KV().Delete(testKey, nil)
if err != nil {
t.Error(err)
}
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.deferFunc != nil {
defer tt.deferFunc(t)
}
got, err := tt.fields.source.Watch()
if (err != nil) != tt.wantErr {
t.Errorf("Watch() error = %v, wantErr %v", err, tt.wantErr)
return
}
time.Sleep(100 * time.Millisecond)
_, err = client.KV().Put(&api.KVPair{Key: tt.args.key, Value: []byte(tt.args.value)}, nil)
if err != nil {
t.Error(err)
}
next, err := got.Next()
if (err != nil) != tt.wantErr {
t.Errorf("Watch() error = %v, wantErr %v", err, tt.wantErr)
return
}
if len(next) != 1 {
t.Error("watch is error")
}
if !reflect.DeepEqual(string(next[0].Value), tt.want) {
t.Errorf("Watch got = %v, want %v", string(next[0].Value), tt.want)
}
})
}
}
func Test_source_Load(t *testing.T) {
client, err := api.NewClient(&api.Config{
Address: "127.0.0.1:8500",
})
if err != nil {
t.Fatal(err)
}
source, err := New(client, WithPath(testPath))
if err != nil {
t.Fatal(err)
}
type args struct {
key string
value string
}
type fields struct {
source config.Source
}
tests := []struct {
name string
args args
fields fields
want []*config.KeyValue
wantErr bool
deferFunc func(t *testing.T)
}{
{
name: "normal",
args: args{
key: testKey,
value: "test value",
},
fields: fields{
source: source,
},
want: []*config.KeyValue{
{
Key: "key",
Value: []byte("test value"),
},
},
deferFunc: func(t *testing.T) {
_, err1 := client.KV().Delete(testKey, nil)
if err1 != nil {
t.Error(err)
}
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.deferFunc != nil {
defer tt.deferFunc(t)
}
_, err = client.KV().Put(&api.KVPair{Key: tt.args.key, Value: []byte(tt.args.value)}, nil)
if err != nil {
t.Error(err)
}
got, err := tt.fields.source.Load()
if (err != nil) != tt.wantErr {
t.Errorf("Load() error = %v, wantErr %v", err, tt.wantErr)
return
}
assert.Equal(t, 1, len(kvs))
assert.Equal(t, tn, kvs[0].Key)
assert.Equal(t, tc, string(kvs[0].Value))
assert.Equal(t, "json", kvs[0].Format)
if !reflect.DeepEqual(got[0], tt.want[0]) {
t.Errorf("Load() got = %v, want %v", got, tt.want)
}
})
}
}

@ -3,9 +3,13 @@ module github.com/go-kratos/kratos/contrib/config/consul/v2
go 1.15
require (
github.com/go-kratos/kratos/v2 v2.1.4
github.com/hashicorp/consul/api v1.10.0
github.com/stretchr/testify v1.7.0
github.com/armon/go-metrics v0.3.10 // indirect
github.com/go-kratos/kratos/v2 v2.6.3
github.com/hashicorp/consul/api v1.20.0
github.com/hashicorp/go-hclog v0.14.1 // indirect
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
)
replace github.com/go-kratos/kratos/v2 => ../../../

File diff suppressed because it is too large Load Diff

@ -1,19 +1,24 @@
package consul
import (
"github.com/go-kratos/kratos/v2/config"
"context"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/api/watch"
"github.com/go-kratos/kratos/v2/config"
)
type watcher struct {
source *source
ch chan interface{}
closeChan chan struct{}
wp *watch.Plan
source *source
ch chan interface{}
wp *watch.Plan
ctx context.Context
cancel context.CancelFunc
}
func (w *watcher) handle(idx uint64, data interface{}) {
func (w *watcher) handle(_ uint64, data interface{}) {
if data == nil {
return
}
@ -27,10 +32,13 @@ func (w *watcher) handle(idx uint64, data interface{}) {
}
func newWatcher(s *source) (*watcher, error) {
ctx, cancel := context.WithCancel(context.Background())
w := &watcher{
source: s,
ch: make(chan interface{}),
closeChan: make(chan struct{}),
source: s,
ch: make(chan interface{}),
ctx: ctx,
cancel: cancel,
}
wp, err := watch.Parse(map[string]interface{}{"type": "keyprefix", "prefix": s.options.path})
@ -54,18 +62,15 @@ func newWatcher(s *source) (*watcher, error) {
func (w *watcher) Next() ([]*config.KeyValue, error) {
select {
case _, ok := <-w.ch:
if !ok {
return nil, nil
}
case <-w.ch:
return w.source.Load()
case <-w.closeChan:
return nil, nil
case <-w.ctx.Done():
return nil, w.ctx.Err()
}
}
func (w *watcher) Stop() error {
w.wp.Stop()
close(w.closeChan)
w.cancel()
return nil
}

@ -4,13 +4,14 @@
import (
"log"
cfg "github.com/go-kratos/kratos/contrib/config/etcd/v2"
"github.com/go-kratos/kratos/v2/config"
clientv3 "go.etcd.io/etcd/client/v3"
"google.golang.org/grpc"
cfg "github.com/go-kratos/kratos/contrib/config/etcd/v2"
"github.com/go-kratos/kratos/v2/config"
)
// create a etcd client
// create an etcd client
client, err := clientv3.New(clientv3.Config{
Endpoints: []string{"127.0.0.1:2379"},
DialTimeout: time.Second,
@ -30,12 +31,16 @@ if err != nil {
c := config.New(config.WithSource(source))
defer c.Close()
// load sources before get
if err := c.Load(); err != nil {
log.Fatalln(err)
}
// acquire config value
foo, err := c.Value("/app-config").String()
if err != nil {
log.Println(err)
log.Fatalln(err)
}
println(foo)
log.Println(foo)
```

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save