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 }
func (nm *NodeManifest) uploadNodeMainifest(stub *pub.WebApiStub, ID string) error { //生成json格式 buf, err := json.Marshal(nm) if err != nil { return err } _, err = stub.Hset(ID, FieldApplist, nm.AppName, string(buf)) if err != nil { return err } fmt.Println("uploadManifest ok") return nil }
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 }
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 }