File tree 1 file changed +6
-2
lines changed
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ const (
20
20
StyleForm
21
21
)
22
22
23
+ func typeConvert (from , to interface {}) interface {} {
24
+ return reflect .ValueOf (from ).Convert (reflect .TypeOf (to )).Interface ()
25
+ }
26
+
23
27
// Param represents an API operation input parameter.
24
28
type Param struct {
25
29
Type string `json:"type"`
@@ -113,12 +117,12 @@ func (p Param) AddFlag(flags *pflag.FlagSet) interface{} {
113
117
if def == nil {
114
118
def = 0
115
119
}
116
- return flags .Int (name , int (def .( float64 ) ), p .Description )
120
+ return flags .Int (name , typeConvert (def , 0 ).( int ), p .Description )
117
121
case "number" :
118
122
if def == nil {
119
123
def = 0.0
120
124
}
121
- return flags .Float64 (name , def .(float64 ), p .Description )
125
+ return flags .Float64 (name , typeConvert ( def , float64 ( 0.0 )) .(float64 ), p .Description )
122
126
case "string" :
123
127
if def == nil {
124
128
def = ""
You can’t perform that action at this time.
0 commit comments