gitlab.com/evatix-go/core@v1.3.55/coreinstruction/SourceDestination.go (about)

     1  package coreinstruction
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"gitlab.com/evatix-go/core/constants"
     7  )
     8  
     9  type SourceDestination struct {
    10  	Source      string `json:"Source,omitempty"`
    11  	Destination string `json:"Destination,omitempty"`
    12  }
    13  
    14  func (it *SourceDestination) IsNull() bool {
    15  	return it == nil
    16  }
    17  
    18  func (it *SourceDestination) IsSourceEmpty() bool {
    19  	return it == nil || it.Source == ""
    20  }
    21  
    22  func (it *SourceDestination) IsDestinationEmpty() bool {
    23  	return it == nil || it.Destination == ""
    24  }
    25  
    26  func (it SourceDestination) String() string {
    27  	if it.IsNull() {
    28  		return "SourceDestination null!"
    29  	}
    30  
    31  	return fmt.Sprintf(
    32  		constants.SourceDestinationFormat,
    33  		it.Source,
    34  		it.Destination)
    35  }
    36  
    37  func (it SourceDestination) FromName() string {
    38  	return it.Source
    39  }
    40  
    41  func (it SourceDestination) ToName() string {
    42  	return it.Destination
    43  }
    44  
    45  func (it *SourceDestination) SetFromName(form string) {
    46  	it.Source = form
    47  }
    48  
    49  func (it *SourceDestination) SetToName(to string) {
    50  	it.Destination = to
    51  }
    52  
    53  func (it *SourceDestination) FromTo() *FromTo {
    54  	if it == nil {
    55  		return nil
    56  	}
    57  
    58  	return &FromTo{
    59  		From: it.Source,
    60  		To:   it.Destination,
    61  	}
    62  }
    63  
    64  func (it *SourceDestination) Rename() *Rename {
    65  	if it == nil {
    66  		return nil
    67  	}
    68  
    69  	return &Rename{
    70  		Existing: it.Source,
    71  		New:      it.Destination,
    72  	}
    73  }
    74  
    75  func (it *SourceDestination) Clone() *SourceDestination {
    76  	if it == nil {
    77  		return nil
    78  	}
    79  
    80  	return &SourceDestination{
    81  		Source:      it.Source,
    82  		Destination: it.Destination,
    83  	}
    84  }