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的更多相关文章

  1. Azure Queue Storage 基本用法 -- Azure Storage 之 Queue

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure File Storage 基 ...

  2. Azure File Storage 基本用法 -- Azure Storage 之 File

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure Blob Storage 基 ...

  3. HTML5_06之拖放API、Worker线程、Storage存储

    1.拖放API中源对象与目标对象事件间的数据传递: ①创建全局变量--污染全局对象:  var 全局变量=null;  src.ondragstart=function(){   全局变量=数据值;  ...

  4. HTML5权威指南--Web Storage,本地数据库,本地缓存API,Web Sockets API,Geolocation API(简要学习笔记二)

    1.Web Storage HTML5除了Canvas元素之外,还有一个非常重要的功能那就是客户端本地保存数据的Web Storage功能. 以前都是用cookies保存用户名等简单信息.   但是c ...

  5. MySQL报错:Got error 28 from storage engine

    今天碰到数据库出错: Got error 28 from storage engine 查了一下,数据库文件所在的盘应该没事,应该是数据库用的临时目录空间不够 问题原因: 磁盘临时空间不够导致. 解决 ...

  6. Html 5 Web Storage

    HTML5 中使用Web Storage 技术进行本地存储,能够在Web 客户端进行数据存储.WebStorage 曾今属于HTML5的规范,目前已经被独立出来形成单独的规范体系.简单来说使用Web本 ...

  7. Azure Blob Storage 基本用法 -- Azure Storage 之 Blob

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure Table storage ...

  8. Azure Table storage 基本用法 -- Azure Storage 之 Table

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table,其中的 Table 就是本文的主角 Azure Tabl ...

  9. Windows Azure Storage (6) Windows Azure Storage之Table

    <Windows Azure Platform 系列文章目录> 最近想了想,还是有必要把Windows Azure Table Storage 给说清楚. 1.概念 Windows Azu ...

  10. [New Portal]Windows Azure Storage (14) 使用Azure Blob的PutBlock方法,实现文件的分块、离线上传

    <Windows Azure Platform 系列文章目录> 相关内容 Windows Azure Platform (二十二) Windows Azure Storage Servic ...

随机推荐

  1. 阿里云安装配置mysql(centos版)

    这种是利用yum下载的也可以使用xftp上传 1,安装mysql数据库 a)下载mysql源安装包:wget http://dev.mysql.com/get/mysql57-community-re ...

  2. Java 学习资料整理

    Java 学习资料整理 Java 精品学习视频教程下载汇总 Java视频教程 孙鑫Java无难事 (全12CD) Java视频教程 即学即会java 上海交大 Java初级编程基础 共25讲下载 av ...

  3. (转)Go语言并发模型:使用 context

    转载自:https://segmentfault.com/a/1190000006744213 context golang 简介 在 Go http包的Server中,每一个请求在都有一个对应的 g ...

  4. python---内置函数,匿名函数,嵌套函数,高阶函数,序列化

    函数简单说明 # 函数即"变量" # 高阶函数 # a.把一个函数名当做实参传给另一个函数(在不修改被装饰函数的源代码的情况下,为其添加功能) # b.返回值中包含函数名(不修改函 ...

  5. 线上Django项目python2到3升级日记

    这两天干了一个几斤疯狂的事情,花不到一个工作日的时间把一个线上Django项目语言版本从python2升级到Python31.字典的一个语法变化 Python2.7: if dict1.haskey( ...

  6. SAE提供服务分析

    这个分析列表主要关注两个问题,服务能做什么,移植实现难度. AppConfig: 这个东西主要面向SAE本身的一些配置选项,移植时放弃这个东西,所以就不谈难度了Counter :这个东西提供某个操作的 ...

  7. Python中urllib.urlencode中文字符的一个问题

    Django项目在访问Restful service时调用urllib.urlencode编码中文字符串时碰到下面这个错误. v = quote_plus(str(v)) UnicodeEncodeE ...

  8. api大全

    免费api大全(更新中) API大全  http://www.apidq.com/    (这个碉堡了) 天气接口 气象局接口 完整数据:http://m.weather.com.cn/data/10 ...

  9. 条件随机场CRF(二) 前向后向算法评估标记序列概率

    条件随机场CRF(一)从随机场到线性链条件随机场 条件随机场CRF(二) 前向后向算法评估标记序列概率 条件随机场CRF(三) 模型学习与维特比算法解码 在条件随机场CRF(一)中我们总结了CRF的模 ...

  10. Robot framework(RF) Builti,Screenshot和Collections标准库介绍

    1.1  Builti标准类库 在学习一门编程语言的时候,大多教材都是从打印“hello world”开始.我们可以像编程语言一样来学习Robot Framework.虽然通过RIDE 提供“填表”一 ...