private/crashreportpb: add protobuf for crashreport and crashcollect

Change-Id: I17da796030f63471ae0900142413523e8e12895d
This commit is contained in:
Yaroslav Vorobiov 2021-04-08 15:39:15 +03:00
parent 948529a600
commit aa27a8f1dd
5 changed files with 371 additions and 0 deletions

View File

@ -0,0 +1,111 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: crashreport.proto
package crashreportpb
import (
fmt "fmt"
math "math"
proto "github.com/gogo/protobuf/proto"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type ReportRequest struct {
Crash []byte `protobuf:"bytes,1,opt,name=crash,proto3" json:"crash,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ReportRequest) Reset() { *m = ReportRequest{} }
func (m *ReportRequest) String() string { return proto.CompactTextString(m) }
func (*ReportRequest) ProtoMessage() {}
func (*ReportRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_0c640f4432300a07, []int{0}
}
func (m *ReportRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ReportRequest.Unmarshal(m, b)
}
func (m *ReportRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ReportRequest.Marshal(b, m, deterministic)
}
func (m *ReportRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_ReportRequest.Merge(m, src)
}
func (m *ReportRequest) XXX_Size() int {
return xxx_messageInfo_ReportRequest.Size(m)
}
func (m *ReportRequest) XXX_DiscardUnknown() {
xxx_messageInfo_ReportRequest.DiscardUnknown(m)
}
var xxx_messageInfo_ReportRequest proto.InternalMessageInfo
func (m *ReportRequest) GetCrash() []byte {
if m != nil {
return m.Crash
}
return nil
}
type ReportResponse struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ReportResponse) Reset() { *m = ReportResponse{} }
func (m *ReportResponse) String() string { return proto.CompactTextString(m) }
func (*ReportResponse) ProtoMessage() {}
func (*ReportResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_0c640f4432300a07, []int{1}
}
func (m *ReportResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ReportResponse.Unmarshal(m, b)
}
func (m *ReportResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ReportResponse.Marshal(b, m, deterministic)
}
func (m *ReportResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_ReportResponse.Merge(m, src)
}
func (m *ReportResponse) XXX_Size() int {
return xxx_messageInfo_ReportResponse.Size(m)
}
func (m *ReportResponse) XXX_DiscardUnknown() {
xxx_messageInfo_ReportResponse.DiscardUnknown(m)
}
var xxx_messageInfo_ReportResponse proto.InternalMessageInfo
func init() {
proto.RegisterType((*ReportRequest)(nil), "crash.ReportRequest")
proto.RegisterType((*ReportResponse)(nil), "crash.ReportResponse")
}
func init() { proto.RegisterFile("crashreport.proto", fileDescriptor_0c640f4432300a07) }
var fileDescriptor_0c640f4432300a07 = []byte{
// 149 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4c, 0x2e, 0x4a, 0x2c,
0xce, 0x28, 0x4a, 0x2d, 0xc8, 0x2f, 0x2a, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05,
0x0b, 0x29, 0xa9, 0x72, 0xf1, 0x06, 0x81, 0x85, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84,
0x44, 0xb8, 0x20, 0x32, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x3c, 0x41, 0x50, 0x65, 0x02, 0x5c, 0x7c,
0x30, 0x65, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x46, 0x6e, 0x5c, 0xdc, 0xce, 0x20, 0x29, 0x88,
0xb0, 0x90, 0x39, 0x17, 0x1b, 0x94, 0x25, 0xa2, 0x07, 0xd6, 0xa2, 0x87, 0x62, 0xac, 0x94, 0x28,
0x9a, 0x28, 0xc4, 0x14, 0x25, 0x06, 0x27, 0xb5, 0x28, 0x95, 0xe2, 0x92, 0xfc, 0xa2, 0x2c, 0xbd,
0xcc, 0x7c, 0x7d, 0x30, 0x43, 0xbf, 0xa0, 0x28, 0xb3, 0x2c, 0xb1, 0x24, 0x55, 0x1f, 0xc9, 0xcd,
0x05, 0x49, 0x49, 0x6c, 0x60, 0x67, 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xdf, 0xed, 0xec,
0x6f, 0xcb, 0x00, 0x00, 0x00,
}

View File

@ -0,0 +1,17 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
syntax = "proto3";
option go_package = "storj.io/storj/private/crashreportpb";
package crash;
service CrashReport {
rpc Report(ReportRequest) returns(ReportResponse) {}
}
message ReportRequest {
bytes crash = 1;
}
message ReportResponse {}

View File

@ -0,0 +1,115 @@
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
// protoc-gen-go-drpc version: v0.0.20
// source: crashreport.proto
package crashreportpb
import (
bytes "bytes"
context "context"
errors "errors"
jsonpb "github.com/gogo/protobuf/jsonpb"
proto "github.com/gogo/protobuf/proto"
drpc "storj.io/drpc"
drpcerr "storj.io/drpc/drpcerr"
)
type drpcEncoding_File_crashreport_proto struct{}
func (drpcEncoding_File_crashreport_proto) Marshal(msg drpc.Message) ([]byte, error) {
return proto.Marshal(msg.(proto.Message))
}
func (drpcEncoding_File_crashreport_proto) Unmarshal(buf []byte, msg drpc.Message) error {
return proto.Unmarshal(buf, msg.(proto.Message))
}
func (drpcEncoding_File_crashreport_proto) JSONMarshal(msg drpc.Message) ([]byte, error) {
var buf bytes.Buffer
err := new(jsonpb.Marshaler).Marshal(&buf, msg.(proto.Message))
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func (drpcEncoding_File_crashreport_proto) JSONUnmarshal(buf []byte, msg drpc.Message) error {
return jsonpb.Unmarshal(bytes.NewReader(buf), msg.(proto.Message))
}
type DRPCCrashReportClient interface {
DRPCConn() drpc.Conn
Report(ctx context.Context, in *ReportRequest) (*ReportResponse, error)
}
type drpcCrashReportClient struct {
cc drpc.Conn
}
func NewDRPCCrashReportClient(cc drpc.Conn) DRPCCrashReportClient {
return &drpcCrashReportClient{cc}
}
func (c *drpcCrashReportClient) DRPCConn() drpc.Conn { return c.cc }
func (c *drpcCrashReportClient) Report(ctx context.Context, in *ReportRequest) (*ReportResponse, error) {
out := new(ReportResponse)
err := c.cc.Invoke(ctx, "/crash.CrashReport/Report", drpcEncoding_File_crashreport_proto{}, in, out)
if err != nil {
return nil, err
}
return out, nil
}
type DRPCCrashReportServer interface {
Report(context.Context, *ReportRequest) (*ReportResponse, error)
}
type DRPCCrashReportUnimplementedServer struct{}
func (s *DRPCCrashReportUnimplementedServer) Report(context.Context, *ReportRequest) (*ReportResponse, error) {
return nil, drpcerr.WithCode(errors.New("Unimplemented"), 12)
}
type DRPCCrashReportDescription struct{}
func (DRPCCrashReportDescription) NumMethods() int { return 1 }
func (DRPCCrashReportDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
switch n {
case 0:
return "/crash.CrashReport/Report", drpcEncoding_File_crashreport_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCCrashReportServer).
Report(
ctx,
in1.(*ReportRequest),
)
}, DRPCCrashReportServer.Report, true
default:
return "", nil, nil, nil, false
}
}
func DRPCRegisterCrashReport(mux drpc.Mux, impl DRPCCrashReportServer) error {
return mux.Register(impl, DRPCCrashReportDescription{})
}
type DRPCCrashReport_ReportStream interface {
drpc.Stream
SendAndClose(*ReportResponse) error
}
type drpcCrashReport_ReportStream struct {
drpc.Stream
}
func (x *drpcCrashReport_ReportStream) SendAndClose(m *ReportResponse) error {
if err := x.MsgSend(m, drpcEncoding_File_crashreport_proto{}); err != nil {
return err
}
return x.CloseSend()
}

View File

@ -0,0 +1,7 @@
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
// Package crashreportpb contains protobuf definitions for crashreport.
package crashreportpb
//go:generate go run gen.go

View File

@ -0,0 +1,121 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
// +build ignore
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
)
var (
mainpkg = flag.String("pkg", "storj.io/storj/private/crashreportpb", "main package name")
protoc = flag.String("protoc", "protoc", "protoc compiler")
)
var ignoreProto = map[string]bool{
"gogo.proto": true,
}
func ignore(files []string) []string {
xs := []string{}
for _, file := range files {
if !ignoreProto[file] {
xs = append(xs, file)
}
}
return xs
}
// Programs needed for code generation:
//
// github.com/ckaznocha/protoc-gen-lint
// storj.io/drpc/cmd/protoc-gen-drpc
// github.com/nilslice/protolock/cmd/protolock
func main() {
flag.Parse()
// TODO: protolock
{
// cleanup previous files
localfiles, err := filepath.Glob("*.pb.go")
check(err)
all := []string{}
all = append(all, localfiles...)
for _, match := range all {
_ = os.Remove(match)
}
}
{
protofiles, err := filepath.Glob("*.proto")
check(err)
protofiles = ignore(protofiles)
overrideImports := ",Mgoogle/protobuf/timestamp.proto=" + *mainpkg
args := []string{
"--lint_out=.",
"--gogo_out=paths=source_relative" + overrideImports + ":.",
"--go-drpc_out=protolib=github.com/gogo/protobuf,paths=source_relative:.",
"-I=.",
}
args = append(args, protofiles...)
// generate new code
cmd := exec.Command(*protoc, args...)
fmt.Println(strings.Join(cmd.Args, " "))
out, err := cmd.CombinedOutput()
if len(out) > 0 {
fmt.Println(string(out))
}
check(err)
}
{
files, err := filepath.Glob("*.pb.go")
check(err)
for _, file := range files {
process(file)
}
}
{
// format code to get rid of extra imports
out, err := exec.Command("goimports", "-local", "storj.io", "-w", ".").CombinedOutput()
if len(out) > 0 {
fmt.Println(string(out))
}
check(err)
}
}
func process(file string) {
data, err := ioutil.ReadFile(file)
check(err)
source := string(data)
// When generating code to the same path as proto, it will
// end up generating an `import _ "."`, the following replace removes it.
source = strings.Replace(source, `_ "."`, "", -1)
err = ioutil.WriteFile(file, []byte(source), 0644)
check(err)
}
func check(err error) {
if err != nil {
panic(err)
}
}