meter/handler: provide initial meter handler

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-03-23 17:00:02 +03:00
parent 8c95448535
commit 881d7afeea
5 changed files with 92 additions and 0 deletions

3
meter/generate.go Normal file
View File

@ -0,0 +1,3 @@
package meter
//go:generate protoc -I./handler -I../ -I/home/vtolstov/.cache/go-path/pkg/mod/github.com/unistack-org/micro-proto@v0.0.1 --micro_out=components=micro|http|server,standalone=false,debug=true,paths=source_relative:./handler handler/handler.proto

View File

@ -0,0 +1,3 @@
package pb
type Empty struct{}

View File

@ -0,0 +1,30 @@
syntax = "proto3";
package meter;
option go_package = "github.com/unistack-org/micro/v3/meter/handler;pb";
import "api/annotations.proto";
import "openapiv2/annotations.proto";
import "codec/frame.proto";
service Meter {
rpc Metrics(Empty) returns (micro.codec.Frame) {
option (micro.openapiv2.openapiv2_operation) = {
operation_id: "Metrics";
responses: {
key: "default";
value: {
description: "Error response";
schema: {
json_schema: {
ref: "Empty";
}
}
}
}
};
option (micro.api.http) = { get: "/metrics"; };
};
};
message Empty{};

View File

@ -0,0 +1,24 @@
// Code generated by protoc-gen-micro
// source: handler.proto
package pb
import (
context "context"
api "github.com/unistack-org/micro/v3/api"
codec "github.com/unistack-org/micro/v3/codec"
)
func NewMeterEndpoints() []*api.Endpoint {
return []*api.Endpoint{
&api.Endpoint{
Name: "Meter.Metrics",
Path: []string{"/metrics"},
Method: []string{"GET"},
Handler: "rpc",
},
}
}
type MeterServer interface {
Metrics(ctx context.Context, req *Empty, rsp *codec.Frame) error
}

View File

@ -0,0 +1,32 @@
// Code generated by protoc-gen-micro
// source: handler.proto
package pb
import (
context "context"
api "github.com/unistack-org/micro/v3/api"
codec "github.com/unistack-org/micro/v3/codec"
server "github.com/unistack-org/micro/v3/server"
)
type meterServer struct {
MeterServer
}
func (h *meterServer) Metrics(ctx context.Context, req *Empty, rsp *codec.Frame) error {
return h.MeterServer.Metrics(ctx, req, rsp)
}
func RegisterMeterServer(s server.Server, sh MeterServer, opts ...server.HandlerOption) error {
type meter interface {
Metrics(ctx context.Context, req *Empty, rsp *codec.Frame) error
}
type Meter struct {
meter
}
h := &meterServer{sh}
for _, endpoint := range NewMeterEndpoints() {
opts = append(opts, api.WithEndpoint(endpoint))
}
return s.Handle(s.NewHandler(&Meter{h}, opts...))
}