Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for []int []string []float32 arguments
- Loading branch information
Showing
5 changed files
with
176 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package uniconfig | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type floatslice struct { | ||
data *[]float64 | ||
} | ||
|
||
func NewFloatSlice(data *[]float64) *floatslice { | ||
return &floatslice{data} | ||
} | ||
|
||
func (i *floatslice) String() string { | ||
return fmt.Sprintf("%d", *i.data) | ||
} | ||
|
||
// The second method is Set(value string) error | ||
func (i *floatslice) Set(value string) error { | ||
tmp := []float64{} | ||
res := strings.Split(value, ",") | ||
for _, p := range res { | ||
p1 := strings.TrimSpace(p) | ||
val, err := strconv.ParseFloat(p1, 64) | ||
if err != nil { | ||
return fmt.Errorf("Cannot parse %s as []float64\n", value) | ||
} | ||
|
||
tmp = append(tmp, val) | ||
} | ||
*i.data = tmp | ||
|
||
return nil | ||
} | ||
|
||
var floatSliceType = reflect.TypeOf([]float64{}) | ||
|
||
//func (i *intslice) Set(value string) error { | ||
//tmp, err := strconv.Atoi(value) | ||
//if err != nil { | ||
//*i.data = append(*i.data, -1) | ||
//} else { | ||
//*i.data = append(*i.data, tmp) | ||
//} | ||
//return nil | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package uniconfig | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type intslice struct { | ||
data *[]int | ||
} | ||
|
||
func NewIntSlice(data *[]int) *intslice { | ||
return &intslice{data} | ||
} | ||
|
||
func (i *intslice) String() string { | ||
return fmt.Sprintf("%d", *i.data) | ||
} | ||
|
||
// The second method is Set(value string) error | ||
func (i *intslice) Set(value string) error { | ||
tmp := []int{} | ||
res := strings.Split(value, ",") | ||
for _, p := range res { | ||
p1 := strings.TrimSpace(p) | ||
val, err := strconv.Atoi(p1) | ||
if err != nil { | ||
return fmt.Errorf("Cannot parse %s as []int\n", value) | ||
} | ||
|
||
tmp = append(tmp, val) | ||
} | ||
*i.data = tmp | ||
|
||
return nil | ||
} | ||
|
||
var intSliceType = reflect.TypeOf([]int{}) | ||
|
||
//func (i *intslice) Set(value string) error { | ||
//tmp, err := strconv.Atoi(value) | ||
//if err != nil { | ||
//*i.data = append(*i.data, -1) | ||
//} else { | ||
//*i.data = append(*i.data, tmp) | ||
//} | ||
//return nil | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package uniconfig | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
) | ||
|
||
type strslice struct { | ||
data *[]string | ||
} | ||
|
||
func NewStrSlice(data *[]string) *strslice { | ||
return &strslice{data} | ||
} | ||
|
||
func (i *strslice) String() string { | ||
return fmt.Sprintf("%+v", *i.data) | ||
} | ||
|
||
// The second method is Set(value string) error | ||
func (i *strslice) Set(value string) error { | ||
tmp := []string{} | ||
res := strings.Split(value, ",") | ||
for _, p := range res { | ||
val := strings.TrimSpace(p) | ||
tmp = append(tmp, val) | ||
} | ||
*i.data = tmp | ||
|
||
return nil | ||
} | ||
|
||
var strSliceType = reflect.TypeOf([]string{}) | ||
|
||
//func (i *intslice) Set(value string) error { | ||
//tmp, err := strconv.Atoi(value) | ||
//if err != nil { | ||
//*i.data = append(*i.data, -1) | ||
//} else { | ||
//*i.data = append(*i.data, tmp) | ||
//} | ||
//return nil | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters