当前位置: 首页>>代码示例>>Golang>>正文


Golang pub.WebApiStub类代码示例

本文整理汇总了Golang中lzbgt/go-losapi/pub.WebApiStub的典型用法代码示例。如果您正苦于以下问题:Golang WebApiStub类的具体用法?Golang WebApiStub怎么用?Golang WebApiStub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WebApiStub类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
开发者ID:lzbgt,项目名称:go-losapi,代码行数:29,代码来源:show.go

示例2: Push

func (m *Manifest) Push(stub *pub.WebApiStub, strPath string) (err error) {
	//联网
	if stub == nil {
		stub, err = pub.GetStub(m.Res.URL)
		if err != nil {
			return err
		}
		reply, err := stub.Login(m.Res.ID, m.Res.PPT)
		if err != nil {
			return err
		}

		stub.Sid = reply.Sid
	}

	m.stub = stub
	fmt.Println(stub.Sid)
	//依次发布资源,并取得资源id list
	m.ids = make([]string, len(m.ResFile), len(m.ResFile))
	for i, v := range m.ResFile {
		//发布资源:参数:name,资源,返回一个id
		name := m.ResName[i]
		if v == "" {
			m.ids[i] = ""
			continue
		}
		fmt.Println(v)
		if m.ids[i], err = PushRes(stub, m.Res.ID, name, strPath+v, 0); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:lzbgt,项目名称:go-losapi,代码行数:33,代码来源:Manifest.go

示例3: 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)
}
开发者ID:lzbgt,项目名称:go-losapi,代码行数:11,代码来源:Manifest.go

示例4: 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
}
开发者ID:lzbgt,项目名称:go-losapi,代码行数:13,代码来源:Command.go

示例5: uploadNodeMainifest

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
}
开发者ID:lzbgt,项目名称:go-losapi,代码行数:13,代码来源:Manifest.go

示例6: 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
}
开发者ID:lzbgt,项目名称:go-losapi,代码行数:17,代码来源:release.go

示例7: 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
}
开发者ID:lzbgt,项目名称:go-losapi,代码行数:44,代码来源:push.go

示例8: 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
}
开发者ID:lzbgt,项目名称:go-losapi,代码行数:20,代码来源:Manifest.go

示例9: 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
}
开发者ID:lzbgt,项目名称:go-losapi,代码行数:22,代码来源:Command.go

示例10: 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
}
开发者ID:lzbgt,项目名称:go-losapi,代码行数:94,代码来源:Command.go

示例11: 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
}
开发者ID:lzbgt,项目名称:go-losapi,代码行数:74,代码来源:clear.go


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