Documentation ¶
Overview ¶
Example ¶
fmt.Println(PrefixUint32([]byte("id-"), 3))
Output: [105 100 45 3 0 0 0]
Index ¶
- Constants
- func CheckError(err error)
- func Concat(bs ...[]byte) []byte
- func Contains(slice, lambdaOrElement interface{}) bool
- func Decode(bs []byte, obj interface{}) error
- func Encode(obj interface{}) ([]byte, error)
- func Filter(collection, predicate interface{}) (interface{}, error)
- func Includes(array []string, objs ...string) bool
- func Join(sep []byte, bs ...[]byte) []byte
- func Open(uri string) error
- func Parse(data []string, def map[int]string, p interface{}) (map[string]string, error)
- func PrefixBytes(bs []byte, prefix ...byte) []byte
- func PrefixUint32(prefix []byte, num uint32) []byte
- func ReadBuf(path string, read func([]byte)) error
- func ReadLines(file string, read func(string)) (err error)
- func Remove(slice, lambdaOrElement interface{}) int
- func SplitAfter(s string, sep ...string) []string
- func UniqueString(prefix string) string
- func UniqueUint32() uint32
- type Cache
- type ChMap
- func (p ChMap) Close()
- func (p ChMap) Count() int
- func (p ChMap) Get(key interface{}) (interface{}, bool)
- func (p ChMap) Has(key interface{}) bool
- func (p ChMap) Iterator(callBack func(k, v interface{}))
- func (p ChMap) Keys() []interface{}
- func (p ChMap) Put(key, value interface{})
- func (p ChMap) Remove(key interface{})
- type Closer
- type FileID
- type ID
- type IDS
- func (s *IDS) Add(ids ...ID) []ID
- func (s *IDS) Contains(id ID) bool
- func (s *IDS) Delete(ids ...ID) []ID
- func (s *IDS) DeleteIndex(index ...int) []ID
- func (s *IDS) Distinct() []ID
- func (s *IDS) Empty() bool
- func (s *IDS) IndexOf(id ID) int
- func (s *IDS) Intersect(ids ...ID) []ID
- func (s *IDS) Reverse() []ID
- type Result
- type Results
- type StringSlice
Examples ¶
- Package
- ChMap.Iterator
- Concat
- Decode
- Encode
- IDS
- IDS.Add
- IDS.Contains
- IDS.Delete
- IDS.DeleteIndex
- IDS.Distinct
- IDS.Empty
- IDS.IndexOf
- IDS.Intersect
- IDS.Reverse
- Join
- NewChMap
- NewID
- PrefixBytes
- PrefixUint32
- ReadLines
- SplitAfter
- StringSlice
- StringSlice.Add
- StringSlice.Contains
- StringSlice.Delete
- StringSlice.IndexOf
- UniqueString
- UniqueUint32
Constants ¶
const IDSplitByte = '-'
IDSplitByte split byte
Variables ¶
This section is empty.
Functions ¶
func Concat ¶
Concat bytes.
Example ¶
a := []byte("aa") b := []byte("bb") fmt.Println(Concat(a, b))
Output: [97 97 98 98]
func Contains ¶
func Contains(slice, lambdaOrElement interface{}) bool
Contains is element contains by lambda or element
func Decode ¶
Decode is bytes to obj.
Example ¶
var str string Decode([]byte{5, 12, 0, 2, 'a', 'b'}, &str) fmt.Println(str)
Output: ab
func Encode ¶
Encode is obj to bytes.
Example ¶
bs, _ := Encode("ab") fmt.Printf("%x\n", bs)
Output: 050c00026162
func Join ¶
Join bytes.
Example ¶
a := []byte("aa") b := []byte("bb") fmt.Println(Join([]byte(","), a, b))
Output: [97 97 44 98 98]
func PrefixBytes ¶
PrefixBytes is prefix add bytes to bytes.
Example ¶
fmt.Println(PrefixBytes([]byte("abc"), 'i', 'd', '-'))
Output: [105 100 45 97 98 99]
func PrefixUint32 ¶
PrefixUint32 is prefix add uint32 to bytes.
Example ¶
fmt.Println(PrefixUint32([]byte("id-"), 3))
Output: [105 100 45 3 0 0 0]
func ReadLines ¶
ReadLines read file.
Example ¶
if err := ReadLines("LICENSE", func(line string) { fmt.Print(line) }); err != nil { fmt.Println(err) }
Output:
func Remove ¶
func Remove(slice, lambdaOrElement interface{}) int
Remove element by lambda or element
func SplitAfter ¶
SplitAfter is plus of strings.SplitAfter.
Example ¶
fmt.Println(SplitAfter("110120119129", "0", "9"))
Output: [110 120 119 129]
func UniqueString ¶
UniqueString 程序运行期间生成不重复的字符串.
Example ¶
fmt.Println(UniqueString("U-")) fmt.Println(UniqueString("K-")) fmt.Println(UniqueString("K-"))
Output: U-1 K-2 K-3
func UniqueUint32 ¶
func UniqueUint32() uint32
UniqueUint32 程序运行期间生成不重复的uint32.
Example ¶
fmt.Println(UniqueUint32()) fmt.Println(UniqueUint32())
Output: 4 5
Types ¶
type ChMap ¶
type ChMap struct {
// contains filtered or unexported fields
}
ChMap is channel map.
func NewChMap ¶
func NewChMap() ChMap
NewChMap new ChMap.
Example ¶
chMap := NewChMap() defer chMap.Close() chMap.Put("key", "value") fmt.Println(chMap.Count()) v, ok := chMap.Get("key") fmt.Println(v, ok) fmt.Println(chMap.Has("key")) fmt.Println(chMap.Has("no key"))
Output: 1 value true true false
type FileID ¶
type FileID struct { Size int64 // contains filtered or unexported fields }
FileID file ID.
type ID ¶
type ID [18]byte
ID is unique primary key
func NewID ¶
NewID is new ID
Example ¶
fmt.Println(ID{}.IsNew()) id := NewID('A') fmt.Println(id.IsNew())
Output: true false
func (*ID) UnmarshalJSON ¶
UnmarshalJSON is json Unmarshal
type IDS ¶
type IDS []ID
IDS is ID slice.
Example ¶
ids := IDS{} ids.Add(NewID('A')) fmt.Println(len(ids))
Output: 1
func (*IDS) Add ¶
Add push ids to ID slice.
Example ¶
ids := IDS{} ids.Add(NewID('A'), NewID('A')) fmt.Println(len(ids))
Output: 2
func (*IDS) Contains ¶
Contains returns true if id is found, else false.
Example ¶
ids := IDS{} id := NewID('K') ids.Add(NewID('A'), NewID('A')) ids.Add(id) fmt.Println(ids.Contains(id)) fmt.Println(ids.Contains(NewID('A')))
Output: true false
func (*IDS) Delete ¶
Delete removes all occurrences of ids in the ID slice.
Example ¶
ids := IDS{} id := NewID('K') ids.Add(NewID('A'), NewID('A')) ids.Add(id) fmt.Println(len(ids)) fmt.Println(ids.Contains(id)) fmt.Println(len(ids.Delete(id))) fmt.Println(ids.Contains(id))
Output: 3 true 2 false
func (*IDS) DeleteIndex ¶
DeleteIndex removes all occurrences of index in the ID slice.
Example ¶
ids := IDS{} id := NewID('K') ids.Add(NewID('A'), NewID('A')) ids.Add(id) fmt.Println(len(ids)) fmt.Println(ids.Contains(id)) fmt.Println(len(ids.DeleteIndex(1, 2))) fmt.Println(ids.Contains(id))
Output: 3 true 1 false
func (*IDS) Distinct ¶
Distinct returns the new duplicate free slice.
Example ¶
ids := IDS{} id := NewID('A') ids.Add(NewID('A'), NewID('A')) ids.Add(id) ids.Add(NewID('A'), NewID('A'), NewID('A'), NewID('A')) ids.Add(id) fmt.Println(len(ids)) ids.Distinct() fmt.Println(len(ids)) fmt.Println(ids[2] == id)
Output: 8 7 true
func (*IDS) Empty ¶
Empty returns true if ID slice is empty, else false.
Example ¶
ids := IDS{} fmt.Println(ids.Empty()) ids.Add(NewID('A')) fmt.Println(ids.Empty())
Output: true false
func (*IDS) IndexOf ¶
IndexOf returns the index of the matched id, else -1.
Example ¶
ids := IDS{} id := NewID('K') ids.Add(NewID('A'), NewID('A')) ids.Add(id) fmt.Println(ids.IndexOf(id))
Output: 2
type StringSlice ¶
type StringSlice []string
StringSlice string slice
Example ¶
ss := StringSlice([]string{"123", "234", "234"}) fmt.Println(ss.Delete("234")) fmt.Println(ss)
Output: [123] [123]
func (*StringSlice) Add ¶
func (ss *StringSlice) Add(vals ...string) []string
Add adds all elements of vals in the slice.
Example ¶
ss := StringSlice([]string{"123"}) fmt.Println(ss.Add("234", "345")) fmt.Println(ss)
Output: [123 234 345] [123 234 345]
func (StringSlice) Contains ¶
func (ss StringSlice) Contains(val string) bool
Contains returns true if val is found, else false.
Example ¶
ss := StringSlice([]string{"123", "234"}) fmt.Println(ss.Contains("234")) fmt.Println(ss.Contains("345"))
Output: true false
func (*StringSlice) Delete ¶
func (ss *StringSlice) Delete(vals ...string) []string
Delete removes all occurrences of vals in the slice.
Example ¶
ss := StringSlice([]string{"123", "234", "234"}) fmt.Println(ss.Delete("345")) fmt.Println(ss.Delete("234")) fmt.Println(ss)
Output: [123 234 234] [123] [123]