forked from eaciit/crowd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.go
46 lines (37 loc) · 827 Bytes
/
base.go
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
43
44
45
46
package crowd
import (
"errors"
"github.com/eaciit/toolkit"
)
type ICrowd interface {
}
type SliceBase struct {
data interface{}
}
func (s *SliceBase) SetData(data interface{}) error {
if !toolkit.IsPointer(data) || !toolkit.IsSlice(data) {
return errors.New("crowd.SliceBase.SetData: data is not pointer of slice")
}
s.data = data
return nil
}
func (s *SliceBase) GetData() interface{} {
if s.data != nil {
return s.data
} else {
return nil
}
}
func (s *SliceBase) Item(i int) interface{} {
return toolkit.SliceItem(s.data, i)
}
func (s *SliceBase) Len() int {
return toolkit.SliceLen(s.data)
}
func (s *SliceBase) Set(i int, d interface{}) error {
e := toolkit.SliceSetItem(s.data, i, d)
if e != nil {
return errors.New(toolkit.Sprintf("SliceBase.Set: [%d] %s", i, e.Error()))
}
return nil
}