ValueToString convert all scalar values to their go string.
(val Value)
| 159 | |
| 160 | // ValueToString convert all scalar values to their go string. |
| 161 | func ValueToString(val Value) (string, bool) { |
| 162 | if val == nil || val.Err() { |
| 163 | return "", false |
| 164 | } |
| 165 | switch v := val.(type) { |
| 166 | case StringValue: |
| 167 | return v.Val(), true |
| 168 | case TimeValue: |
| 169 | return fmt.Sprintf("%v", v.Val()), true |
| 170 | case ByteSliceValue: |
| 171 | return string(v.Val()), true |
| 172 | case NumericValue, BoolValue, IntValue: |
| 173 | return val.ToString(), true |
| 174 | case Slice: |
| 175 | // This is controversial, if we are demanding a "ToString" |
| 176 | // should we: |
| 177 | // 1) take first? |
| 178 | // 2) append comma separated? |
| 179 | // 3) error? |
| 180 | // |
| 181 | // Our answer is that we are demanding a scalar string |
| 182 | // and going to take first. calling function would have had to do type detection |
| 183 | // if they wanted something else. |
| 184 | if v.Len() == 0 { |
| 185 | return "", false |
| 186 | } |
| 187 | v1 := v.SliceValue()[0] |
| 188 | if v1 == nil { |
| 189 | return "", false |
| 190 | } |
| 191 | return v1.ToString(), true |
| 192 | } |
| 193 | return "", false |
| 194 | } |
| 195 | |
| 196 | // ValueToStrings convert all scalar values to their go []string. |
| 197 | func ValueToStrings(val Value) ([]string, bool) { |