storage.go
package storage
import (
"fmt"
"os"
)
const DEFAULT_STORAGE_ENGINE = "bolt" //默认存储引擎 为 bolt
//存储引擎map集合
var supportedStorage = map[string]func(path string) (Storage, error){
"kv": openKVStorage,
"bolt": openBoltStorage,
}
//存储引擎注册
func RegisterStorageEngine(name string, fn func(path string) (Storage, error)) {
supportedStorage[name] = fn
}
//存储引擎接口
type Storage interface {
Set(k, v []byte) error
Get(k []byte) ([]byte, error)
Delete(k []byte) error
ForEach(fn func(k, v []byte) error) error
Close() error
WALName() string
}
//打开存储引擎 存储引擎 优先使用用户自定的引擎 ,默认引擎为bolt 。如果不存在 使用默认引擎
func OpenStorage(path string) (Storage, error) {
wse := os.Getenv("WUKONG_STORAGE_ENGINE") //默认从环境变量中 加载存储引擎
if wse == "" {
wse = DEFAULT_STORAGE_ENGINE
}
//从引擎map中获取 引擎对象
if fn, has := supportedStorage[wse]; has {
return fn(path)
}
return nil, fmt.Errorf("unsupported storage engine %v", wse)
}
storage.go的更多相关文章
- Azure Queue Storage 基本用法 -- Azure Storage 之 Queue
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure File Storage 基 ...
- Azure File Storage 基本用法 -- Azure Storage 之 File
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure Blob Storage 基 ...
- HTML5_06之拖放API、Worker线程、Storage存储
1.拖放API中源对象与目标对象事件间的数据传递: ①创建全局变量--污染全局对象: var 全局变量=null; src.ondragstart=function(){ 全局变量=数据值; ...
- HTML5权威指南--Web Storage,本地数据库,本地缓存API,Web Sockets API,Geolocation API(简要学习笔记二)
1.Web Storage HTML5除了Canvas元素之外,还有一个非常重要的功能那就是客户端本地保存数据的Web Storage功能. 以前都是用cookies保存用户名等简单信息. 但是c ...
- MySQL报错:Got error 28 from storage engine
今天碰到数据库出错: Got error 28 from storage engine 查了一下,数据库文件所在的盘应该没事,应该是数据库用的临时目录空间不够 问题原因: 磁盘临时空间不够导致. 解决 ...
- Html 5 Web Storage
HTML5 中使用Web Storage 技术进行本地存储,能够在Web 客户端进行数据存储.WebStorage 曾今属于HTML5的规范,目前已经被独立出来形成单独的规范体系.简单来说使用Web本 ...
- Azure Blob Storage 基本用法 -- Azure Storage 之 Blob
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure Table storage ...
- Azure Table storage 基本用法 -- Azure Storage 之 Table
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table,其中的 Table 就是本文的主角 Azure Tabl ...
- Windows Azure Storage (6) Windows Azure Storage之Table
<Windows Azure Platform 系列文章目录> 最近想了想,还是有必要把Windows Azure Table Storage 给说清楚. 1.概念 Windows Azu ...
- [New Portal]Windows Azure Storage (14) 使用Azure Blob的PutBlock方法,实现文件的分块、离线上传
<Windows Azure Platform 系列文章目录> 相关内容 Windows Azure Platform (二十二) Windows Azure Storage Servic ...
随机推荐
- angularjs指令中的compile与link函数详解
这篇文章主要介绍了angularjs指令中的compile与link函数详解,本文同时诉大家complie,pre-link,post-link的用法与区别等内容,需要的朋友可以参考下 通常大家在 ...
- spring boot之入门Controller常用注解
Controller常用注解 @Controller 处理http请求 @RestController Spring4之后新加的注解,原来返回json数据需要@ResponseBody配合@Cont ...
- 排序算法入门之堆排序(Java实现)
堆排序 在学习了二叉堆(优先队列)以后,我们来看看堆排序.堆排序总的运行时间为O(NlonN). 堆的概念 堆是以数组作为存储结构. 可以看出,它们满足以下规律: 设当前元素在数组中以R[i]表示,那 ...
- 轻松解决oracle11g 空表不能exp导出的问题
轻松解决oracle11g 空表不能exp导出的问题 [引用 2012-9-22 18:06:36] 字号:大 中 小 oracle11g的新特性,数据条数是0时不分配segment,所以就不 ...
- jvm栈-运行控制,jvm-堆运行存储共享单元
JVM-栈 2012-09-17 15:43:53 分类: Java 原文转自:http://www.blogjava.net/nkjava/archive/2012/03/15/371971.ht ...
- mysql统计类似SQL语句查询次数
mysql统计类似SQL语句查询次数 vc-mysql-sniffer 工具抓取的sql分析. 1.先用shell脚本把所有enter符号替换为null,再根据语句前后的字符分隔语句 grep -Ev ...
- wave音频格式一窥
学习需要不断的刨根问底,首先,RIFF是微软多媒体格式的一个规范. 其次,有很多用C++实现wave解析的好文章.
- hadoop配置文件详解系列(一)-core-site.xml篇
接上一个属性,这个属性就是设置阈值的. hadoop.security.groups.cache.secs 300 配置用户组映射缓存时间的,当过期时重新获取并缓存. hadoop.security. ...
- vfd电子时钟制作
17年也没干个啥,年后就去折腾着玩意儿了,也不知道我折腾它还是它折腾我.反正总之现在勉强可以交作业了,呵呵 硬件: 1.罗耶振荡电路输出一路4v交流,一路25v交流 其中4v直接驱动灯丝,另一路经电桥 ...
- Ubuntu 下命令安装 Java
1. 使用 java -version 查看系统是否存在 jdk. 2. ubuntu使用的是openjdk,所以我们需要先找到合适的jdk版本.在命令行中输入命令:apt-cache search ...