hello

package module
v0.0.0-...-1453545 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 15 Imported by: 0

README

grpc-example

Example Go client-server project that uses gRPC

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client wraps a generated gRPC client with the connection

func NewClient

func NewClient(endpoint string, opts ...grpc.DialOption) (c *Client, err error)

Create a new client from client options

func (*Client) Close

func (c *Client) Close() error

Close the connection

func (*Client) ConnectMock

func (c *Client) ConnectMock(mock *mock.HelloService, opts ...grpc.DialOption) (err error)

Connect the mock to the client

func (*Client) SayBidirectional

func (c *Client) SayBidirectional(ctx context.Context, langs <-chan string, greetings chan<- string) (err error)

func (*Client) SayClientStream

func (c *Client) SayClientStream(ctx context.Context, langs <-chan string) (greetings []string, err error)

func (*Client) SayHello

func (c *Client) SayHello(ctx context.Context, langCode string) (_ string, err error)

func (*Client) SayServerStream

func (c *Client) SayServerStream(ctx context.Context, langCodes []string) (greetings []string, err error)

type Messages

type Messages struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Messages) Get

func (m *Messages) Get(key string) (value string, err error)

func (*Messages) Load

func (m *Messages) Load(path string) (err error)

type Server

type Server struct {
	pb.UnimplementedHelloServer
	// contains filtered or unexported fields
}

Struct that implements the gRPC service

func NewServer

func NewServer(opts ...grpc.ServerOption) (s *Server, err error)

Create a new server

func (*Server) Run

func (s *Server) Run(sock net.Listener)

Run the gRPC server on the socket. This is extracted into its own method to make it easier to inject sockets for testing.

func (*Server) SayBidirectional

func (s *Server) SayBidirectional(stream pb.Hello_SayBidirectionalServer) (err error)

Bidirectional streaming RPC

func (*Server) SayClientStream

func (s *Server) SayClientStream(stream pb.Hello_SayClientStreamServer) (err error)

Client streaming RPC

func (*Server) SayHello

func (s *Server) SayHello(ctx context.Context, req *pb.HelloRequest) (rep *pb.HelloReply, err error)

Unary RPC

func (*Server) SayServerStream

func (s *Server) SayServerStream(req *pb.HelloManyRequest, stream pb.Hello_SayServerStreamServer) (err error)

Server streaming RPC

func (*Server) Serve

func (s *Server) Serve(bindaddr string) (err error)

Start the server

func (*Server) Shutdown

func (s *Server) Shutdown() error

Stop the server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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