mirror of
https://github.com/go-micro/go-micro.git
synced 2025-06-24 22:26:54 +02:00
Add examples
This commit is contained in:
92
examples/template/api/proto/example/example.micro.go
Normal file
92
examples/template/api/proto/example/example.micro.go
Normal file
@ -0,0 +1,92 @@
|
||||
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||
// source: proto/example/example.proto
|
||||
|
||||
package go_micro_api_template
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
proto1 "github.com/micro/go-micro/v2/api/proto"
|
||||
math "math"
|
||||
)
|
||||
|
||||
import (
|
||||
context "context"
|
||||
client "github.com/micro/go-micro/v2/client"
|
||||
server "github.com/micro/go-micro/v2/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.ProtoPackageIsVersion3 // 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 Example service
|
||||
|
||||
type ExampleService interface {
|
||||
Call(ctx context.Context, in *proto1.Request, opts ...client.CallOption) (*proto1.Response, error)
|
||||
}
|
||||
|
||||
type exampleService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewExampleService(name string, c client.Client) ExampleService {
|
||||
if c == nil {
|
||||
c = client.NewClient()
|
||||
}
|
||||
if len(name) == 0 {
|
||||
name = "go.micro.api.template"
|
||||
}
|
||||
return &exampleService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *exampleService) Call(ctx context.Context, in *proto1.Request, opts ...client.CallOption) (*proto1.Response, error) {
|
||||
req := c.c.NewRequest(c.name, "Example.Call", in)
|
||||
out := new(proto1.Response)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for Example service
|
||||
|
||||
type ExampleHandler interface {
|
||||
Call(context.Context, *proto1.Request, *proto1.Response) error
|
||||
}
|
||||
|
||||
func RegisterExampleHandler(s server.Server, hdlr ExampleHandler, opts ...server.HandlerOption) error {
|
||||
type example interface {
|
||||
Call(ctx context.Context, in *proto1.Request, out *proto1.Response) error
|
||||
}
|
||||
type Example struct {
|
||||
example
|
||||
}
|
||||
h := &exampleHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&Example{h}, opts...))
|
||||
}
|
||||
|
||||
type exampleHandler struct {
|
||||
ExampleHandler
|
||||
}
|
||||
|
||||
func (h *exampleHandler) Call(ctx context.Context, in *proto1.Request, out *proto1.Response) error {
|
||||
return h.ExampleHandler.Call(ctx, in, out)
|
||||
}
|
Reference in New Issue
Block a user