github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/grpcwrapper/rawydb/operation.go (about)

     1  package rawydb
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Operations"
     7  
     8  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
     9  )
    10  
    11  type Operation struct {
    12  	ID     string
    13  	Ready  bool
    14  	Status StatusCode
    15  	Issues Issues
    16  }
    17  
    18  func (o *Operation) FromProto(proto *Ydb_Operations.Operation) error {
    19  	o.ID = proto.GetId()
    20  	o.Ready = proto.GetReady()
    21  	if err := o.Status.FromProto(proto.GetStatus()); err != nil {
    22  		return err
    23  	}
    24  
    25  	return o.Issues.FromProto(proto.GetIssues())
    26  }
    27  
    28  func (o *Operation) OperationStatusToError() error {
    29  	if !o.Status.IsSuccess() {
    30  		return xerrors.WithStackTrace(fmt.Errorf("ydb: create topic error [%v]: %v", o.Status, o.Issues))
    31  	}
    32  
    33  	return nil
    34  }
    35  
    36  func (o *Operation) FromProtoWithStatusCheck(proto *Ydb_Operations.Operation) error {
    37  	if err := o.FromProto(proto); err != nil {
    38  		return err
    39  	}
    40  
    41  	return o.OperationStatusToError()
    42  }