kraken

package module
v0.0.0-...-0b0b2d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

README

kraken

Kraken project is golang extensions library

Code Example
package main

import (
	"fmt"
	"time"
	"math/rand"
	"github.com/koomox/kraken/cache"
	"github.com/koomox/kraken/uuid"
)

func main() {
	rand.Seed(time.Now().UnixNano())
	store := cache.NewWithStringComparator()
	var elements []string
	for i := 0; i < 10; i++ {
		elements = append(elements, uuid.NewUUID())
	}
	for k, v := range elements {
		store.Put(fmt.Sprintf("%v", k), v, 60 * time.Second)
	}
	store.Put("name", "kraken", 60 * time.Second)
	store.Remove("1")
	ids := []string{"name", "1", fmt.Sprintf("%v", rand.Intn(len(elements)))}
	for _, id := range ids {
		if v := store.Get(id); v != nil {
			fmt.Println(v.(string))
		}
	}
	store.CallbackFunc(func(v interface{}){
		if v != nil {
			fmt.Println(v.(string))
		}
	})
	store.CancelFunc(func(v interface{}) bool {
		if v != nil {
			if (v.(string) == "kraken") {
				fmt.Println(v.(string))
				return true
			}
		}
		return false
	})
	b, err := store.ToJSON()
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(string(b))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Put(interface{}, interface{}, time.Duration)
	Get(interface{}) interface{}
	Remove(interface{})
	GetWithExpire(interface{}) (interface{}, time.Time)
	Values() []interface{}
	ToJSON() ([]byte, error)
	CallbackFunc(func(interface{}))
	CancelFunc(func(interface{}) bool)
}

type Tree

type Tree interface {
	Put(interface{}, interface{})
	Get(interface{}) interface{}
	Remove(interface{})
	Cleanup()
	Values() []interface{}
	ToJSON() ([]byte, error)
	CallbackFunc(func(interface{}))
	CancelFunc(func(interface{}) bool)
}

Directories

Path Synopsis
Package redblacktree implements a red-black tree.
Package redblacktree implements a red-black tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL