• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang errors.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/syndtr/goleveldb/leveldb/errors.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Write

func (x singleWriter) Write(p []byte) (int, error) {
	w := x.w
	if w.seq != x.seq {
		return 0, errors.New("leveldb/journal: stale writer")
	}
	if w.err != nil {
		return 0, w.err
	}
	n0 := len(p)
	for len(p) > 0 {
		// Write a block, if it is full.
		if w.j == blockSize {
			w.fillHeader(false)
			w.writeBlock()
			if w.err != nil {
				return 0, w.err
			}
			w.first = false
		}
		// Copy bytes into the buffer.
		n := copy(w.buf[w.j:], p)
		w.j += n
		p = p[n:]
	}
	return n0, nil
}
开发者ID:lessos,项目名称:lessdb,代码行数:26,代码来源:journal.go


示例2: readBlockCached

func (r *Reader) readBlockCached(bh blockHandle, verifyChecksum, fillCache bool) (*block, util.Releaser, error) {
	if r.cache != nil {
		var err error
		ch := r.cache.Get(bh.offset, func() (charge int, value interface{}) {
			if !fillCache {
				return 0, nil
			}
			var b *block
			b, err = r.readBlock(bh, verifyChecksum)
			if err != nil {
				return 0, nil
			}
			return cap(b.data), b
		})
		if ch != nil {
			b, ok := ch.Value().(*block)
			if !ok {
				ch.Release()
				return nil, nil, errors.New("leveldb/table: inconsistent block type")
			}
			return b, ch, err
		} else if err != nil {
			return nil, nil, err
		}
	}

	b, err := r.readBlock(bh, verifyChecksum)
	return b, b, err
}
开发者ID:ericcapricorn,项目名称:syncthing,代码行数:29,代码来源:reader.go


示例3: ReadByte

func (x *singleReader) ReadByte() (byte, error) {
	r := x.r
	if r.seq != x.seq {
		return 0, errors.New("leveldb/journal: stale reader")
	}
	if x.err != nil {
		return 0, x.err
	}
	if r.err != nil {
		return 0, r.err
	}
	for r.i == r.j {
		if r.last {
			return 0, io.EOF
		}
		x.err = r.nextChunk(false)
		if x.err != nil {
			if x.err == errSkip {
				x.err = io.ErrUnexpectedEOF
			}
			return 0, x.err
		}
	}
	c := r.buf[r.i]
	r.i++
	return c, nil
}
开发者ID:lessos,项目名称:lessdb,代码行数:27,代码来源:journal.go


示例4: upgradeViaRest

func upgradeViaRest() error {
	cfg, err := config.Load(locations[locConfigFile], protocol.LocalDeviceID)
	if err != nil {
		return err
	}
	target := cfg.GUI().URL()
	r, _ := http.NewRequest("POST", target+"/rest/system/upgrade", nil)
	r.Header.Set("X-API-Key", cfg.GUI().APIKey())

	tr := &http.Transport{
		Dial:            dialer.Dial,
		Proxy:           http.ProxyFromEnvironment,
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	client := &http.Client{
		Transport: tr,
		Timeout:   60 * time.Second,
	}
	resp, err := client.Do(r)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		bs, err := ioutil.ReadAll(resp.Body)
		defer resp.Body.Close()
		if err != nil {
			return err
		}
		return errors.New(string(bs))
	}

	return err
}
开发者ID:acogdev,项目名称:syncthing,代码行数:33,代码来源:main.go


示例5: Read

func (x *singleReader) Read(p []byte) (int, error) {
	r := x.r
	if r.seq != x.seq {
		return 0, errors.New("leveldb/journal: stale reader")
	}
	if x.err != nil {
		return 0, x.err
	}
	if r.err != nil {
		return 0, r.err
	}
	for r.i == r.j {
		if r.last {
			return 0, io.EOF
		}
		x.err = r.nextChunk(false)
		if x.err != nil {
			if x.err == errSkip {
				x.err = io.ErrUnexpectedEOF
			}
			return 0, x.err
		}
	}
	n := copy(p, r.buf[r.i:r.j])
	r.i += n
	return n, nil
}
开发者ID:lessos,项目名称:lessdb,代码行数:27,代码来源:journal.go


示例6: readFilterBlockCached

func (r *Reader) readFilterBlockCached(bh blockHandle, fillCache bool) (*filterBlock, util.Releaser, error) {
	if r.cache != nil {
		var (
			err error
			ch  *cache.Handle
		)
		if fillCache {
			ch = r.cache.Get(bh.offset, func() (size int, value cache.Value) {
				var b *filterBlock
				b, err = r.readFilterBlock(bh)
				if err != nil {
					return 0, nil
				}
				return cap(b.data), b
			})
		} else {
			ch = r.cache.Get(bh.offset, nil)
		}
		if ch != nil {
			b, ok := ch.Value().(*filterBlock)
			if !ok {
				ch.Release()
				return nil, nil, errors.New("leveldb/table: inconsistent block type")
			}
			return b, ch, err
		} else if err != nil {
			return nil, nil, err
		}
	}

	b, err := r.readFilterBlock(bh)
	return b, b, err
}
开发者ID:tendermint,项目名称:functional-tester,代码行数:33,代码来源:reader.go


示例7: GetParentInfo

func GetParentInfo(node string) (node_info.NodeInfo, tree_lib.TreeError) {
	var (
		err   tree_lib.TreeError
		pname string
	)
	err.From = tree_lib.FROM_GET_PARENT_INFO

	err = ForEach(DB_NODE, func(key []byte, val []byte) error {
		n := node_info.NodeInfo{}
		err := ffjson.Unmarshal(val, &n)
		if err != nil {
			return err
		}

		if _, ok := tree_lib.ArrayContains(n.Childs, node); ok {
			pname = n.Name
			return errors.New("Just Err for break")
		}

		return nil
	})

	if len(pname) == 0 {
		return node_info.NodeInfo{}, tree_lib.TreeError{}
	}

	// Node relations first element should be parent node
	return GetNodeInfo(pname)
}
开发者ID:treescale,项目名称:treescale,代码行数:29,代码来源:node_db.go


示例8: Close

// Close finishes the current journal and closes the writer.
func (w *Writer) Close() error {
	w.seq++
	w.writePending()
	if w.err != nil {
		return w.err
	}
	w.err = errors.New("leveldb/journal: closed Writer")
	return nil
}
开发者ID:lessos,项目名称:lessdb,代码行数:10,代码来源:journal.go


示例9: UpdateConfig

// UpdateConfig writes the updated configuration data to the storage location.
func UpdateConfig(conf Configuration) (err error) {
	cfgDir, _ := getConfigDir()
	d, err := json.Marshal(&conf)
	if err != nil {
		return errors.New("Could not save new json config")
	}
	ioutil.WriteFile(cfgDir+"/1Password.json", d, 0664)
	return nil
}
开发者ID:Nitecon,项目名称:1Password,代码行数:10,代码来源:config.go


示例10: del

func del(k string) error {
	if len(strings.TrimSpace(k)) == 0 {
		return errors.New("uid was nil")
	}
	_, err := redis.Int(rds.Do("DEL", k))
	if err != nil {
		return err
	}
	return nil
}
开发者ID:yqj2012,项目名称:Coolpy5Sub,代码行数:10,代码来源:Node.go


示例11: updateSubdomainMap

func (ms *MirageStorage) updateSubdomainMap(subdomainMap map[string]int) error {
	//dump.Dump(subdomainMap)
	subdomainData, err := json.Marshal(subdomainMap)

	err = ms.Set("subdomain-map", subdomainData)
	if err != nil {
		return errors.New(fmt.Sprintf("failed to update subdomain-map: %s", err.Error()))
	}

	return nil
}
开发者ID:Konboi,项目名称:mirage,代码行数:11,代码来源:storage.go


示例12: getDataNodeFromId

func getDataNodeFromId(topo *Topology, id string) (foundDn *DataNode) {
	nid := NodeId(id)
	topo.WalkDataNode(func(dn *DataNode) (e error) {
		if dn.Id() == nid {
			foundDn = dn
			e = errors.New("Found.")
		}
		return
	})
	return
}
开发者ID:tnextday,项目名称:seaweedfs,代码行数:11,代码来源:volume_growth_test.go


示例13: nodeCreate

func nodeCreate(ukey string, node *Node) error {
	v, err := Incr.NodeInrc()
	if err != nil {
		return err
	}
	node.Id = v
	json, err := json.Marshal(node)
	if err != nil {
		return err
	}
	key := ukey + ":" + strconv.FormatInt(node.HubId, 10) + ":" + strconv.FormatInt(node.Id, 10)
	_, err = rds.Do("SET", key, json)
	if err != nil {
		return err
	}
	//验证nodetype
	if NodeTypeEnum.GetName(node.Type-1) == "" {
		return errors.New("node type error")
	}
	//初始化控制器
	if node.Type == NodeTypeEnum.Switcher {
		err := Controller.BeginSwitcher(ukey, node.HubId, node.Id)
		if err != nil {
			return errors.New("init error")
		}
	} else if node.Type == NodeTypeEnum.GenControl {
		err := Controller.BeginGenControl(ukey, node.HubId, node.Id)
		if err != nil {
			return errors.New("init error")
		}
	} else if node.Type == NodeTypeEnum.RangeControl {
		err := Controller.BeginRangeControl(ukey, node.HubId, node.Id)
		if err != nil {
			return errors.New("init error")
		}
	}
	return nil
}
开发者ID:yqj2012,项目名称:Coolpy5Sub,代码行数:38,代码来源:Node.go


示例14: RemoveFromSubdomainMap

func (ms *MirageStorage) RemoveFromSubdomainMap(subdomain string) error {
	subdomainMap, err := ms.getSubdomainMap()
	if err != nil {
		return errors.New(fmt.Sprintf("failed to get subdomain-map: %s", err.Error()))
	}

	beforeLen := len(subdomainMap)

	delete(subdomainMap, subdomain)

	if beforeLen == len(subdomainMap) {
		return nil
	}

	return ms.updateSubdomainMap(subdomainMap)
}
开发者ID:Konboi,项目名称:mirage,代码行数:16,代码来源:storage.go


示例15: nodeStartWith

func nodeStartWith(k string) ([]*Node, error) {
	data, err := redis.Strings(rds.Do("KEYSSTART", k))
	if err != nil {
		return nil, err
	}
	if len(data) <= 0 {
		return nil, errors.New("no data")
	}
	var ndata []*Node
	for _, v := range data {
		o, _ := redis.String(rds.Do("GET", v))
		h := &Node{}
		json.Unmarshal([]byte(o), &h)
		ndata = append(ndata, h)
	}
	return ndata, nil
}
开发者ID:yqj2012,项目名称:Coolpy5Sub,代码行数:17,代码来源:Node.go


示例16: AddToSubdomainMap

func (ms *MirageStorage) AddToSubdomainMap(subdomain string) error {
	subdomainMap, err := ms.getSubdomainMap()
	if err != nil {
		return errors.New(fmt.Sprintf("failed to get subdomain-map: %s", err.Error()))
	}

	beforeLen := len(subdomainMap)

	subdomainMap[subdomain] = 1 // meanless value

	if beforeLen == len(subdomainMap) {
		// need not to update
		fmt.Println("subdomainMap length is not changed!")
		return nil
	}

	return ms.updateSubdomainMap(subdomainMap)
}
开发者ID:Konboi,项目名称:mirage,代码行数:18,代码来源:storage.go


示例17: loadConfig

func loadConfig(cfgFile string) (*config.Wrapper, string, error) {
	info, err := os.Stat(cfgFile)
	if err != nil {
		return nil, "", err
	}
	if !info.Mode().IsRegular() {
		return nil, "", errors.New("configuration is not a file")
	}

	cfg, err := config.Load(cfgFile, myID)
	if err != nil {
		return nil, "", err
	}

	myCfg := cfg.Devices()[myID]
	myName := myCfg.Name
	if myName == "" {
		myName, _ = os.Hostname()
	}

	return cfg, myName, nil
}
开发者ID:JBTech,项目名称:syncthing,代码行数:22,代码来源:main.go


示例18: newBlockIter

func (r *Reader) newBlockIter(b *block, bReleaser util.Releaser, slice *util.Range, inclLimit bool) *blockIter {
	bi := &blockIter{
		tr:            r,
		block:         b,
		blockReleaser: bReleaser,
		// Valid key should never be nil.
		key:             make([]byte, 0),
		dir:             dirSOI,
		riStart:         0,
		riLimit:         b.restartsLen,
		offsetStart:     0,
		offsetRealStart: 0,
		offsetLimit:     b.restartsOffset,
	}
	if slice != nil {
		if slice.Start != nil {
			if bi.Seek(slice.Start) {
				bi.riStart = b.restartIndex(bi.restartIndex, b.restartsLen, bi.prevOffset)
				bi.offsetStart = b.restartOffset(bi.riStart)
				bi.offsetRealStart = bi.prevOffset
			} else {
				bi.riStart = b.restartsLen
				bi.offsetStart = b.restartsOffset
				bi.offsetRealStart = b.restartsOffset
			}
		}
		if slice.Limit != nil {
			if bi.Seek(slice.Limit) && (!inclLimit || bi.Next()) {
				bi.offsetLimit = bi.prevOffset
				bi.riLimit = bi.restartIndex + 1
			}
		}
		bi.reset()
		if bi.offsetStart > bi.offsetLimit {
			bi.sErr(errors.New("leveldb/table: invalid slice range"))
		}
	}
	return bi
}
开发者ID:tendermint,项目名称:functional-tester,代码行数:39,代码来源:reader.go


示例19: SetRelations

// Key -> value ..... node_name -> node1,node2,node3
// []byte -> []string{}.Join(",")
// First element of string array should be parent node
func SetRelations(node string) (err tree_lib.TreeError) {
	err.From = tree_lib.FROM_SET_RELATIONS
	parent_name := ""
	inf := node_info.NodeInfo{}
	inf, err = GetNodeInfo(node)
	if !err.IsNull() {
		return
	}

	rels := inf.Childs

	// Getting parent node
	err = ForEach(DB_NODE, func(key []byte, val []byte) error {
		nf := node_info.NodeInfo{}
		err := ffjson.Unmarshal(val, &nf)
		if err != nil {
			return err
		}
		if _, ok := tree_lib.ArrayContains(nf.Childs, node); ok {
			parent_name = nf.Name
			return errors.New("") // Just ending the ForEach with empty error
		}

		return nil
	})

	if !err.IsNull() {
		return
	}

	if len(parent_name) != 0 {
		rels = append(append([]string{}, parent_name), rels...)
	}

	err = Set(DB_RELATIONS, []byte(node), []byte(strings.Join(rels, ",")))
	return
}
开发者ID:treescale,项目名称:treescale,代码行数:40,代码来源:node_db.go


示例20: add

// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package leveldb

import (
	"sync"
	"time"

	"github.com/syndtr/goleveldb/leveldb/errors"
	"github.com/syndtr/goleveldb/leveldb/opt"
	"github.com/syndtr/goleveldb/leveldb/storage"
)

var (
	errCompactionTransactExiting = errors.New("leveldb: compaction transact exiting")
)

type cStat struct {
	duration time.Duration
	read     int64
	write    int64
}

func (p *cStat) add(n *cStatStaging) {
	p.duration += n.duration
	p.read += n.read
	p.write += n.write
}

func (p *cStat) get() (duration time.Duration, read, write int64) {
开发者ID:Codzart,项目名称:go-ethereum,代码行数:31,代码来源:db_compaction.go



注:本文中的github.com/syndtr/goleveldb/leveldb/errors.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errors.NewErrCorrupted函数代码示例发布时间:2022-05-28
下一篇:
Golang customer.New函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap