-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy patharray.go
More file actions
42 lines (32 loc) · 668 Bytes
/
array.go
File metadata and controls
42 lines (32 loc) · 668 Bytes
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
package jsongo
import (
"reflect"
"errors"
"fmt"
)
type A []interface{}
func Array() *A {
return &A{}
}
func (this *A) Put(value interface{}) *A {
*this = append(*this, value)
return this
}
func (this *A) Indent() string {
return indent(this)
}
func (this *A) String() string {
return _string(this)
}
func (this *A) Size() int {
return len(*this)
}
func (this *A) OfString() (values []string, err error) {
for _, value := range *this {
if reflect.TypeOf(value).String() != "string" {
return nil, errors.New(fmt.Sprintf("Value is %s, not a string.", reflect.TypeOf(value)))
}
values = append(values, value.(string))
}
return values, nil
}