/
uistep.go
94 lines (69 loc) · 1.99 KB
/
uistep.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package gaia
import (
"fmt"
"github.com/mitchellh/copystructure"
"go.aporeto.io/elemental"
)
// UIStep represents the model of a uistep
type UIStep struct {
// Defines if the step is an advanced one.
Advanced bool `json:"advanced" msgpack:"advanced" bson:"advanced" mapstructure:"advanced,omitempty"`
// Description of the step.
Description string `json:"description" msgpack:"description" bson:"description" mapstructure:"description,omitempty"`
// Name of the step.
Name string `json:"name" msgpack:"name" bson:"name" mapstructure:"name,omitempty"`
// List of parameters for this step.
Parameters []*UIParameter `json:"parameters" msgpack:"parameters" bson:"parameters" mapstructure:"parameters,omitempty"`
ModelVersion int `json:"-" msgpack:"-" bson:"_modelversion"`
}
// NewUIStep returns a new *UIStep
func NewUIStep() *UIStep {
return &UIStep{
ModelVersion: 1,
Parameters: []*UIParameter{},
}
}
// BleveType implements the bleve.Classifier Interface.
func (o *UIStep) BleveType() string {
return "uistep"
}
// DeepCopy returns a deep copy if the UIStep.
func (o *UIStep) DeepCopy() *UIStep {
if o == nil {
return nil
}
out := &UIStep{}
o.DeepCopyInto(out)
return out
}
// DeepCopyInto copies the receiver into the given *UIStep.
func (o *UIStep) DeepCopyInto(out *UIStep) {
target, err := copystructure.Copy(o)
if err != nil {
panic(fmt.Sprintf("Unable to deepcopy UIStep: %s", err))
}
*out = *target.(*UIStep)
}
// Validate valides the current information stored into the structure.
func (o *UIStep) Validate() error {
errors := elemental.Errors{}
requiredErrors := elemental.Errors{}
if err := elemental.ValidateRequiredString("name", o.Name); err != nil {
requiredErrors = requiredErrors.Append(err)
}
for _, sub := range o.Parameters {
if sub == nil {
continue
}
if err := sub.Validate(); err != nil {
errors = errors.Append(err)
}
}
if len(requiredErrors) > 0 {
return requiredErrors
}
if len(errors) > 0 {
return errors
}
return nil
}