An open API service indexing awesome lists of open source software.

https://github.com/xuender/toolkit

golang toolkit
https://github.com/xuender/toolkit

Last synced: 2 months ago
JSON representation

golang toolkit

Awesome Lists containing this project

README

        

# toolkit

golang toolkit.

## Usage

### Cache
```go
package main

import (
"fmt"
"time"

"github.com/xuender/toolkit"
)

func main() {
// LRU
cache := toolkit.NewCache(time.Second*3, true)
cache.Set("key1", "value1")
cache.SetByDuration("key2", "value2", time.Second)
cache.Set("key3", "value3")

fmt.Println("init size:", cache.Size())
time.Sleep(time.Second * 2)
cache.Get("key3") // reset expire time.
fmt.Println("2 Second:", cache.Size())
time.Sleep(time.Second * 2)
fmt.Println("4 Second:", cache.Size())
}
```

### SyncMap
```go
package main

import (
"fmt"

"github.com/xuender/toolkit"
)

func main() {
m := toolkit.NewSyncMap()
m.Set("key1", "value1")
m.Set("key2", "value2")

fmt.Println(m.Get("key1"))
fmt.Println(m.Size())
}
```

### ChMap
```go
package main

import (
"fmt"

"github.com/xuender/toolkit"
)

func main() {
m:= toolkit.NewChMap()
defer m.Close()
m.Set("key1", "value1")
m.Set("key2", "value2")

fmt.Println(m.Get("key1"))
fmt.Println(m.Size())
}
```