Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toldata generated unreachable code. #18

Open
herpiko opened this issue Oct 2, 2020 · 0 comments
Open

Toldata generated unreachable code. #18

herpiko opened this issue Oct 2, 2020 · 0 comments

Comments

@herpiko
Copy link
Contributor

herpiko commented Oct 2, 2020

Proto,

syntax = "proto3";

package xxx.blob;
option go_package = "xxx_blob";

message BlobChunk {
  int32 size = 1;
  bytes data = 2;
  int32 seq = 3;
}

message BlobData {
  string id = 1;
  string filename = 2;
  string content_type = 3;
  int64 timestamp = 4;
  int64 size = 5;
  string metadata = 6;
  bool has_content = 8;
  bool is_public = 9;
  string bucket = 10;
}

message PutResponse {
  string id = 1;
}

message GetRequest {
  string id = 1;
}

message DeleteRequest {
  string id = 1;
  string bucket = 2;
}

message UpdateRequest {
  string id = 1;
  BlobData list = 3;
}

message GetPublicRequest {
  string filename = 1;
}

message GetPolicyRequest {
  string policy_id = 1;
}

message GetPolicyDocRequest {
  string filename = 1;
}

message GetDefaultRequest {
  string filename = 1;
}

message GetChunksRequest {
  string blob_id = 1;
}

message PutChunksRequest {
  string blob_id = 1;
  BlobChunk chunk = 2;
}

message ListRequest {
  int32 limit = 1;
  int32 page = 2;
  string order_by = 3;
  string order = 4;
  string search = 5;

  // list of files
  int32 total = 6;
  repeated BlobData list = 7;
}

message ListResponse {
  int32 limit = 1;
  int32 page = 2;
  string order_by = 3;
  string order = 4;
  string search = 5;

  // list of files
  int32 total = 6;
  repeated BlobData list = 7;
}

message BucketRequest {
  string filename = 1;
  string bucket = 2;
}

message Empty {}
service Blob {
  rpc Put(BlobData) returns (PutResponse) {}
  rpc Get(GetRequest) returns (BlobData) {}
  rpc GetFromBucket(BucketRequest) returns (BlobData){}
  rpc GetPolicy(GetPolicyRequest) returns (BlobData) {}
  rpc GetPolicyDoc(GetPolicyDocRequest) returns (BlobData) {}
  rpc GetDefault(GetDefaultRequest) returns (BlobData) {}
  rpc GetPublic(GetPublicRequest) returns (BlobData) {}
  rpc List(ListRequest) returns (ListResponse) {}
  rpc Delete(DeleteRequest) returns (Empty) {}
  rpc Update(UpdateRequest) returns (Empty) {}
  rpc PutChunks(stream PutChunksRequest) returns (Empty) {}
  rpc GetChunks(GetChunksRequest) returns (stream BlobChunk) {}
}

go vet,

# xxx_blob
./blob.grpc.pb.go:211:2: unreachable code

blob.grpc.pb.go,

// Code generated by github.com/citradigital/toldata. DO NOT EDIT.
// package: xxx.blob
// source: blob.proto
package xxx_blob

import (
	"io"

	"github.com/citradigital/toldata"
	context "golang.org/x/net/context"
)

// Workaround for template problem
func _eof_grpc() error {
	return io.EOF
}

type BlobGRPC struct {
	Context context.Context
	Bus     *toldata.Bus
	Service *BlobToldataClient
}

func NewBlobGRPC(ctx context.Context, config toldata.ServiceConfiguration) (*BlobGRPC, error) {
	client, err := toldata.NewBus(ctx, config)
	if err != nil {
		return nil, err
	}

	service := BlobGRPC{
		Context: ctx,
		Bus:     client,
		Service: NewBlobToldataClient(client),
	}

	return &service, nil
}

func (svc *BlobGRPC) Close() {
	svc.Bus.Close()
}

func (svc *BlobGRPC) Put(ctx context.Context, req *BlobData) (*PutResponse, error) {
	return svc.Service.Put(ctx, req)
}

func (svc *BlobGRPC) Get(ctx context.Context, req *GetRequest) (*BlobData, error) {
	return svc.Service.Get(ctx, req)
}

func (svc *BlobGRPC) GetFromBucket(ctx context.Context, req *BucketRequest) (*BlobData, error) {
	return svc.Service.GetFromBucket(ctx, req)
}

func (svc *BlobGRPC) GetPolicy(ctx context.Context, req *GetPolicyRequest) (*BlobData, error) {
	return svc.Service.GetPolicy(ctx, req)
}

func (svc *BlobGRPC) GetPolicyDoc(ctx context.Context, req *GetPolicyDocRequest) (*BlobData, error) {
	return svc.Service.GetPolicyDoc(ctx, req)
}

func (svc *BlobGRPC) GetDefault(ctx context.Context, req *GetDefaultRequest) (*BlobData, error) {
	return svc.Service.GetDefault(ctx, req)
}

func (svc *BlobGRPC) GetPublic(ctx context.Context, req *GetPublicRequest) (*BlobData, error) {
	return svc.Service.GetPublic(ctx, req)
}

func (svc *BlobGRPC) List(ctx context.Context, req *ListRequest) (*ListResponse, error) {
	return svc.Service.List(ctx, req)
}

func (svc *BlobGRPC) Delete(ctx context.Context, req *DeleteRequest) (*Empty, error) {
	return svc.Service.Delete(ctx, req)
}

func (svc *BlobGRPC) Update(ctx context.Context, req *UpdateRequest) (*Empty, error) {
	return svc.Service.Update(ctx, req)
}

func (svc *BlobGRPC) PutChunks(stream Blob_PutChunksServer) error {
	svrStream, err := svc.Service.PutChunks(stream.Context())
	if err != nil {
		return err
	}

	for {
		isEOF := false
		data, err := stream.Recv()
		if err != nil {
			if err == io.EOF {
				isEOF = true
			} else {
				return err
			}
		}

		if data != nil {
			err = svrStream.Send(data)
			if err != nil {
				return err
			}
		}
		if isEOF {
			break
		}
	}

	resp, err := svrStream.Done()
	if err != nil {
		return err
	}
	err = stream.SendAndClose(resp)

	if err != nil {
		return err
	}

	return nil
}

func (svc *BlobGRPC) GetChunks(req *GetChunksRequest, stream Blob_GetChunksServer) error {
	svrStream, err := svc.Service.GetChunks(stream.Context(), req)
	if err != nil {
		return err
	}

	for {
		data, err := svrStream.Receive()

		if err != nil {
			return err
		}
		err = stream.Send(data)
		if err != nil {
			return err
		}
	}

	return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant