Skip to content

Commit

Permalink
improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgooz committed Aug 29, 2018
1 parent e85f699 commit 54011d6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Event struct {
CreatedAt time.Time
}

// Create creates an event.
// Create creates an event eventKey with eventData for service s.
func Create(s *service.Service, eventKey string, eventData map[string]interface{}) (*Event, error) {
event, err := s.GetEvent(eventKey)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions service/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func (s *Service) GetEvent(eventKey string) (*Event, error) {
return event, nil
}

// ValidateData validates event data to match with paremeter config.
// ValidateData produces warnings for event datas that doesn't satisfy their parameter schema.
func (e *Event) ValidateData(eventData map[string]interface{}) []*ParameterWarning {
return validateParametersSchema(e.Data, eventData)
}

// RequireData requires event data to match with paremeter config.
// RequireData requires event datas to be matched with parameter schemas.
func (e *Event) RequireData(eventData map[string]interface{}) error {
warnings := e.ValidateData(eventData)
if len(warnings) > 0 {
Expand Down
8 changes: 4 additions & 4 deletions service/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func (s *Service) GetTask(taskKey string) (*Task, error) {
return task, nil
}

// ValidateInputs validates task inputs to match with paremeter config.
// ValidateInputs produces warnings for task inputs that doesn't satisfy their parameter schema.
func (t *Task) ValidateInputs(taskInputs map[string]interface{}) []*ParameterWarning {
return validateParametersSchema(t.Inputs, taskInputs)
}

// RequireInputs requires task inputs to match with paremeter config.
// RequireInputs requires task inputs to be matched with parameter schemas.
func (t *Task) RequireInputs(taskInputs map[string]interface{}) error {
warnings := t.ValidateInputs(taskInputs)
if len(warnings) > 0 {
Expand All @@ -43,12 +43,12 @@ func (t *Task) GetOutput(outputKey string) (*Output, error) {
return output, nil
}

// ValidateData validates task outputs to match with paremeter config.
// ValidateData produces warnings for task outputs that doesn't satisfy their parameter schema.
func (o *Output) ValidateData(outputData map[string]interface{}) []*ParameterWarning {
return validateParametersSchema(o.Data, outputData)
}

// RequireData requires task outputs to match with paremeter config.
// RequireData requires task outputs to be matched with parameter schemas.
func (o *Output) RequireData(outputData map[string]interface{}) error {
warnings := o.ValidateData(outputData)
if len(warnings) > 0 {
Expand Down
5 changes: 4 additions & 1 deletion service/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func validateParametersSchema(parameters map[string]*Parameter,
return warnings
}

// parameterValidator provides functionalities to check data against parameter schema.
type parameterValidator struct {
key string
parameter *Parameter
Expand All @@ -41,7 +42,7 @@ func newParameterValidator(key string, parameter *Parameter) *parameterValidator
return &parameterValidator{key, parameter}
}

// Validate returns a warning based on the match of the data given in parameter and the parameter.
// Validate validates value by comparing to corresponding parameter schema.
func (v *parameterValidator) Validate(value interface{}) *ParameterWarning {
if value == nil {
if v.parameter.Optional {
Expand All @@ -53,6 +54,7 @@ func (v *parameterValidator) Validate(value interface{}) *ParameterWarning {
return v.validateType(value)
}

// validateType checks if value comforts its expected type.
func (v *parameterValidator) validateType(value interface{}) *ParameterWarning {
switch v.parameter.Type {
case "String":
Expand Down Expand Up @@ -87,6 +89,7 @@ func (v *parameterValidator) validateType(value interface{}) *ParameterWarning {
return nil
}

// newParameterWarning creates a ParameterWarning with given warning message.
func (v *parameterValidator) newParameterWarning(warning string) *ParameterWarning {
return &ParameterWarning{
Key: v.key,
Expand Down

0 comments on commit 54011d6

Please sign in to comment.