forked from rai-project/dlframework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_parameter.go
62 lines (56 loc) · 1.48 KB
/
type_parameter.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
package dlframework
import (
"errors"
"fmt"
"strings"
"github.com/spf13/cast"
)
func (param *ModelManifest_Type_Parameter) MarshalYAML() (interface{}, error) {
return cast.ToStringE(param.Value)
}
func (param *ModelManifest_Type_Parameter) UnmarshalYAML(unmarshal func(interface{}) error) error {
toListString := func(v interface{}) string {
return fmt.Sprintf("[%s]", strings.Join(cast.ToStringSlice(v), ","))
}
var stringSlice []string
if err := unmarshal(&stringSlice); err == nil {
param.Value = toListString(stringSlice)
return nil
}
var int32Slice []int32
if err := unmarshal(&int32Slice); err == nil {
param.Value = toListString(int32Slice)
return nil
}
var float32Slice []float32
if err := unmarshal(&float32Slice); err == nil {
param.Value = toListString(float32Slice)
return nil
}
var int32Value []int32
if err := unmarshal(&int32Value); err == nil {
param.Value = cast.ToString(int32Value)
return nil
}
var int64Value []int64
if err := unmarshal(&int64Value); err == nil {
param.Value = cast.ToString(int64Value)
return nil
}
var float32Value []float32
if err := unmarshal(&float32Value); err == nil {
param.Value = cast.ToString(int32Value)
return nil
}
var float64Value []float64
if err := unmarshal(&float64Value); err == nil {
param.Value = cast.ToString(float64Value)
return nil
}
var str string
if err := unmarshal(&str); err == nil {
param.Value = str
return nil
}
return errors.New("unable to unmarshal model type parameter")
}