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

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