You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
578 B
Go
38 lines
578 B
Go
package starmap
|
|
|
|
import "errors"
|
|
|
|
func Get(key string) (interface{}, error) {
|
|
var err error
|
|
kvmu.RLock()
|
|
defer kvmu.RUnlock()
|
|
data, ok := kvMap[key]
|
|
if !ok {
|
|
err = errors.New("key not exists")
|
|
}
|
|
return data, err
|
|
}
|
|
|
|
func Store(key string, value interface{}) error {
|
|
kvmu.Lock()
|
|
defer kvmu.Unlock()
|
|
kvMap[key] = value
|
|
return nil
|
|
}
|
|
|
|
func Delete(key string) error {
|
|
kvmu.Lock()
|
|
defer kvmu.Unlock()
|
|
delete(kvMap, key)
|
|
return nil
|
|
}
|
|
|
|
func Range(run func(k string, v interface{}) bool) error {
|
|
for k, v := range kvMap {
|
|
if !run(k, v) {
|
|
break
|
|
}
|
|
}
|
|
return nil
|
|
}
|