update recorder proto

This commit is contained in:
ginuerzh 2023-10-27 22:13:11 +08:00
parent e190e1c74d
commit 2cfb0a14b4
5 changed files with 84 additions and 15 deletions

View File

@ -23,7 +23,8 @@ func (s *server) Record(ctx context.Context, in *proto.RecordRequest) (*proto.Re
reply := &proto.RecordReply{
Ok: true,
}
log.Printf("record: %s", string(in.GetData()))
log.Printf("data: %s, metadata: %s", string(in.GetData()), string(in.Metadata))
return reply, nil
}

View File

@ -0,0 +1,53 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"net"
"net/http"
)
var (
port = flag.Int("port", 8000, "The server port")
)
type recorderRequest struct {
Data []byte `json:"data"`
Metadata []byte `json:"metadata"`
}
type recorderResponse struct {
OK bool `json:"ok"`
}
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("/recorder", func(w http.ResponseWriter, r *http.Request) {
rb := recorderRequest{}
if err := json.NewDecoder(r.Body).Decode(&rb); err != nil {
log.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
resp := recorderResponse{
OK: true,
}
log.Printf("recorder: data=%s, metadata: %s", string(rb.Data), string(rb.Metadata))
json.NewEncoder(w).Encode(resp)
})
if err := http.Serve(lis, nil); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}

View File

@ -4,8 +4,8 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.25.0-devel
// protoc v3.14.0
// protoc-gen-go v1.28.1
// protoc v3.15.8
// source: recorder.proto
package proto
@ -30,6 +30,7 @@ type RecordRequest struct {
unknownFields protoimpl.UnknownFields
Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
Metadata []byte `protobuf:"bytes,2,opt,name=metadata,proto3" json:"metadata,omitempty"`
}
func (x *RecordRequest) Reset() {
@ -71,6 +72,13 @@ func (x *RecordRequest) GetData() []byte {
return nil
}
func (x *RecordRequest) GetMetadata() []byte {
if x != nil {
return x.Metadata
}
return nil
}
type RecordReply struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -122,18 +130,20 @@ var File_recorder_proto protoreflect.FileDescriptor
var file_recorder_proto_rawDesc = []byte{
0x0a, 0x0e, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x23, 0x0a, 0x0d, 0x52, 0x65, 0x63, 0x6f, 0x72,
0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3f, 0x0a, 0x0d, 0x52, 0x65, 0x63, 0x6f, 0x72,
0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x1d, 0x0a, 0x0b,
0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x6f,
0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, 0x32, 0x3e, 0x0a, 0x08, 0x52,
0x65, 0x63, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x32, 0x0a, 0x06, 0x52, 0x65, 0x63, 0x6f, 0x72,
0x64, 0x12, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x42, 0x29, 0x5a, 0x27, 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, 0x69, 0x6e, 0x67, 0x72, 0x65, 0x73, 0x73,
0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08,
0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08,
0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, 0x1d, 0x0a, 0x0b, 0x52, 0x65, 0x63, 0x6f,
0x72, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x6b, 0x18, 0x01, 0x20,
0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, 0x32, 0x3e, 0x0a, 0x08, 0x52, 0x65, 0x63, 0x6f, 0x72,
0x64, 0x65, 0x72, 0x12, 0x32, 0x0a, 0x06, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x14, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x63, 0x6f,
0x72, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x42, 0x29, 0x5a, 0x27, 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, 0x69, 0x6e, 0x67, 0x72, 0x65, 0x73, 0x73, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

View File

@ -8,6 +8,7 @@ option go_package = "github.com/go-gost/plugin/ingress/proto";
message RecordRequest {
bytes data = 1;
bytes metadata = 2;
}
message RecordReply {

View File

@ -1,4 +1,8 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.15.8
// source: recorder.proto
package proto