本文整理汇总了Golang中lzbgt/go-losapi/pub.WebApiStub.Hget方法的典型用法代码示例。如果您正苦于以下问题:Golang WebApiStub.Hget方法的具体用法?Golang WebApiStub.Hget怎么用?Golang WebApiStub.Hget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lzbgt/go-losapi/pub.WebApiStub
的用法示例。
在下文中一共展示了WebApiStub.Hget方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: showRes
func showRes(stub *pub.WebApiStub, ID, resName string) error {
var oldver int
var err error
oldver, err = pub.O2Int(stub.Hget(ID, resName, pub.FD_LastVer))
log.Info("ResName:", resName)
if err != nil {
return errors.New("failed to get last version of " + resName + "\nerror: " + err.Error())
}
log.Info("Last Version:", oldver)
oldver, err = pub.O2Int(stub.Hget(ID, resName, pub.FD_Release))
if err != nil {
return errors.New("failed to get release version of " + resName + "\nerror: " + err.Error())
}
log.Info("Release Version:", oldver)
// if log.verbose {
// keys, err := stub.Hkeys(ID, resName)
// if err != nil {
// return errors.New("failed to get info of ", resName, "\nerror: ", err.Error())
// }
// for _, key := range keys {
// fmt.Println(key)
// }
// }
return nil
}
示例2: init
func (nm *NodeManifest) init(stub *pub.WebApiStub, ID, appName string) error {
o, err := stub.Hget(ID, FieldApplist, appName)
// fmt.Println(o, err)
if err != nil {
return err
}
fmt.Println("NodeManifest init")
str, _ := o.(string)
buf := []byte(str)
return json.Unmarshal(buf, nm)
}
示例3: ReleaseRes
func ReleaseRes(stub *pub.WebApiStub, id, resName string, ver int) (err error) {
if ver == 0 {
ver, err = pub.O2Int(stub.Hget(id, resName, pub.FD_LastVer))
if err != nil {
ver = 0
}
}
if _, err = stub.Hset(id, resName, pub.FD_Release, ver); err != nil {
return err
}
fmt.Printf("set res[%s] version to [%d]\r\n", resName, ver)
return nil
}
示例4: ReleaseRes
func ReleaseRes(stub *pub.WebApiStub, id, resName string, ver int) error {
lastVer, err := pub.O2Int(stub.Hget(id, resName, pub.FD_LastVer))
if err != nil {
return errors.New("failed to get version for this resouce \"" + resName + "\"\nerror:" + err.Error())
}
if ver == -1 {
ver = lastVer
}
if _, err = stub.Hset(id, resName, pub.FD_Release, ver); err != nil {
return err
}
fmt.Printf("released res \"%s\" version %d \r\n", resName, ver)
return nil
}
示例5: PushRes
func PushRes(stub *pub.WebApiStub, BID, name, filename string, ver int) (ID string, err error) {
log.V(" push", name, filename)
if name == "" {
return "", errName.Format("is null")
}
var oldver int
var oldId string
oldver, err = pub.O2Int(stub.Hget(BID, name, pub.FD_LastVer))
if err != nil {
oldver = 0
}
log.V("last version:", oldver)
if ver > 0 && ver <= oldver {
return "", errVer.Format(ver, oldver)
}
strVer := fmt.Sprint(oldver)
if oldId, err = pub.O2Str(stub.Hget(BID, name, strVer)); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
oldId = ""
}
log.V("last id:", oldId)
//读取文件
var rd []byte
rd, err = ioutil.ReadFile(filename)
if err != nil {
return
}
ID, err = stub.Setdata(BID, rd)
if err != nil {
return
}
log.V("new id:", ID)
if ID == oldId {
log.V("resource not changed")
return
}
ver = oldver + 1
strver := fmt.Sprintf("%d", oldver+1)
stub.Hset(BID, name, strver, ID)
stub.Hset(BID, name, pub.FD_LastVer, ver)
return
}
示例6: init
func (nm *NodeManifest) init(stub *pub.WebApiStub, ID, appName string) error {
o, err := stub.Hget(ID, FieldApplist, appName)
// log.Info(o, err)
if err != nil {
return err
}
log.Debug("NodeManifest init")
str, _ := o.(string)
if str == "" {
return errors.New("No app \"" + appName + "\" for bid \"" + ID + "\"")
}
buf := []byte(str)
err = json.Unmarshal(buf, nm)
if err != nil {
ret := errors.New("Invalid manifest:" + str + " " + err.Error())
return ret
}
return nil
}
示例7: showRes
func showRes(stub *pub.WebApiStub, ID, resName string) error {
keys, err := stub.Hkeys(ID, resName)
if err != nil {
return err
}
for _, key := range keys {
fmt.Println(key)
}
var oldver int
oldver, err = pub.O2Int(stub.Hget(ID, resName, pub.FD_LastVer))
if err != nil {
oldver = 0
}
fmt.Printf("last version is %d\r\n", oldver)
oldver, err = pub.O2Int(stub.Hget(ID, resName, pub.FD_Release))
if err != nil {
oldver = 0
}
fmt.Printf("release version is %d\r\n", oldver)
return nil
}
示例8: clearRes
// ver = -1 release
// ver = -2 last
func clearRes(stub *pub.WebApiStub, ID, name string, ver int) (err error) {
//if name == "" {
// if flag.NArg() < 2 {
// return errors.New("Res clear name ver")
// }
// name = flag.Arg(1)
// if *ver == 0 {
// if flag.NArg() < 3 {
// return errors.New("Res clear name ver")
// }
// strVer := flag.Arg(2)
// if strVer == pub.FD_Release {
// *ver, err = pub.O2Int(stub.Hget(ID, name, pub.FD_Release))
// if err != nil {
// *ver = 0
// }
// } else {
// if _, err = fmt.Sscan(strVer, ver); err != nil {
// return err
// }
// }
// }
//}
var c int64
getVer := func(strType string, def int) (ver int) {
ver, err = pub.O2Int(stub.Hget(ID, name, strType))
if err != nil {
ver = def
}
return
}
if ver == -1 {
ver = getVer(pub.FD_Release, 0)
} else if ver == -2 {
ver = getVer(pub.FD_LastVer, 0)
}
rVer := getVer(pub.FD_Release, -1)
lVer := getVer(pub.FD_LastVer, -1)
//rVer, err := pub.O2Int(stub.Hget(ID, name, pub.FD_Release))
//if err != nil {
// //fmt.Println(err.Error())
// rVer = -1
//}
//lVer, err := pub.O2Int(stub.Hget(ID, name, pub.FD_LastVer))
//if err != nil {
// //fmt.Println(err.Error())
// lVer = -1
//}
fmt.Printf("clear name=%s ver =%d\r\n", name, ver)
//versions, err := stub.Hkeys(ID, name)
//if err != nil {
// return err
//}
fvs, err := stub.Hgetall(ID, name)
if err != nil {
return err
}
var mapRef = make(map[string]int, 10)
for _, fv := range fvs {
id, _ := fv.Value.(string) //resid
mapRef[id] = mapRef[id] + 1
}
fmt.Printf("last version:%d, release version:%d\r\n", lVer, rVer)
for _, fv := range fvs {
v, err := pub.O2Int(fv.Field, nil) //版本v
if err != nil {
continue
}
id, _ := fv.Value.(string) //resid
fmt.Println("cur version:", v, " get id :", fv.Value, "refs=", mapRef[id])
if v >= ver || v == lVer || v == rVer {
//要确保release和debug能正常使用
continue
}
//根据版本取资源的id
if mapRef[id] <= 1 {
fmt.Printf("ref[%d] <= 1, no use, to del res\r\n", mapRef[id])
if c, err = stub.Del(ID, id); err != nil {
return err
}
fmt.Println("del res ok. c=", c, "id:", fv.Value)
}
if c, err = stub.Hdel(ID, name, fv.Field); err != nil {
return err
}
fmt.Println("c=", c, "version:", fv.Field, " deleted")
}
return nil
}
示例9: clearRes
func clearRes(stub *pub.WebApiStub, ID, name string, ver int) (err error) {
var c int64
getVer := func(strType string, def int) (ver int) {
ver, err = pub.O2Int(stub.Hget(ID, name, strType))
if err != nil {
ver = def
}
return
}
if ver == -1 {
ver = getVer(pub.FD_Release, -1)
if ver == -1 {
log.Info("failed to get release version for res", name)
return nil
}
} else if ver == -2 {
if ver == -1 {
log.Info("failed to get last version for res", name)
return nil
}
}
if (ver - 4) < 0 {
log.Info("no need to clear")
return
}
rVer := getVer(pub.FD_Release, -1)
lVer := getVer(pub.FD_LastVer, -1)
log.Info("clear resouce ", name)
log.V("range: version 0 ~", ver-4, "except v", rVer, "(release) and", lVer, "(last)")
fvs, err := stub.Hgetall(ID, name)
if err != nil {
return err
}
var mapRef = make(map[string]int, 10)
for _, fv := range fvs {
id, _ := fv.Value.(string) //resid
mapRef[id] = mapRef[id] + 1
}
fmt.Printf("last version:%d, release version:%d\r\n", lVer, rVer)
for _, fv := range fvs {
v, err := pub.O2Int(fv.Field, nil) //版本v
if err != nil {
continue
}
id, _ := fv.Value.(string) //resid
fmt.Println("cur version:", v, " get id :", fv.Value, "refs=", mapRef[id])
// for safety, preserve at least 4 versions
if v >= (ver-4) || v == lVer || v == rVer {
//要确保release和debug能正常使用
continue
}
//根据版本取资源的id
if mapRef[id] <= 1 {
fmt.Printf("ref[%d] <= 1, no use, to del res\r\n", mapRef[id])
if c, err = stub.Del(ID, id); err != nil {
return err
}
fmt.Println("del res ok. c=", c, "id:", fv.Value)
}
if c, err = stub.Hdel(ID, name, fv.Field); err != nil {
return err
}
fmt.Println("c=", c, "version:", fv.Field, " deleted")
}
return nil
}