本文整理汇总了Golang中github.com/syndtr/goleveldb/leveldb/errors.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}