github.com/mweagle/Sparta@v1.15.0/aws/step/state_result.go (about)

     1  package step
     2  
     3  import (
     4  	"math/rand"
     5  )
     6  
     7  ////////////////////////////////////////////////////////////////////////////////
     8  // SuccessState
     9  ////////////////////////////////////////////////////////////////////////////////
    10  
    11  // SuccessState represents the end of the state machine
    12  type SuccessState struct {
    13  	baseInnerState
    14  }
    15  
    16  // Name returns the WaitDelay name
    17  func (ss *SuccessState) Name() string {
    18  	return ss.name
    19  }
    20  
    21  // Next sets the step after the wait delay
    22  func (ss *SuccessState) Next(nextState MachineState) MachineState {
    23  	ss.next = nextState
    24  	return ss
    25  }
    26  
    27  // AdjacentStates returns nodes reachable from this node
    28  func (ss *SuccessState) AdjacentStates() []MachineState {
    29  	if ss.next == nil {
    30  		return nil
    31  	}
    32  	return []MachineState{ss.next}
    33  }
    34  
    35  // WithComment returns the WaitDelay comment
    36  func (ss *SuccessState) WithComment(comment string) TransitionState {
    37  	ss.comment = comment
    38  	return ss
    39  }
    40  
    41  // WithInputPath returns the TaskState input data selector
    42  func (ss *SuccessState) WithInputPath(inputPath string) TransitionState {
    43  	ss.inputPath = inputPath
    44  	return ss
    45  }
    46  
    47  // WithOutputPath returns the TaskState output data selector
    48  func (ss *SuccessState) WithOutputPath(outputPath string) TransitionState {
    49  	ss.outputPath = outputPath
    50  	return ss
    51  }
    52  
    53  // MarshalJSON for custom marshalling
    54  func (ss *SuccessState) MarshalJSON() ([]byte, error) {
    55  	return ss.marshalStateJSON("Succeed", nil)
    56  }
    57  
    58  // NewSuccessState returns a "SuccessState" with the supplied
    59  // name
    60  func NewSuccessState(name string) *SuccessState {
    61  	return &SuccessState{
    62  		baseInnerState: baseInnerState{
    63  			name:              name,
    64  			id:                rand.Int63(),
    65  			isEndStateInvalid: true,
    66  		},
    67  	}
    68  }
    69  
    70  ////////////////////////////////////////////////////////////////////////////////
    71  
    72  // FailState represents the end of state machine
    73  type FailState struct {
    74  	baseInnerState
    75  	ErrorName string
    76  	Cause     error
    77  }
    78  
    79  // Name returns the WaitDelay name
    80  func (fs *FailState) Name() string {
    81  	return fs.name
    82  }
    83  
    84  // Next sets the step after the wait delay
    85  func (fs *FailState) Next(nextState MachineState) MachineState {
    86  	return fs
    87  }
    88  
    89  // AdjacentStates returns nodes reachable from this node
    90  func (fs *FailState) AdjacentStates() []MachineState {
    91  	return nil
    92  }
    93  
    94  // WithComment returns the WaitDelay comment
    95  func (fs *FailState) WithComment(comment string) TransitionState {
    96  	fs.comment = comment
    97  	return fs
    98  }
    99  
   100  // WithInputPath returns the TaskState input data selector
   101  func (fs *FailState) WithInputPath(inputPath string) TransitionState {
   102  	return fs
   103  }
   104  
   105  // WithOutputPath returns the TaskState output data selector
   106  func (fs *FailState) WithOutputPath(outputPath string) TransitionState {
   107  	return fs
   108  }
   109  
   110  // MarshalJSON for custom marshaling
   111  func (fs *FailState) MarshalJSON() ([]byte, error) {
   112  	additionalParams := make(map[string]interface{})
   113  	additionalParams["Error"] = fs.ErrorName
   114  	if fs.Cause != nil {
   115  		additionalParams["Cause"] = fs.Cause.Error()
   116  	}
   117  	return fs.marshalStateJSON("Fail", additionalParams)
   118  }
   119  
   120  // NewFailState returns a "FailState" with the supplied
   121  // information
   122  func NewFailState(failStateName string, errorName string, cause error) *FailState {
   123  	return &FailState{
   124  		baseInnerState: baseInnerState{
   125  			name:              failStateName,
   126  			id:                rand.Int63(),
   127  			isEndStateInvalid: true,
   128  		},
   129  		ErrorName: errorName,
   130  		Cause:     cause,
   131  	}
   132  }