frog

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

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

Go to latest
Published: Feb 24, 2018 License: MIT Imports: 9 Imported by: 0

README

frog

Frog generates golang Google protobuf RPC interface. With the generated rpc interface, it is easy and flexibly to implement your own RPC system.

Installation

+ go get -u github.com/yplusplus/frog
+ copy github.com/yplusplus/frog/link/link_frog.go to github.com/golang/protobuf/protoc-gen-go
+ re-build and re-install protoc-gen-go

And then, you can use following command to generate rpc code: protoc --go_out=plugins=frog:. *.proto

Examples

+ cd github.com/yplusplus/frog/example
+ go build
+ ./example

Check example/ for more detail.

Other

Welcome to contribute

Documentation

Overview

Package frog defines RPC interface

Index

Constants

This section is empty.

Variables

View Source
var (
	TypeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem()
)

Functions

func CallMethod

func CallMethod(meta *RpcMethod, ctx context.Context, request proto.Message, response proto.Message) (err error)

CallMethod invokes meta.method with given arguments

func GenerateServiceDesc

func GenerateServiceDesc(fileDescriptor []byte)

GenerateServiceDesc called by generated code to generate ServiceDesc and MethodDesc

func GenerateServiceDescName

func GenerateServiceDescName(servName string) string

GenerateServiceDescName generates service descriptor name with service name

func RegisterService

func RegisterService(sd *ServiceDesc, service interface{}, register MethodsRegister) (err error)

RegisterService registers all rpc methods in service with given register It is called from generated code

Types

type DefaultCall

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

DefaultCall implements RpcCall interface and is enough to deal with most situations.

func NewDefaultCall

func NewDefaultCall(request, response proto.Message) *DefaultCall

func (*DefaultCall) Close

func (c *DefaultCall) Close(err error)

func (*DefaultCall) Done

func (c *DefaultCall) Done() chan struct{}

func (*DefaultCall) Error

func (c *DefaultCall) Error() error

func (*DefaultCall) Request

func (c *DefaultCall) Request() proto.Message

func (*DefaultCall) Response

func (c *DefaultCall) Response() proto.Message

type MethodDesc

type MethodDesc struct {
	*desc.MethodDescriptorProto
	// contains filtered or unexported fields
}

MethodDesc wraps MethodDescriptorProto and provide more functions

func (*MethodDesc) GetServiceDesc

func (md *MethodDesc) GetServiceDesc() *ServiceDesc

GetServiceDesc returns method's service descriptor

type MethodsRegister

type MethodsRegister func([]*RpcMethod) error

type RpcCall

type RpcCall interface {
	Request() proto.Message  // The request to the rpc
	Response() proto.Message // The response from rpc
	Error() error            // After completion, the error status.
	Done() chan struct{}     // Strobes when call is complete.
}

RpcCall represents an RPC call

type RpcChannel

type RpcChannel interface {

	// Go invokes the function asynchronously. It returns the RpcCall structure
	// representing the invocation and will be called by many goroutines simultaneously.
	Go(method *MethodDesc, ctx context.Context, request proto.Message, response proto.Message) RpcCall
}

RpcChannel represents a communication line to a Service which can be used to call that Service's methods. The Service may be running on another machine. Normally, you should not call an RpcChannel directly, but instead construct a stub Service wrapping it. Example:

  channel := NewMyRpcChannel("remotehost.example.com:1234")
  stub := NewMyServiceStub(channel)
	 err := stub.MyMethod(ctx, &request, &response)
	 call := stub.AsyncMyMethod(ctx, &request, &response)
	 <-call.Done()

type RpcMethod

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

RpcMethod represents a rpc method metadata

func (*RpcMethod) Descriptor

func (meta *RpcMethod) Descriptor() *MethodDesc

Descriptor returns method descriptor

func (*RpcMethod) Name

func (meta *RpcMethod) Name() string

Name returns method name which format is "service.method"

func (*RpcMethod) NewRequest

func (meta *RpcMethod) NewRequest() proto.Message

NewInput news a input variance

func (*RpcMethod) NewResponse

func (meta *RpcMethod) NewResponse() proto.Message

NewInput news a output variance

type ServiceDesc

type ServiceDesc struct {
	*desc.ServiceDescriptorProto
	// contains filtered or unexported fields
}

ServiceDesc wraps ServiceDescriptorProto and provide more functions

func ServiceDescriptor

func ServiceDescriptor(servicename string) *ServiceDesc

ServiceDescriptorProto called by generated code

func (*ServiceDesc) Method

func (sd *ServiceDesc) Method(index int) *MethodDesc

Method returns the i-th method descriptor of service

func (*ServiceDesc) NumMethod

func (sd *ServiceDesc) NumMethod() int

NumMethod returns the number of methods of service

Directories

Path Synopsis
Package main is a generated protocol buffer package.
Package main is a generated protocol buffer package.
Package frog outputs rpc service descriptions in Go code.
Package frog outputs rpc service descriptions in Go code.

Jump to

Keyboard shortcuts

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