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


Golang C.leveldb_open函數代碼示例

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


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

示例1: Open

// Open opens a database.
//
// Creating a new database is done by calling SetCreateIfMissing(true) on the
// *Options passed to Open.
//
// It is usually wise to set a Cache object on the *Options with SetCache() to
// keep recently used data from that database in memory.
func Open(dbname string, o *Options) (*DB, error) {
	var errStr *C.char
	ldbname := C.CString(dbname)
	defer C.free(unsafe.Pointer(ldbname))

	leveldb := C.leveldb_open(o.Opt, ldbname, &errStr)
	if errStr != nil {
		return nil, DatabaseError(C.GoString(errStr))
	}
	return &DB{leveldb}, nil
}
開發者ID:andradeandrey,項目名稱:levigo,代碼行數:18,代碼來源:db.go

示例2: Open

func Open(name string, options *Options) (*Db, error) {
	var db_err *C.char

	db_name := C.CString(name)
	defer C.free(unsafe.Pointer(db_name))

	ldb := C.leveldb_open(options.options, db_name, &db_err)
	if ldb == nil {
		return nil, ldb_error(C.GoString(db_err))
	}

	return &Db{ldb}, nil
}
開發者ID:monadbobo,項目名稱:agent_leveldb,代碼行數:13,代碼來源:leveldb.go

示例3: open

func (db *DB) open() error {
	db.initOptions(db.cfg)

	var errStr *C.char
	ldbname := C.CString(db.path)
	defer C.leveldb_free(unsafe.Pointer(ldbname))

	db.db = C.leveldb_open(db.opts.Opt, ldbname, &errStr)
	if errStr != nil {
		db.db = nil
		return saveError(errStr)
	}
	return nil
}
開發者ID:huanshi,項目名稱:ledisdb,代碼行數:14,代碼來源:db.go

示例4: Open

func Open(path string) (*LevelDB, error) {
	var err *C.char
	db := &LevelDB{}
	db.dbOpts = &DBOptions{C.leveldb_options_create()}
	db.readOpts = &ReadOptions{C.leveldb_readoptions_create()}
	db.writeOpts = &WriteOptions{C.leveldb_writeoptions_create()}

	C.leveldb_options_set_create_if_missing(db.dbOpts.Opts, 1)
	db.db = C.leveldb_open(db.dbOpts.Opts, C.CString(path), &err)
	if db.db == nil {
		e := &DBError{}
		e.Err = "Open db failed"
		return nil, e
	}
	if err != nil {
		e := &DBError{}
		e.Err = C.GoString(err)
		return db, e
	}
	return db, nil
}
開發者ID:shafreeck,項目名稱:hermes,代碼行數:21,代碼來源:db.go

示例5: OpenLeveldb

func OpenLeveldb(dir string) (*Leveldb, error) {
	options := C.leveldb_options_create()
	C.leveldb_options_set_create_if_missing(options, C.uchar(1))
	cache := C.leveldb_cache_create_lru(levelCacheCap)
	C.leveldb_options_set_cache(options, cache)
	cDir := C.CString(dir)
	defer C.free(unsafe.Pointer(cDir))
	var err *C.char
	db := C.leveldb_open(options, cDir, &err)
	if err != nil {
		return nil, errors.New(fmt.Sprintf("%s: %s", err, dir))
	}
	C.leveldb_free(unsafe.Pointer(err))
	err = nil
	leveldb := &Leveldb{
		cdb:           db,
		read_options:  C.leveldb_readoptions_create(),
		write_options: C.leveldb_writeoptions_create(),
		cache:         cache,
	}
	return leveldb, nil
}
開發者ID:reusee,項目名稱:obox,代碼行數:22,代碼來源:leveldb.go

示例6: OpenLevelDB

// Open LevelDB with given name
func OpenLevelDB(path string) (leveldb *LevelDB, err error) {

	cpath := C.CString(path) // convert path to c string
	defer C.leveldb_free(unsafe.Pointer(cpath))

	// allocate LevelDB Option struct to open
	opt := C.leveldb_options_create()
	defer C.leveldb_free(unsafe.Pointer(opt))

	// set open option
	C.leveldb_options_set_create_if_missing(opt, C.uchar(1))

	// open leveldb
	var cerr *C.char
	cleveldb := C.leveldb_open(opt, cpath, &cerr)

	if cerr != nil {
		defer C.leveldb_free(unsafe.Pointer(cerr))
		return nil, errors.New(C.GoString(cerr))
	}

	return &LevelDB{cleveldb, path}, nil
}
開發者ID:OktayGardener,項目名稱:Computer-Science-CalPoly,代碼行數:24,代碼來源:leveldb.go


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