add traffic limiter plugin

This commit is contained in:
ginuerzh 2023-11-18 18:26:15 +08:00
parent 0ae4157b9d
commit bfe81cbb44
8 changed files with 510 additions and 18 deletions

View File

@ -41,7 +41,7 @@ func main() {
} }
resp := bypassResponse{ resp := bypassResponse{
OK: true, OK: false,
} }
log.Printf("bypass: client=%s network=%s, addr=%s, host=%s", rb.Client, rb.Network, rb.Addr, rb.Host) log.Printf("bypass: client=%s network=%s, addr=%s, host=%s", rb.Client, rb.Network, rb.Addr, rb.Host)

View File

@ -34,6 +34,7 @@ type SelectRequest struct {
Host string `protobuf:"bytes,3,opt,name=host,proto3" json:"host,omitempty"` Host string `protobuf:"bytes,3,opt,name=host,proto3" json:"host,omitempty"`
Client string `protobuf:"bytes,4,opt,name=client,proto3" json:"client,omitempty"` Client string `protobuf:"bytes,4,opt,name=client,proto3" json:"client,omitempty"`
Path string `protobuf:"bytes,5,opt,name=path,proto3" json:"path,omitempty"` Path string `protobuf:"bytes,5,opt,name=path,proto3" json:"path,omitempty"`
Src string `protobuf:"bytes,6,opt,name=src,proto3" json:"src,omitempty"`
} }
func (x *SelectRequest) Reset() { func (x *SelectRequest) Reset() {
@ -103,6 +104,13 @@ func (x *SelectRequest) GetPath() string {
return "" return ""
} }
func (x *SelectRequest) GetSrc() string {
if x != nil {
return x.Src
}
return ""
}
type SelectReply struct { type SelectReply struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -154,23 +162,25 @@ var File_hop_proto protoreflect.FileDescriptor
var file_hop_proto_rawDesc = []byte{ var file_hop_proto_rawDesc = []byte{
0x0a, 0x09, 0x68, 0x6f, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x0a, 0x09, 0x68, 0x6f, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x22, 0x7d, 0x0a, 0x0d, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x74, 0x6f, 0x22, 0x8f, 0x01, 0x0a, 0x0d, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71,
0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18,
0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12,
0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64,
0x72, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x64, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
0x04, 0x68, 0x6f, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x18, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74,
0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x12,
0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61,
0x68, 0x22, 0x21, 0x0a, 0x0b, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x74, 0x68, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x72, 0x63, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52,
0x12, 0x12, 0x0a, 0x04, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x03, 0x73, 0x72, 0x63, 0x22, 0x21, 0x0a, 0x0b, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65,
0x6e, 0x6f, 0x64, 0x65, 0x32, 0x39, 0x0a, 0x03, 0x48, 0x6f, 0x70, 0x12, 0x32, 0x0a, 0x06, 0x53, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
0x65, 0x6c, 0x65, 0x63, 0x74, 0x12, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x0c, 0x52, 0x04, 0x6e, 0x6f, 0x64, 0x65, 0x32, 0x39, 0x0a, 0x03, 0x48, 0x6f, 0x70, 0x12, 0x32,
0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x70, 0x72, 0x0a, 0x06, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x12, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x42, 0x2e, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12,
0x25, 0x5a, 0x23, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x70,
0x2d, 0x67, 0x6f, 0x73, 0x74, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x68, 0x6f, 0x70, 0x6c, 0x79, 0x42, 0x25, 0x5a, 0x23, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x2f, 0x67, 0x6f, 0x2d, 0x67, 0x6f, 0x73, 0x74, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f,
0x68, 0x6f, 0x70, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
} }
var ( var (

View File

@ -12,6 +12,7 @@ message SelectRequest {
string host = 3; string host = 3;
string client = 4; string client = 4;
string path = 5; string path = 5;
string src = 6;
} }
message SelectReply { message SelectReply {

View File

@ -0,0 +1,43 @@
package main
import (
"context"
"flag"
"fmt"
"log"
"net"
"github.com/go-gost/plugin/limiter/traffic/proto"
"google.golang.org/grpc"
)
var (
port = flag.Int("port", 8000, "The server port")
)
type server struct {
proto.UnimplementedLimiterServer
}
func (s *server) Limit(ctx context.Context, in *proto.LimitRequest) (*proto.LimitReply, error) {
reply := &proto.LimitReply{
In: 1024 * 1024,
Out: 512 * 1024,
}
log.Printf("limiter: client=%s src=%s network=%s, addr=%s", in.Client, in.Src, in.Network, in.Addr)
return reply, nil
}
func main() {
flag.Parse()
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
proto.RegisterLimiterServer(s, &server{})
log.Printf("server listening at %v", lis.Addr())
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}

View File

@ -0,0 +1,57 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"net"
"net/http"
)
var (
port = flag.Int("port", 8000, "The server port")
)
type limiterRequest struct {
Network string `json:"network"`
Addr string `json:"addr"`
Client string `json:"client"`
Src string `json:"src"`
}
type limiterResponse struct {
In int64 `json:"in"`
Out int64 `json:"out"`
}
func main() {
flag.Parse()
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
log.Printf("server listening at %v", lis.Addr())
http.HandleFunc("/limiter", func(w http.ResponseWriter, r *http.Request) {
req := limiterRequest{}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
log.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
resp := limiterResponse{
In: 1024 * 1024, // 1MB
Out: 512 * 1024, // 512KB
}
log.Printf("limiter: client=%s src=%s network=%s, addr=%s", req.Client, req.Src, req.Network, req.Addr)
json.NewEncoder(w).Encode(resp)
})
if err := http.Serve(lis, nil); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}

View File

@ -0,0 +1,253 @@
// protoc --go_out=. --go_opt=paths=source_relative \
// --go-grpc_out=. --go-grpc_opt=paths=source_relative \
// limiter.proto
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc v3.15.8
// source: limiter.proto
package proto
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type LimitRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"`
Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"`
Client string `protobuf:"bytes,3,opt,name=client,proto3" json:"client,omitempty"`
Src string `protobuf:"bytes,4,opt,name=src,proto3" json:"src,omitempty"`
}
func (x *LimitRequest) Reset() {
*x = LimitRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_limiter_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *LimitRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LimitRequest) ProtoMessage() {}
func (x *LimitRequest) ProtoReflect() protoreflect.Message {
mi := &file_limiter_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use LimitRequest.ProtoReflect.Descriptor instead.
func (*LimitRequest) Descriptor() ([]byte, []int) {
return file_limiter_proto_rawDescGZIP(), []int{0}
}
func (x *LimitRequest) GetNetwork() string {
if x != nil {
return x.Network
}
return ""
}
func (x *LimitRequest) GetAddr() string {
if x != nil {
return x.Addr
}
return ""
}
func (x *LimitRequest) GetClient() string {
if x != nil {
return x.Client
}
return ""
}
func (x *LimitRequest) GetSrc() string {
if x != nil {
return x.Src
}
return ""
}
type LimitReply struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
In int64 `protobuf:"varint,1,opt,name=in,proto3" json:"in,omitempty"`
Out int64 `protobuf:"varint,2,opt,name=out,proto3" json:"out,omitempty"`
}
func (x *LimitReply) Reset() {
*x = LimitReply{}
if protoimpl.UnsafeEnabled {
mi := &file_limiter_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *LimitReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LimitReply) ProtoMessage() {}
func (x *LimitReply) ProtoReflect() protoreflect.Message {
mi := &file_limiter_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use LimitReply.ProtoReflect.Descriptor instead.
func (*LimitReply) Descriptor() ([]byte, []int) {
return file_limiter_proto_rawDescGZIP(), []int{1}
}
func (x *LimitReply) GetIn() int64 {
if x != nil {
return x.In
}
return 0
}
func (x *LimitReply) GetOut() int64 {
if x != nil {
return x.Out
}
return 0
}
var File_limiter_proto protoreflect.FileDescriptor
var file_limiter_proto_rawDesc = []byte{
0x0a, 0x0d, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x66, 0x0a, 0x0c, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72,
0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b,
0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x61, 0x64, 0x64, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x18, 0x03,
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03,
0x73, 0x72, 0x63, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x72, 0x63, 0x22, 0x2e,
0x0a, 0x0a, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x0e, 0x0a, 0x02,
0x69, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x6e, 0x12, 0x10, 0x0a, 0x03,
0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x6f, 0x75, 0x74, 0x32, 0x3a,
0x0a, 0x07, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x72, 0x12, 0x2f, 0x0a, 0x05, 0x4c, 0x69, 0x6d,
0x69, 0x74, 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x69, 0x6d, 0x69, 0x74,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x4c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x69,
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x67, 0x6f, 0x73, 0x74,
0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x72, 0x2f,
0x74, 0x72, 0x61, 0x66, 0x66, 0x69, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_limiter_proto_rawDescOnce sync.Once
file_limiter_proto_rawDescData = file_limiter_proto_rawDesc
)
func file_limiter_proto_rawDescGZIP() []byte {
file_limiter_proto_rawDescOnce.Do(func() {
file_limiter_proto_rawDescData = protoimpl.X.CompressGZIP(file_limiter_proto_rawDescData)
})
return file_limiter_proto_rawDescData
}
var file_limiter_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_limiter_proto_goTypes = []interface{}{
(*LimitRequest)(nil), // 0: proto.LimitRequest
(*LimitReply)(nil), // 1: proto.LimitReply
}
var file_limiter_proto_depIdxs = []int32{
0, // 0: proto.Limiter.Limit:input_type -> proto.LimitRequest
1, // 1: proto.Limiter.Limit:output_type -> proto.LimitReply
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_limiter_proto_init() }
func file_limiter_proto_init() {
if File_limiter_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_limiter_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*LimitRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_limiter_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*LimitReply); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_limiter_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_limiter_proto_goTypes,
DependencyIndexes: file_limiter_proto_depIdxs,
MessageInfos: file_limiter_proto_msgTypes,
}.Build()
File_limiter_proto = out.File
file_limiter_proto_rawDesc = nil
file_limiter_proto_goTypes = nil
file_limiter_proto_depIdxs = nil
}

View File

@ -0,0 +1,23 @@
// protoc --go_out=. --go_opt=paths=source_relative \
// --go-grpc_out=. --go-grpc_opt=paths=source_relative \
// limiter.proto
syntax = "proto3";
package proto;
option go_package = "github.com/go-gost/plugin/limiter/traffic/proto";
message LimitRequest {
string network = 1;
string addr = 2;
string client = 3;
string src = 4;
}
message LimitReply {
int64 in = 1;
int64 out = 2;
}
service Limiter {
rpc Limit(LimitRequest) returns (LimitReply);
}

View File

@ -0,0 +1,105 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.15.8
// source: limiter.proto
package proto
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// LimiterClient is the client API for Limiter service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type LimiterClient interface {
Limit(ctx context.Context, in *LimitRequest, opts ...grpc.CallOption) (*LimitReply, error)
}
type limiterClient struct {
cc grpc.ClientConnInterface
}
func NewLimiterClient(cc grpc.ClientConnInterface) LimiterClient {
return &limiterClient{cc}
}
func (c *limiterClient) Limit(ctx context.Context, in *LimitRequest, opts ...grpc.CallOption) (*LimitReply, error) {
out := new(LimitReply)
err := c.cc.Invoke(ctx, "/proto.Limiter/Limit", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// LimiterServer is the server API for Limiter service.
// All implementations must embed UnimplementedLimiterServer
// for forward compatibility
type LimiterServer interface {
Limit(context.Context, *LimitRequest) (*LimitReply, error)
mustEmbedUnimplementedLimiterServer()
}
// UnimplementedLimiterServer must be embedded to have forward compatible implementations.
type UnimplementedLimiterServer struct {
}
func (UnimplementedLimiterServer) Limit(context.Context, *LimitRequest) (*LimitReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Limit not implemented")
}
func (UnimplementedLimiterServer) mustEmbedUnimplementedLimiterServer() {}
// UnsafeLimiterServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to LimiterServer will
// result in compilation errors.
type UnsafeLimiterServer interface {
mustEmbedUnimplementedLimiterServer()
}
func RegisterLimiterServer(s grpc.ServiceRegistrar, srv LimiterServer) {
s.RegisterService(&Limiter_ServiceDesc, srv)
}
func _Limiter_Limit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LimitRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LimiterServer).Limit(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/proto.Limiter/Limit",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LimiterServer).Limit(ctx, req.(*LimitRequest))
}
return interceptor(ctx, in, info, handler)
}
// Limiter_ServiceDesc is the grpc.ServiceDesc for Limiter service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Limiter_ServiceDesc = grpc.ServiceDesc{
ServiceName: "proto.Limiter",
HandlerType: (*LimiterServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Limit",
Handler: _Limiter_Limit_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "limiter.proto",
}