Last active
February 27, 2019 22:15
-
-
Save swedishborgie/ea6b9f0f58aa1b4590713923125035c6 to your computer and use it in GitHub Desktop.
protoc-gen-micro issue #12 example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
option go_package = "myservice"; | |
message MyMessage { | |
uint32 id = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code generated by protoc-gen-micro. DO NOT EDIT. | |
// source: service.proto | |
/* | |
Package myservice is a generated protocol buffer package. | |
It is generated from these files: | |
service.proto | |
It has these top-level messages: | |
*/ | |
package myservice | |
import proto "github.com/golang/protobuf/proto" | |
import fmt "fmt" | |
import math "math" | |
import ( | |
context "context" | |
client "github.com/micro/go-micro/client" | |
server "github.com/micro/go-micro/server" | |
) | |
// Reference imports to suppress errors if they are not otherwise used. | |
var _ = proto.Marshal | |
var _ = fmt.Errorf | |
var _ = math.Inf | |
// This is a compile-time assertion to ensure that this generated file | |
// is compatible with the proto package it is being compiled against. | |
// A compilation error at this line likely means your copy of the | |
// proto package needs to be updated. | |
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package | |
// Reference imports to suppress errors if they are not otherwise used. | |
var _ context.Context | |
var _ client.Option | |
var _ server.Option | |
// Client API for MyService service | |
type MyService interface { | |
DoThing(ctx context.Context, in *MyMessage, opts ...client.CallOption) (*MyMessage, error) | |
} | |
type myService struct { | |
c client.Client | |
name string | |
} | |
func NewMyService(name string, c client.Client) MyService { | |
if c == nil { | |
c = client.NewClient() | |
} | |
if len(name) == 0 { | |
name = "myservice" | |
} | |
return &myService{ | |
c: c, | |
name: name, | |
} | |
} | |
func (c *myService) DoThing(ctx context.Context, in *MyMessage, opts ...client.CallOption) (*MyMessage, error) { | |
req := c.c.NewRequest(c.name, "MyService.DoThing", in) | |
out := new(MyMessage) | |
err := c.c.Call(ctx, req, out, opts...) | |
if err != nil { | |
return nil, err | |
} | |
return out, nil | |
} | |
// Server API for MyService service | |
type MyServiceHandler interface { | |
DoThing(context.Context, *MyMessage, *MyMessage) error | |
} | |
func RegisterMyServiceHandler(s server.Server, hdlr MyServiceHandler, opts ...server.HandlerOption) error { | |
type myService interface { | |
DoThing(ctx context.Context, in *MyMessage, out *MyMessage) error | |
} | |
type MyService struct { | |
myService | |
} | |
h := &myServiceHandler{hdlr} | |
return s.Handle(s.NewHandler(&MyService{h}, opts...)) | |
} | |
type myServiceHandler struct { | |
MyServiceHandler | |
} | |
func (h *myServiceHandler) DoThing(ctx context.Context, in *MyMessage, out *MyMessage) error { | |
return h.MyServiceHandler.DoThing(ctx, in, out) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code generated by protoc-gen-micro. DO NOT EDIT. | |
// source: service.proto | |
/* | |
Package myservice is a generated protocol buffer package. | |
It is generated from these files: | |
service.proto | |
It has these top-level messages: | |
*/ | |
package myservice | |
import proto "github.com/golang/protobuf/proto" | |
import fmt "fmt" | |
import math "math" | |
import messages "." | |
import ( | |
context "context" | |
client "github.com/micro/go-micro/client" | |
server "github.com/micro/go-micro/server" | |
) | |
// Reference imports to suppress errors if they are not otherwise used. | |
var _ = proto.Marshal | |
var _ = fmt.Errorf | |
var _ = math.Inf | |
var _ = messages.MyMessage{} | |
// This is a compile-time assertion to ensure that this generated file | |
// is compatible with the proto package it is being compiled against. | |
// A compilation error at this line likely means your copy of the | |
// proto package needs to be updated. | |
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package | |
// Reference imports to suppress errors if they are not otherwise used. | |
var _ context.Context | |
var _ client.Option | |
var _ server.Option | |
// Client API for MyService service | |
type MyService interface { | |
DoThing(ctx context.Context, in *messages.MyMessage, opts ...client.CallOption) (*messages.MyMessage, error) | |
} | |
type myService struct { | |
c client.Client | |
name string | |
} | |
func NewMyService(name string, c client.Client) MyService { | |
if c == nil { | |
c = client.NewClient() | |
} | |
if len(name) == 0 { | |
name = "myservice" | |
} | |
return &myService{ | |
c: c, | |
name: name, | |
} | |
} | |
func (c *myService) DoThing(ctx context.Context, in *messages.MyMessage, opts ...client.CallOption) (*messages.MyMessage, error) { | |
req := c.c.NewRequest(c.name, "MyService.DoThing", in) | |
out := new(messages.MyMessage) | |
err := c.c.Call(ctx, req, out, opts...) | |
if err != nil { | |
return nil, err | |
} | |
return out, nil | |
} | |
// Server API for MyService service | |
type MyServiceHandler interface { | |
DoThing(context.Context, *messages.MyMessage, *messages.MyMessage) error | |
} | |
func RegisterMyServiceHandler(s server.Server, hdlr MyServiceHandler, opts ...server.HandlerOption) error { | |
type myService interface { | |
DoThing(ctx context.Context, in *messages.MyMessage, out *messages.MyMessage) error | |
} | |
type MyService struct { | |
myService | |
} | |
h := &myServiceHandler{hdlr} | |
return s.Handle(s.NewHandler(&MyService{h}, opts...)) | |
} | |
type myServiceHandler struct { | |
MyServiceHandler | |
} | |
func (h *myServiceHandler) DoThing(ctx context.Context, in *messages.MyMessage, out *messages.MyMessage) error { | |
return h.MyServiceHandler.DoThing(ctx, in, out) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
option go_package = "myservice"; | |
import "messages.proto"; | |
service MyService { | |
rpc DoThing(MyMessage) returns (MyMessage) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment