52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
|
// Code generated by protoc-gen-micro
|
||
|
// source: service.proto
|
||
|
package service
|
||
|
|
||
|
import (
|
||
|
context "context"
|
||
|
proto "github.com/unistack-org/micro-logger-service/v3/proto"
|
||
|
api "github.com/unistack-org/micro/v3/api"
|
||
|
client "github.com/unistack-org/micro/v3/client"
|
||
|
server "github.com/unistack-org/micro/v3/server"
|
||
|
)
|
||
|
|
||
|
type loggerClient struct {
|
||
|
c client.Client
|
||
|
name string
|
||
|
}
|
||
|
|
||
|
func NewLoggerClient(name string, c client.Client) LoggerClient {
|
||
|
return &loggerClient{c: c, name: name}
|
||
|
}
|
||
|
|
||
|
func (c *loggerClient) Log(ctx context.Context, req *proto.Message, opts ...client.CallOption) (*proto.Empty, error) {
|
||
|
rsp := &proto.Empty{}
|
||
|
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Logger.Log", req), rsp, opts...)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return rsp, nil
|
||
|
}
|
||
|
|
||
|
type loggerServer struct {
|
||
|
LoggerServer
|
||
|
}
|
||
|
|
||
|
func (h *loggerServer) Log(ctx context.Context, req *proto.Message, rsp *proto.Empty) error {
|
||
|
return h.LoggerServer.Log(ctx, req, rsp)
|
||
|
}
|
||
|
|
||
|
func RegisterLoggerServer(s server.Server, sh LoggerServer, opts ...server.HandlerOption) error {
|
||
|
type logger interface {
|
||
|
Log(ctx context.Context, req *proto.Message, rsp *proto.Empty) error
|
||
|
}
|
||
|
type Logger struct {
|
||
|
logger
|
||
|
}
|
||
|
h := &loggerServer{sh}
|
||
|
for _, endpoint := range NewLoggerEndpoints() {
|
||
|
opts = append(opts, api.WithEndpoint(endpoint))
|
||
|
}
|
||
|
return s.Handle(s.NewHandler(&Logger{h}, opts...))
|
||
|
}
|