goo_grpc

package
v1.0.53 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

README

goo-grpc

服务端

var cfg = goo_etcd.Config{
    User: "test",
    Password: "123456",
    Endpoints: []string{"localhost:23791", "localhost:23792", "localhost:23793"},
}

func init() {
	goo_etcd.Init(cfg)
}

func main() {
	s := goo_grpc.New(goo_grpc.Config{
		ENV:         "test",
		ServiceName: "lpro/grpc-user",
		Version:     "v100",
		Addr:        "127.0.0.1:10011",
	}).Register2Etcd(goo_etcd.CLI())

	pb_user_v1.RegisterGetterServer(s.Server, &Server{})

	s.Serve()
}

客户端

var cfg = goo_etcd.Config{
    User: "test",
    Password: "123456",
    Endpoints: []string{"localhost:23791", "localhost:23792", "localhost:23793"},
}

func init() {
	goo_etcd.Init(cfg)
}

func main() {
	serviceName := "/test/lproj/grpc-user/v100"

	cc, err := goo_grpc.DialWithEtcd(context.TODO(), serviceName, goo_etcd.CLI())
	if err != nil {
		goo_log.Error(err.Error())
	}

	// -------------------------------------
	// -------------------------------------

	cli := pb_user_v1.NewGetterClient(cc)

	for {
		select {
		case <-goo_context.Cancel().Done():
			return
		default:
			cli.Info(context.TODO(), &pb_user_v1.InfoParams{Id: 1})
			time.Sleep(time.Second)
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context(c *gin.Context) context.Context

func Dial

func Dial(ctx context.Context, addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

func DialWithEtcd added in v1.0.2

func DialWithEtcd(ctx context.Context, serviceName string, cli *goo_etcd.Client) (*grpc.ClientConn, error)

func GRPCInterceptor

func GRPCInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (rsp interface{}, err error)

Types

type Config added in v1.0.2

type Config struct {
	ENV         string
	ServiceName string
	Version     string
	Addr        string
	PProfEnable bool
	PProfAddr   string
}

type GRPCGraceful

type GRPCGraceful struct {
	// contains filtered or unexported fields
}

func NewGRPCGraceful

func NewGRPCGraceful(nett, addr string, s *grpc.Server) *GRPCGraceful

func (*GRPCGraceful) Serve

func (g *GRPCGraceful) Serve() error

type Option added in v1.0.2

type Option struct {
	Name  string
	Value interface{}
}

func EnvOption added in v1.0.2

func EnvOption(env string) Option

func EtcdOption added in v1.0.2

func EtcdOption(cli *goo_etcd.Client) Option

func ProjectNameOption added in v1.0.2

func ProjectNameOption(projectName string) Option

func ServiceNameOption added in v1.0.2

func ServiceNameOption(serviceName string) Option

func VersionOption added in v1.0.2

func VersionOption(version string) Option

type Resolver

type Resolver struct {
}

func (*Resolver) Close

func (r *Resolver) Close()

func (*Resolver) ResolveNow

func (r *Resolver) ResolveNow(o resolver.ResolveNowOptions)

type ResolverEtcd added in v1.0.2

type ResolverEtcd struct {
	// contains filtered or unexported fields
}

func NewResolverEtcd added in v1.0.2

func NewResolverEtcd(ctx context.Context, cli *goo_etcd.Client) *ResolverEtcd

func (*ResolverEtcd) Build added in v1.0.2

func (*ResolverEtcd) Scheme added in v1.0.2

func (b *ResolverEtcd) Scheme() string

type Server

type Server struct {
	*grpc.Server
	// contains filtered or unexported fields
}

func New

func New(cfg Config) *Server

func (*Server) Register2Etcd added in v1.0.2

func (s *Server) Register2Etcd(cli *goo_etcd.Client) *Server

func (*Server) Serve

func (s *Server) Serve() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL