ttrpc: rename project to ttrpc
Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
1bfe6fb8f6
commit
f147d6ca77
@ -1,4 +1,4 @@
|
|||||||
package mgrpc
|
package ttrpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package mgrpc
|
package ttrpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package mgrpc
|
package ttrpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
|
"github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
|
||||||
"github.com/gogo/protobuf/vanity"
|
"github.com/gogo/protobuf/vanity"
|
||||||
"github.com/gogo/protobuf/vanity/command"
|
"github.com/gogo/protobuf/vanity/command"
|
||||||
_ "github.com/stevvooe/mgrpc"
|
_ "github.com/stevvooe/ttrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
// source: github.com/stevvooe/mgrpc/example/example.proto
|
// source: github.com/stevvooe/ttrpc/example/example.proto
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Package example is a generated protocol buffer package.
|
Package example is a generated protocol buffer package.
|
||||||
|
|
||||||
It is generated from these files:
|
It is generated from these files:
|
||||||
github.com/stevvooe/mgrpc/example/example.proto
|
github.com/stevvooe/ttrpc/example/example.proto
|
||||||
|
|
||||||
It has these top-level messages:
|
It has these top-level messages:
|
||||||
Method1Request
|
Method1Request
|
||||||
@ -23,7 +23,7 @@ import _ "github.com/gogo/protobuf/gogoproto"
|
|||||||
import _ "github.com/gogo/protobuf/types"
|
import _ "github.com/gogo/protobuf/types"
|
||||||
|
|
||||||
import context "context"
|
import context "context"
|
||||||
import github_com_stevvooe_mgrpc "github.com/stevvooe/mgrpc"
|
import github_com_stevvooe_ttrpc "github.com/stevvooe/ttrpc"
|
||||||
|
|
||||||
import strings "strings"
|
import strings "strings"
|
||||||
import reflect "reflect"
|
import reflect "reflect"
|
||||||
@ -68,9 +68,9 @@ func (*Method2Request) ProtoMessage() {}
|
|||||||
func (*Method2Request) Descriptor() ([]byte, []int) { return fileDescriptorExample, []int{2} }
|
func (*Method2Request) Descriptor() ([]byte, []int) { return fileDescriptorExample, []int{2} }
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
proto.RegisterType((*Method1Request)(nil), "mgrpc.example.v1.Method1Request")
|
proto.RegisterType((*Method1Request)(nil), "ttrpc.example.v1.Method1Request")
|
||||||
proto.RegisterType((*Method1Response)(nil), "mgrpc.example.v1.Method1Response")
|
proto.RegisterType((*Method1Response)(nil), "ttrpc.example.v1.Method1Response")
|
||||||
proto.RegisterType((*Method2Request)(nil), "mgrpc.example.v1.Method2Request")
|
proto.RegisterType((*Method2Request)(nil), "ttrpc.example.v1.Method2Request")
|
||||||
}
|
}
|
||||||
func (m *Method1Request) Marshal() (dAtA []byte, err error) {
|
func (m *Method1Request) Marshal() (dAtA []byte, err error) {
|
||||||
size := m.Size()
|
size := m.Size()
|
||||||
@ -189,23 +189,23 @@ type ExampleService interface {
|
|||||||
Method2(ctx context.Context, req *Method1Request) (*google_protobuf1.Empty, error)
|
Method2(ctx context.Context, req *Method1Request) (*google_protobuf1.Empty, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterExampleService(srv *github_com_stevvooe_mgrpc.Server, svc ExampleService) error {
|
func RegisterExampleService(srv *github_com_stevvooe_ttrpc.Server, svc ExampleService) error {
|
||||||
return srv.Register("mgrpc.example.v1.Example", map[string]github_com_stevvooe_mgrpc.Handler{
|
return srv.Register("ttrpc.example.v1.Example", map[string]github_com_stevvooe_ttrpc.Handler{
|
||||||
"Method1": github_com_stevvooe_mgrpc.HandlerFunc(func(ctx context.Context, req interface{}) (interface{}, error) {
|
"Method1": github_com_stevvooe_ttrpc.HandlerFunc(func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
return svc.Method1(ctx, req.(*Method1Request))
|
return svc.Method1(ctx, req.(*Method1Request))
|
||||||
}),
|
}),
|
||||||
"Method2": github_com_stevvooe_mgrpc.HandlerFunc(func(ctx context.Context, req interface{}) (interface{}, error) {
|
"Method2": github_com_stevvooe_ttrpc.HandlerFunc(func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
return svc.Method2(ctx, req.(*Method1Request))
|
return svc.Method2(ctx, req.(*Method1Request))
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExampleClient struct {
|
type ExampleClient struct {
|
||||||
client *github_com_stevvooe_mgrpc.Client
|
client *github_com_stevvooe_ttrpc.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ExampleClient) Method1(ctx context.Context, req *Method1Request) (*Method1Response, error) {
|
func (c *ExampleClient) Method1(ctx context.Context, req *Method1Request) (*Method1Response, error) {
|
||||||
resp, err := c.client.Call(ctx, "mgrpc.example.v1.Example", "Method1", req)
|
resp, err := c.client.Call(ctx, "ttrpc.example.v1.Example", "Method1", req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -213,7 +213,7 @@ func (c *ExampleClient) Method1(ctx context.Context, req *Method1Request) (*Meth
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ExampleClient) Method2(ctx context.Context, req *Method1Request) (*google_protobuf1.Empty, error) {
|
func (c *ExampleClient) Method2(ctx context.Context, req *Method1Request) (*google_protobuf1.Empty, error) {
|
||||||
resp, err := c.client.Call(ctx, "mgrpc.example.v1.Example", "Method2", req)
|
resp, err := c.client.Call(ctx, "ttrpc.example.v1.Example", "Method2", req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -711,7 +711,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
proto.RegisterFile("github.com/stevvooe/mgrpc/example/example.proto", fileDescriptorExample)
|
proto.RegisterFile("github.com/stevvooe/ttrpc/example/example.proto", fileDescriptorExample)
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileDescriptorExample = []byte{
|
var fileDescriptorExample = []byte{
|
||||||
|
34
generator.go
34
generator.go
@ -1,4 +1,4 @@
|
|||||||
package mgrpc
|
package ttrpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
@ -7,32 +7,32 @@ import (
|
|||||||
"github.com/gogo/protobuf/protoc-gen-gogo/generator"
|
"github.com/gogo/protobuf/protoc-gen-gogo/generator"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mgrpcGenerator struct {
|
type ttrpcGenerator struct {
|
||||||
*generator.Generator
|
*generator.Generator
|
||||||
generator.PluginImports
|
generator.PluginImports
|
||||||
|
|
||||||
typeurlPkg generator.Single
|
typeurlPkg generator.Single
|
||||||
mgrpcPkg generator.Single
|
ttrpcPkg generator.Single
|
||||||
contextPkg generator.Single
|
contextPkg generator.Single
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
generator.RegisterPlugin(new(mgrpcGenerator))
|
generator.RegisterPlugin(new(ttrpcGenerator))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mgrpcGenerator) Name() string {
|
func (p *ttrpcGenerator) Name() string {
|
||||||
return "mgrpc"
|
return "ttrpc"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mgrpcGenerator) Init(g *generator.Generator) {
|
func (p *ttrpcGenerator) Init(g *generator.Generator) {
|
||||||
p.Generator = g
|
p.Generator = g
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mgrpcGenerator) Generate(file *generator.FileDescriptor) {
|
func (p *ttrpcGenerator) Generate(file *generator.FileDescriptor) {
|
||||||
p.PluginImports = generator.NewPluginImports(p.Generator)
|
p.PluginImports = generator.NewPluginImports(p.Generator)
|
||||||
p.contextPkg = p.NewImport("context")
|
p.contextPkg = p.NewImport("context")
|
||||||
p.typeurlPkg = p.NewImport("github.com/containerd/typeurl")
|
p.typeurlPkg = p.NewImport("github.com/containerd/typeurl")
|
||||||
p.mgrpcPkg = p.NewImport("github.com/stevvooe/mgrpc")
|
p.ttrpcPkg = p.NewImport("github.com/stevvooe/ttrpc")
|
||||||
|
|
||||||
for _, service := range file.GetService() {
|
for _, service := range file.GetService() {
|
||||||
serviceName := service.GetName()
|
serviceName := service.GetName()
|
||||||
@ -44,7 +44,7 @@ func (p *mgrpcGenerator) Generate(file *generator.FileDescriptor) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mgrpcGenerator) genService(fullName string, service *descriptor.ServiceDescriptorProto) {
|
func (p *ttrpcGenerator) genService(fullName string, service *descriptor.ServiceDescriptorProto) {
|
||||||
serviceName := service.GetName() + "Service"
|
serviceName := service.GetName() + "Service"
|
||||||
p.P()
|
p.P()
|
||||||
p.P("type ", serviceName, " interface{")
|
p.P("type ", serviceName, " interface{")
|
||||||
@ -61,12 +61,12 @@ func (p *mgrpcGenerator) genService(fullName string, service *descriptor.Service
|
|||||||
|
|
||||||
p.P()
|
p.P()
|
||||||
// registration method
|
// registration method
|
||||||
p.P("func Register", serviceName, "(srv *", p.mgrpcPkg.Use(), ".Server, svc ", serviceName, ") error {")
|
p.P("func Register", serviceName, "(srv *", p.ttrpcPkg.Use(), ".Server, svc ", serviceName, ") error {")
|
||||||
p.In()
|
p.In()
|
||||||
p.P(`return srv.Register("`, fullName, `", map[string]`, p.mgrpcPkg.Use(), ".Handler{")
|
p.P(`return srv.Register("`, fullName, `", map[string]`, p.ttrpcPkg.Use(), ".Handler{")
|
||||||
p.In()
|
p.In()
|
||||||
for _, method := range service.Method {
|
for _, method := range service.Method {
|
||||||
p.P(`"`, method.GetName(), `": `, p.mgrpcPkg.Use(), `.HandlerFunc(func(ctx context.Context, req interface{}) (interface{}, error) {`)
|
p.P(`"`, method.GetName(), `": `, p.ttrpcPkg.Use(), `.HandlerFunc(func(ctx context.Context, req interface{}) (interface{}, error) {`)
|
||||||
p.In()
|
p.In()
|
||||||
p.P("return svc.", method.GetName(), "(ctx, req.(*", p.typeName(method.GetInputType()), "))")
|
p.P("return svc.", method.GetName(), "(ctx, req.(*", p.typeName(method.GetInputType()), "))")
|
||||||
p.Out()
|
p.Out()
|
||||||
@ -82,11 +82,11 @@ func (p *mgrpcGenerator) genService(fullName string, service *descriptor.Service
|
|||||||
p.P()
|
p.P()
|
||||||
p.P("type ", clientStructType, " struct{")
|
p.P("type ", clientStructType, " struct{")
|
||||||
p.In()
|
p.In()
|
||||||
p.P("client *", p.mgrpcPkg.Use(), ".Client")
|
p.P("client *", p.ttrpcPkg.Use(), ".Client")
|
||||||
p.Out()
|
p.Out()
|
||||||
p.P("}")
|
p.P("}")
|
||||||
p.P()
|
p.P()
|
||||||
p.P("func New", clientType, "(client *", p.mgrpcPkg.Use(), ".Client)", serviceName, "{")
|
p.P("func New", clientType, "(client *", p.ttrpcPkg.Use(), ".Client)", serviceName, "{")
|
||||||
p.In()
|
p.In()
|
||||||
p.P("return &", clientStructType, "{")
|
p.P("return &", clientStructType, "{")
|
||||||
p.In()
|
p.In()
|
||||||
@ -115,11 +115,11 @@ func (p *mgrpcGenerator) genService(fullName string, service *descriptor.Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mgrpcGenerator) objectNamed(name string) generator.Object {
|
func (p *ttrpcGenerator) objectNamed(name string) generator.Object {
|
||||||
p.Generator.RecordTypeUse(name)
|
p.Generator.RecordTypeUse(name)
|
||||||
return p.Generator.ObjectNamed(name)
|
return p.Generator.ObjectNamed(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mgrpcGenerator) typeName(str string) string {
|
func (p *ttrpcGenerator) typeName(str string) string {
|
||||||
return p.Generator.TypeName(p.objectNamed(str))
|
return p.Generator.TypeName(p.objectNamed(str))
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package mgrpc
|
package ttrpc
|
||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package mgrpc
|
package ttrpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package mgrpc
|
package ttrpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
Loading…
Reference in New Issue
Block a user