aboutsummaryrefslogtreecommitdiff
path: root/int64_slice.go
diff options
context:
space:
mode:
authorMitch Connors <[email protected]>2019-09-17 09:43:30 -0700
committerGitHub <[email protected]>2019-09-17 09:43:30 -0700
commit7b22f689a41a1727c42eb02aaa1492d26402c592 (patch)
treeca8ae6c13649d5a76f09cd8c7a4ca5011c870c85 /int64_slice.go
parent972238283c0625cf3e881de7699ba8f2524c340a (diff)
parent8e39cc44d9bd06ee2d9ef3109c93809072d5e551 (diff)
Merge pull request #216 from therealmitchconnors/elegant
Implement SliceValue for better list semantics
Diffstat (limited to 'int64_slice.go')
-rw-r--r--int64_slice.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/int64_slice.go b/int64_slice.go
index 86cb619..2546463 100644
--- a/int64_slice.go
+++ b/int64_slice.go
@@ -51,6 +51,44 @@ func (s *int64SliceValue) String() string {
return "[" + strings.Join(out, ",") + "]"
}
+func (s *int64SliceValue) fromString(val string) (int64, error) {
+ return strconv.ParseInt(val, 0, 64)
+}
+
+func (s *int64SliceValue) toString(val int64) string {
+ return fmt.Sprintf("%d", val)
+}
+
+func (s *int64SliceValue) Append(val string) error {
+ i, err := s.fromString(val)
+ if err != nil {
+ return err
+ }
+ *s.value = append(*s.value, i)
+ return nil
+}
+
+func (s *int64SliceValue) Replace(val []string) error {
+ out := make([]int64, len(val))
+ for i, d := range val {
+ var err error
+ out[i], err = s.fromString(d)
+ if err != nil {
+ return err
+ }
+ }
+ *s.value = out
+ return nil
+}
+
+func (s *int64SliceValue) GetSlice() []string {
+ out := make([]string, len(*s.value))
+ for i, d := range *s.value {
+ out[i] = s.toString(d)
+ }
+ return out
+}
+
func int64SliceConv(val string) (interface{}, error) {
val = strings.Trim(val, "[]")
// Empty string would cause a slice with one (empty) entry