當前位置: 首頁>>代碼示例>>Golang>>正文


Golang kvstore.KVStore類代碼示例

本文整理匯總了Golang中github.com/xtracdev/xavi/kvstore.KVStore的典型用法代碼示例。如果您正苦於以下問題:Golang KVStore類的具體用法?Golang KVStore怎麽用?Golang KVStore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了KVStore類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Store

//Store persists the listener defintions in the supplied key value store
func (listenerConfig *ListenerConfig) Store(kvs kvstore.KVStore) (err error) {
	b, err := json.Marshal(listenerConfig)
	if err != nil {
		return err
	}

	key := fmt.Sprintf("listeners/%s", listenerConfig.Name)
	log.Info(fmt.Sprintf("adding %s under key %s", string(b), key))
	err = kvs.Put(key, b)
	return
}
開發者ID:xtracdev,項目名稱:xavi,代碼行數:12,代碼來源:listenercfg.go

示例2: ListListenerConfigs

//ListListenerConfigs retrieves the listener defs from the KVS
func ListListenerConfigs(kvs kvstore.KVStore) ([]*ListenerConfig, error) {
	pairs, err := kvs.List("listeners/")
	if err != nil {
		return nil, err
	}

	var listeners []*ListenerConfig
	for _, p := range pairs {
		listeners = append(listeners, JSONToListener(p.Value))
	}

	return listeners, nil
}
開發者ID:xtracdev,項目名稱:xavi,代碼行數:14,代碼來源:listenercfg.go

示例3: ListBackendConfigs

//ListBackendConfigs lists the backend definitions present in the supplied KVS
func ListBackendConfigs(kvs kvstore.KVStore) ([]*BackendConfig, error) {
	pairs, err := kvs.List("backends/")
	if err != nil {
		return nil, err
	}

	var backends []*BackendConfig
	for _, p := range pairs {
		backends = append(backends, JSONToBackend(p.Value))
	}

	return backends, nil
}
開發者ID:xtracdev,項目名稱:xavi,代碼行數:14,代碼來源:backendcfg.go

示例4: ListRouteConfigs

//ListRouteConfigs returns the route configs in the key value store
func ListRouteConfigs(kvs kvstore.KVStore) ([]*RouteConfig, error) {
	pairs, err := kvs.List("routes/")
	if err != nil {
		return nil, err
	}

	var routes []*RouteConfig
	for _, p := range pairs {
		routes = append(routes, JSONToRoute(p.Value))
	}

	return routes, nil
}
開發者ID:xtracdev,項目名稱:xavi,代碼行數:14,代碼來源:routecfg.go

示例5: Store

//Store persists a backend definition using the supplied key value store
func (backendConfig *BackendConfig) Store(kvs kvstore.KVStore) error {
	b, err := json.Marshal(backendConfig)
	if err != nil {
		return err
	}

	key := fmt.Sprintf("backends/%s", backendConfig.Name)
	log.Info(fmt.Sprintf("Adding %s under key %s", string(b), key))
	err = kvs.Put(key, b)
	if err != nil {
		return err
	}

	return nil
}
開發者ID:xtracdev,項目名稱:xavi,代碼行數:16,代碼來源:backendcfg.go

示例6: Store

//Store persists the route definition using the supplied KVS
func (routeConfig *RouteConfig) Store(kvs kvstore.KVStore) error {
	b, err := json.Marshal(routeConfig)
	if err != nil {
		return nil
	}

	key := fmt.Sprintf("routes/%s", routeConfig.Name)
	log.Info(fmt.Sprintf("adding %s under key %s", string(b), key))
	err = kvs.Put(key, b)
	if err != nil {
		return err
	}

	return nil
}
開發者ID:xtracdev,項目名稱:xavi,代碼行數:16,代碼來源:routecfg.go

示例7: PutDefinition

//PutDefinition creates or updates a server definition
func (ServerDef) PutDefinition(kvs kvstore.KVStore, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
	body, err := ioutil.ReadAll(req.Body)
	req.Body.Close()
	log.Info(fmt.Sprintf("Put request with payload %s", string(body)))
	if err != nil {
		resp.WriteHeader(http.StatusInternalServerError)
		return nil, nil
	}

	serverName := resourceIDFromURI(req.RequestURI)
	log.Info(serverName)
	if serverName == "" {
		resp.WriteHeader(http.StatusNotFound)
		return nil, errServiceResourceMissing
	}

	serverConfig := new(config.ServerConfig)
	err = json.Unmarshal(body, serverConfig)
	if err != nil {
		log.Warn("Error unmarshaling request body")
		resp.WriteHeader(http.StatusBadRequest)
		return nil, err
	}

	serverConfig.Name = serverName
	err = serverConfig.Store(kvs)
	if err != nil {
		log.Warn("Error persisting server definition")
		resp.WriteHeader(http.StatusInternalServerError)
		return nil, err
	}

	err = kvs.Flush()
	if err != nil {
		return nil, err
	}

	return nil, nil
}
開發者ID:xtracdev,項目名稱:xavi,代碼行數:40,代碼來源:server_endpoint.go

示例8: readKey

func readKey(key string, kvs kvstore.KVStore) ([]byte, error) {
	log.Info("Read key " + key)
	return kvs.Get(key)
}
開發者ID:xtracdev,項目名稱:xavi,代碼行數:4,代碼來源:config.go


注:本文中的github.com/xtracdev/xavi/kvstore.KVStore類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。