Merge remote-tracking branch 'rem/v3' into v3
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
<<<<<<< HEAD
|
||||
package meter // import "go.unistack.org/micro-server-http/v4/handler/meter"
|
||||
=======
|
||||
package meter_handler
|
||||
>>>>>>> rem/v3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -8,11 +12,18 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
<<<<<<< HEAD
|
||||
codecpb "go.unistack.org/micro-proto/v4/codec"
|
||||
"go.unistack.org/micro/v4/logger"
|
||||
"go.unistack.org/micro/v4/metadata"
|
||||
"go.unistack.org/micro/v4/meter"
|
||||
"go.unistack.org/micro/v4/options"
|
||||
=======
|
||||
codecpb "go.unistack.org/micro-proto/v3/codec"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
>>>>>>> rem/v3
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -36,7 +47,7 @@ var bufPool = sync.Pool{
|
||||
var _ MeterServiceServer = (*Handler)(nil)
|
||||
|
||||
type Handler struct {
|
||||
opts Options
|
||||
Options Options
|
||||
}
|
||||
|
||||
type Option func(*Options)
|
||||
@@ -44,7 +55,11 @@ type Option func(*Options)
|
||||
type Options struct {
|
||||
Meter meter.Meter
|
||||
Name string
|
||||
<<<<<<< HEAD
|
||||
MeterOptions []options.Option
|
||||
=======
|
||||
MeterOptions []meter.Option
|
||||
>>>>>>> rem/v3
|
||||
DisableCompress bool
|
||||
}
|
||||
|
||||
@@ -66,7 +81,11 @@ func DisableCompress(g bool) Option {
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
func MeterOptions(opts ...options.Option) Option {
|
||||
=======
|
||||
func MeterOptions(opts ...meter.Option) Option {
|
||||
>>>>>>> rem/v3
|
||||
return func(o *Options) {
|
||||
o.MeterOptions = append(o.MeterOptions, opts...)
|
||||
}
|
||||
@@ -82,7 +101,7 @@ func NewOptions(opts ...Option) Options {
|
||||
|
||||
func NewHandler(opts ...Option) *Handler {
|
||||
options := NewOptions(opts...)
|
||||
return &Handler{opts: options}
|
||||
return &Handler{Options: options}
|
||||
}
|
||||
|
||||
func (h *Handler) Metrics(ctx context.Context, req *codecpb.Frame, rsp *codecpb.Frame) error {
|
||||
@@ -97,7 +116,11 @@ func (h *Handler) Metrics(ctx context.Context, req *codecpb.Frame, rsp *codecpb.
|
||||
|
||||
w := io.Writer(buf)
|
||||
|
||||
<<<<<<< HEAD
|
||||
if md, ok := metadata.FromIncomingContext(ctx); gzipAccepted(md) && ok && !h.opts.DisableCompress {
|
||||
=======
|
||||
if md, ok := metadata.FromOutgoingContext(ctx); gzipAccepted(md) && ok && !h.Options.DisableCompress {
|
||||
>>>>>>> rem/v3
|
||||
omd, _ := metadata.FromOutgoingContext(ctx)
|
||||
omd.Set(contentEncodingHeader, "gzip")
|
||||
gz := gzipPool.Get().(*gzip.Writer)
|
||||
@@ -110,8 +133,13 @@ func (h *Handler) Metrics(ctx context.Context, req *codecpb.Frame, rsp *codecpb.
|
||||
gz.Flush()
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
if err := h.opts.Meter.Write(w, h.opts.MeterOptions...); err != nil {
|
||||
log.Error(ctx, "http/meter: write failed", err)
|
||||
=======
|
||||
if err := h.Options.Meter.Write(w, h.Options.MeterOptions...); err != nil {
|
||||
log.Error(ctx, "http/meter write failed", err)
|
||||
>>>>>>> rem/v3
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
syntax = "proto3";
|
||||
|
||||
<<<<<<< HEAD
|
||||
package micro.server.http.v4.handler.meter;
|
||||
option go_package = "go.unistack.org/micro-server-http/v4/handler/meter;meter";
|
||||
=======
|
||||
package micro.server.http.v3.handler.meter;
|
||||
option go_package = "go.unistack.org/micro-server-http/v3/handler/meter;meter_handler";
|
||||
>>>>>>> rem/v3
|
||||
|
||||
import "api/annotations.proto";
|
||||
import "openapiv3/annotations.proto";
|
||||
|
||||
@@ -1,19 +1,36 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// versions:
|
||||
<<<<<<< HEAD
|
||||
// - protoc-gen-go-micro v4.0.2
|
||||
// - protoc v4.23.4
|
||||
=======
|
||||
// - protoc-gen-go-micro v3.10.4
|
||||
// - protoc v5.28.3
|
||||
>>>>>>> rem/v3
|
||||
// source: meter/meter.proto
|
||||
|
||||
package meter
|
||||
package meter_handler
|
||||
|
||||
import (
|
||||
context "context"
|
||||
<<<<<<< HEAD
|
||||
codec "go.unistack.org/micro-proto/v4/codec"
|
||||
=======
|
||||
codec "go.unistack.org/micro-proto/v3/codec"
|
||||
client "go.unistack.org/micro/v3/client"
|
||||
>>>>>>> rem/v3
|
||||
)
|
||||
|
||||
var (
|
||||
MeterServiceName = "MeterService"
|
||||
)
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
type MeterServiceClient interface {
|
||||
Metrics(ctx context.Context, req *codec.Frame, opts ...client.CallOption) (*codec.Frame, error)
|
||||
}
|
||||
>>>>>>> rem/v3
|
||||
|
||||
type MeterServiceServer interface {
|
||||
Metrics(ctx context.Context, req *codec.Frame, rsp *codec.Frame) error
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
<<<<<<< HEAD
|
||||
// protoc-gen-go-micro version: v4.0.2
|
||||
=======
|
||||
// protoc-gen-go-micro version: v3.10.4
|
||||
>>>>>>> rem/v3
|
||||
// source: meter/meter.proto
|
||||
|
||||
package meter
|
||||
package meter_handler
|
||||
|
||||
import (
|
||||
context "context"
|
||||
<<<<<<< HEAD
|
||||
codec "go.unistack.org/micro-proto/v4/codec"
|
||||
v4 "go.unistack.org/micro-server-http/v4"
|
||||
options "go.unistack.org/micro/v4/options"
|
||||
@@ -22,8 +27,55 @@ var (
|
||||
Stream: false,
|
||||
},
|
||||
}
|
||||
=======
|
||||
v31 "go.unistack.org/micro-client-http/v3"
|
||||
codec "go.unistack.org/micro-proto/v3/codec"
|
||||
v3 "go.unistack.org/micro-server-http/v3"
|
||||
client "go.unistack.org/micro/v3/client"
|
||||
server "go.unistack.org/micro/v3/server"
|
||||
http "net/http"
|
||||
>>>>>>> rem/v3
|
||||
)
|
||||
|
||||
var (
|
||||
MeterServiceServerEndpoints = []v3.EndpointMetadata{
|
||||
{
|
||||
Name: "MeterService.Metrics",
|
||||
Path: "/metrics",
|
||||
Method: "GET",
|
||||
Body: "",
|
||||
Stream: false,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
type meterServiceClient struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewMeterServiceClient(name string, c client.Client) MeterServiceClient {
|
||||
return &meterServiceClient{c: c, name: name}
|
||||
}
|
||||
|
||||
func (c *meterServiceClient) Metrics(ctx context.Context, req *codec.Frame, opts ...client.CallOption) (*codec.Frame, error) {
|
||||
errmap := make(map[string]interface{}, 1)
|
||||
errmap["default"] = &codec.Frame{}
|
||||
opts = append(opts,
|
||||
v31.ErrorMap(errmap),
|
||||
)
|
||||
opts = append(opts,
|
||||
v31.Method(http.MethodGet),
|
||||
v31.Path("/metrics"),
|
||||
)
|
||||
rsp := &codec.Frame{}
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "MeterService.Metrics", req), rsp, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
type meterServiceServer struct {
|
||||
MeterServiceServer
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user