コード例 #1
0
// NewCache creates a new Cache object.
func NewCache(
	expiry time.Duration,
	constructor func(string) (interface{}, error),
	destructor func(interface{})) *Cache {
	return &Cache{
		lastUsedMap: treemap.NewWith(int64Comparator),
		expiry:      expiry,
		constructor: constructor,
		destructor:  destructor,
		data:        make(map[string]*cacheEntry),
	}
}
コード例 #2
0
ファイル: Lab3Client.go プロジェクト: PulkitD93/cmpe273-lab3
	"net/http"
	"strings"
)

type KeyValue struct {
	Key   int    `json:"key"`
	Value string `json:"value"`
}

type GetAllKeysRes []KeyValue

type PutKeyValueResponse struct {
	Message string `json:"message"`
}

var circle *treemap.Map = treemap.NewWith(UInt64Comparator)

func main() {

	addToCircle("http://localhost:3000/keys")
	addToCircle("http://localhost:3001/keys")
	addToCircle("http://localhost:3002/keys")

	mux := httprouter.New()
	mux.PUT("/keys/:key_id/:value", storeKeyValue)
	mux.GET("/keys/:key_id", getKeyValue)
	server := http.Server{
		Addr:    "0.0.0.0:8080",
		Handler: mux,
	}
	server.ListenAndServe()