kratos icon indicating copy to clipboard operation
kratos copied to clipboard

feat(cmd/protoc-gen-go-kratos): generate kratos client

Open Casper-Mars opened this issue 2 years ago • 2 comments

Description (what this PR does / why we need it):

Generate kratos`s grpc-client

Which issue(s) this PR fixes (resolves / be part of):

#2010

Other

The file that generate by plugin:

// Code generated by protoc-gen-go-kratos. DO NOT EDIT
// versions:
// protoc-gen-go-kratos v2.3.1

package tests

import (
	context "context"
	wrr "github.com/go-kratos/kratos/v2/selector/wrr"
	grpc "github.com/go-kratos/kratos/v2/transport/grpc"
	http "github.com/go-kratos/kratos/v2/transport/http"
)

// This is a compile-time assertion to ensure that this generated file
// is compatible with the kratos package it is being compiled against.
var _ = new(context.Context)

//NewLibraryServiceGRPCClient create grpc client for kratos
func NewLibraryServiceGRPCClient(ctx context.Context, opts ...grpc.ClientOption) (cli LibraryServiceClient, err error) {
	targetOpts := make([]grpc.ClientOption, 0, len(opts)+2)
	targetOpts = append(targetOpts,
		grpc.WithBalancerName(wrr.Name),
		grpc.WithEndpoint("discovery://service_name"),
	)
	conn, err := grpc.DialInsecure(ctx, append(targetOpts, opts...)...)
	if err != nil {
		return nil, err
	}
	return NewLibraryServiceClient(conn), nil
}

//NewLibraryServiceKratosHTTPClientV2 create http client for kratos
func NewLibraryServiceKratosHTTPClientV2(ctx context.Context, opts ...http.ClientOption) (cli LibraryServiceHTTPClient, err error) {
	targetOpts := make([]http.ClientOption, 0, len(opts)+2)
	targetOpts = append(targetOpts, http.WithEndpoint("discovery://service_name"))
	client, err := http.NewClient(ctx, append(targetOpts, opts...)...)
	if err != nil {
		return nil, err
	}
	return NewLibraryServiceHTTPClient(client), nil
}

Casper-Mars avatar Jun 11 '22 06:06 Casper-Mars

Codecov Report

Merging #2096 (fec45f9) into main (3aaac45) will decrease coverage by 0.07%. The diff coverage is 66.66%.

:exclamation: Current head fec45f9 differs from pull request most recent head 136bc4d. Consider uploading reports for the commit 136bc4d to get more accurate results

@@            Coverage Diff             @@
##             main    #2096      +/-   ##
==========================================
- Coverage   79.09%   79.02%   -0.08%     
==========================================
  Files          84       84              
  Lines        3683     3704      +21     
==========================================
+ Hits         2913     2927      +14     
- Misses        559      563       +4     
- Partials      211      214       +3     
Impacted Files Coverage Δ
config/config.go 54.66% <ø> (ø)
encoding/form/well_known_types.go 77.27% <ø> (ø)
transport/grpc/client.go 91.30% <60.00%> (-1.80%) :arrow_down:
encoding/form/proto_encode.go 71.22% <64.70%> (-0.78%) :arrow_down:
transport/http/binding/encode.go 81.39% <100.00%> (+0.90%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3aaac45...136bc4d. Read the comment docs.

codecov-commenter avatar Jun 11 '22 07:06 codecov-commenter

或许注释可以是

// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc             v3.19.4
// source: helloworld/helloworld/helloworld.proto

daemon365 avatar Jul 10 '22 12:07 daemon365