rpc

package
v0.0.0-...-26b160e Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Overview

@Time : 2018/10/12 10:58 @Author : kenny zhu @File : micro_rpc.go @Software: GoLand @Others:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

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

Generator generates implementations of an RPC server for a package. It will declare a new type with the following name: {serviceName}Server with the first letter in lower case. In case the type already exists in the package, it will not be generated again. The purpose of that is that you can customize the type, even though the methods are automatically generated. Same happens with the constructor. If it does not exist, a function named new{ServiceName}Server with no parameters and a single result of the type {serviceName}Server will be generated. It can be defined, to avoid a default implementation, but the same signature is required, as it is used for registering the server implementation.

So, if you have a service named FooService, you can implement `fooServiceServer` and `func newFooServiceServer() *fooServiceServer`.

All generated methods will use as receiver a field in the server implementation with the same name as the type of the receiver. For example, the method generated for `func (*Foo) Bar()` will be require that our `fooServiceServer` had a field with that name.

type fooServiceServer struct {
	Foo *Foo
}

For every method you want to generate an RPC method for, you have to implement its receiver by yourself in the server implementation type and the constructor.

A single file per package will be generated containing all the RPC methods. The file will be written to the package path and it will be named "server.proteus.go"

func NewGenerator

func NewGenerator() *Generator

NewGenerator creates a new Generator.

func (*Generator) Generate

func (g *Generator) Generate(proto *protobuf2.Package, path string) error

Generate creates a new file in the package at the given path and implements the server according to the given proto package. generate rpc service...

type MicroGenerator

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

Generator generates implementations of an RPC server for a package. It will declare a new type with the following name: {serviceName}Server with the first letter in lower case. In case the type already exists in the package, it will not be generated again. The purpose of that is that you can customize the type, even though the methods are automatically generated. Same happens with the constructor. If it does not exist, a function named new{ServiceName}Server with no parameters and a single result of the type {serviceName}Server will be generated. It can be defined, to avoid a default implementation, but the same signature is required, as it is used for registering the server implementation.

So, if you have a service named FooService, you can implement `fooServiceServer` and `func newFooServiceServer() *fooServiceServer`.

All generated methods will use as receiver a field in the server implementation with the same name as the type of the receiver. For example, the method generated for `func (*Foo) Bar()` will be require that our `fooServiceServer` had a field with that name.

type fooServiceServer struct {
	Foo *Foo
}

For every method you want to generate an RPC method for, you have to implement its receiver by yourself in the server implementation type and the constructor.

A single file per package will be generated containing all the RPC methods. The file will be written to the package path and it will be named "server.micro.go"

func NewMicroGenerator

func NewMicroGenerator() *MicroGenerator

NewGenerator creates a new Generator.

func (*MicroGenerator) Generate

func (g *MicroGenerator) Generate(proto *protobuf2.Package, path string) error

Generate creates a new file in the package at the given path and implements the server according to the given proto package. generate micro service...

Jump to

Keyboard shortcuts

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