Skip to content

Commit

Permalink
remove redundant functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lovromazgon committed Feb 29, 2024
1 parent e5b020b commit e4d9c1a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 68 deletions.
37 changes: 0 additions & 37 deletions config/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@

package config

import (
"fmt"
"strconv"
"strings"
)

// Parameters is a map of all configuration parameters.
type Parameters map[string]Parameter

Expand Down Expand Up @@ -51,34 +45,3 @@ const (
func (pt ParameterType) MarshalText() ([]byte, error) {
return []byte(pt.String()), nil
}

func (pt *ParameterType) UnmarshalText(b []byte) error {
if len(b) == 0 {
return nil // empty string, do nothing
}

switch string(b) {
case ParameterTypeString.String():
*pt = ParameterTypeString
case ParameterTypeInt.String():
*pt = ParameterTypeInt
case ParameterTypeFloat.String():
*pt = ParameterTypeFloat
case ParameterTypeBool.String():
*pt = ParameterTypeBool
case ParameterTypeFile.String():
*pt = ParameterTypeFile
case ParameterTypeDuration.String():
*pt = ParameterTypeDuration
default:
// it may not be a known parameter type, but we also allow ParameterType(int)
valIntRaw := strings.TrimSuffix(strings.TrimPrefix(string(b), "ParameterType("), ")")
valInt, err := strconv.Atoi(valIntRaw)
if err != nil {
return fmt.Errorf("parameter type %q: %w", b, ErrInvalidParameterType)
}
*pt = ParameterType(valInt)
}

return nil
}
31 changes: 0 additions & 31 deletions config/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,6 @@ func (vt ValidationType) MarshalText() ([]byte, error) {
return []byte(vt.String()), nil
}

func (vt *ValidationType) UnmarshalText(b []byte) error {
if len(b) == 0 {
return nil // empty string, do nothing
}

switch string(b) {
case ValidationTypeRequired.String():
*vt = ValidationTypeRequired
case ValidationTypeGreaterThan.String():
*vt = ValidationTypeGreaterThan
case ValidationTypeLessThan.String():
*vt = ValidationTypeLessThan
case ValidationTypeInclusion.String():
*vt = ValidationTypeInclusion
case ValidationTypeExclusion.String():
*vt = ValidationTypeExclusion
case ValidationTypeRegex.String():
*vt = ValidationTypeRegex
default:
// it may not be a known validation type, but we also allow ValidationType(int)
valIntRaw := strings.TrimSuffix(strings.TrimPrefix(string(b), "ValidationType("), ")")
valInt, err := strconv.Atoi(valIntRaw)
if err != nil {
return fmt.Errorf("validation type %q: %w", b, ErrInvalidValidationType)
}
*vt = ValidationType(valInt)
}

return nil
}

type ValidationRequired struct{}

func (v ValidationRequired) Type() ValidationType { return ValidationTypeRequired }
Expand Down

0 comments on commit e4d9c1a

Please sign in to comment.