github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/cmd/internal/types/result.go (about)

     1  /*
     2   * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved.
     3   * This software is released under GPL3.
     4   * The full license information can be found under:
     5   * https://www.gnu.org/licenses/gpl-3.0.en.html
     6   *
     7   */
     8  
     9  package types
    10  
    11  import (
    12  	"github.com/vchain-us/vcn/pkg/api"
    13  )
    14  
    15  type Result struct {
    16  	api.ArtifactResponse `yaml:",inline"`
    17  	Verification         *api.BlockchainVerification `json:"verification" yaml:"verification"`
    18  	Errors               []error                     `json:"error,omitempty" yaml:"error,omitempty"`
    19  }
    20  
    21  func (r *Result) AddError(err error) {
    22  	r.Errors = append(r.Errors, err)
    23  }
    24  
    25  func NewResult(a *api.Artifact, ar *api.ArtifactResponse, v *api.BlockchainVerification) *Result {
    26  
    27  	var vv *api.BlockchainVerification
    28  	if v != nil {
    29  		vCopy := *v
    30  		vv = &vCopy
    31  	}
    32  
    33  	var r Result
    34  
    35  	switch true {
    36  	case ar != nil:
    37  		r = Result{*ar, vv, nil}
    38  	case a != nil:
    39  		r = Result{api.ArtifactResponse{
    40  			Name:        a.Name,
    41  			Kind:        a.Kind,
    42  			Hash:        a.Hash,
    43  			Size:        a.Size,
    44  			ContentType: a.ContentType,
    45  			Metadata:    a.Metadata,
    46  		}, vv, nil}
    47  	default:
    48  		r = Result{}
    49  		r.Verification = vv
    50  	}
    51  
    52  	// Do not show status and level from platform
    53  	r.Status = ""
    54  	r.Level = 0
    55  
    56  	return &r
    57  }