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

Golang intf.Command类代码示例

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

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



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

示例1: Do

func Do(args intf.Command) (result string, err error) {

	subs := args.Subs()

	cred := subs[1] + ":" + subs[2]
	sEnc := b64.StdEncoding.EncodeToString([]byte(cred))
	result, err = Login(&LoginObject{subs[0], sEnc})

	return
}
开发者ID:m1028639,项目名称:xld,代码行数:10,代码来源:login.go


示例2: describe

func describe(args intf.Command) (result string, err error) {
	subs := args.Subs()

	for _, sub := range subs {
		_, err := describeOne(sub)
		if err != nil {
			return "error", err
		}
	}
	return "", nil
}
开发者ID:m1028639,项目名称:xld,代码行数:11,代码来源:describe.go


示例3: modify

func modify(args intf.Command) (result string, err error) {
	resultMap, err := ReadAsMap(args)
	if err != nil {
		return "error", err
	}

	content := resultMap["content"]
	mapContent, ok := content.(map[string]interface{})
	if !ok {
		return "error", errors.New("Unable to modify existing content")
	}

	props := args.Arguments()
	for _, prop := range props {
		key := prop.Name()

		split := strings.SplitN(key, "-", 2)
		prefix := split[0]
		switch prefix {
		case "add", "remove", "change":
			if len(split) > 1 {
				key = split[1]
			}
			err = handleAddRemoveChange(mapContent, prefix, key, prop)
			if err != nil {
				return "error", err
			}
		default:
			typeName, ok := resultMap["type"].(string)
			if !ok {
				return "error", errors.New("Cannot resolve type for existing item")
			}

			ciType, err := metadata.Type(typeName)
			if err != nil {
				return "error", err
			}

			err = handleDefault(mapContent, key, prop, ciType)
			if err != nil {
				return "error", err
			}
		}
	}

	json, err := json.MarshalIndent(resultMap, "", "    ")

	createCmd, err := cmd.NewStdinCmd("modify-sub", string(json))
	if err != nil {
		return "error", err
	}
	return createOrModify(createCmd)
}
开发者ID:m1028639,项目名称:xld,代码行数:53,代码来源:modify.go


示例4: ReadAsMap

func ReadAsMap(args intf.Command) (resultMap map[string]interface{}, err error) {
	subs := args.Subs()

	ci := AntiAbbreviate(subs[0])

	body, err := http.Read("/repository/ci/" + ci)
	if err != nil {
		return
	}

	return xml2CleanMap(body)

}
开发者ID:m1028639,项目名称:xld,代码行数:13,代码来源:read.go


示例5: remove

func remove(args intf.Command) (result string, err error) {

	for _, sub := range args.Subs() {
		ciName := AntiAbbreviate(sub)
		// TODO validate input

		body, err := http.Remove("/repository/ci/" + ciName)
		if err != nil {
			return "error", err
		}

		result = string(body)
	}

	return
}
开发者ID:m1028639,项目名称:xld,代码行数:16,代码来源:remove.go


示例6: createOrModify

func createOrModify(args intf.Command) (result string, err error) {
	subs := args.Subs()
	typeName := subs[0]
	ciName := subs[1]

	ciType, err := metadata.Type(typeName)
	if err != nil {
		return
	}

	// put this as the root in a map containing a map
	// do this AFTER the for loop

	// create new map and put the below in it

	mapProps := make(map[string]interface{})

	props := args.Arguments()
	for _, prop := range props {
		key := prop.Name()

		mapProps[key], err = translateProp(ciType, prop)
		if err != nil {
			return
		}
	}

	id := ciName
	id = AntiAbbreviate(id)
	if ciType.Root != "" && !strings.HasPrefix(id, ciType.Root) {
		id = ciType.Root + "/" + id
	}
	mapProps["-id"] = id

	final := map[string]interface{}{ciType.Type: mapProps}

	// TODO Make this a util?
	json, _ := j2x.MapToJson(final)
	xml, _ := j2x.JsonToXml(json)

	switch args.Main() {
	case "create":
		body, err := http.Create("/repository/ci/"+id, bytes.NewBuffer(xml))
		if err != nil {
			return "error", err
		}
		return Xml2CleanJson(body)
	case "modify-sub":
		body, err := http.Update("/repository/ci/"+id, bytes.NewBuffer(xml))
		if err != nil {
			return "error", err
		}
		return Xml2CleanJson(body)
	}
	return "error", errors.New("Unknown command " + args.Main())

}
开发者ID:m1028639,项目名称:xld,代码行数:57,代码来源:create.go


示例7: list

func list(args intf.Command) (result string, err error) {
	subs := args.Subs()

	arguments := make([]string, 0)

	if len(subs) > 0 {
		if strings.HasSuffix(subs[0], "*") {
			arguments = append(arguments, "ancestor="+url.QueryEscape(AntiAbbreviate(strings.Replace(subs[0], "*", "", -1))))
		} else {
			arguments = append(arguments, "parent="+url.QueryEscape(AntiAbbreviate(subs[0])))
		}
	}

	extra := args.Arguments()
	for _, el := range extra {
		name := el.Name()

		switch name {
		case "type":
			arguments = append(arguments, "type="+url.QueryEscape(el.Value()))
		case "like":
			arguments = append(arguments, "namePattern="+url.QueryEscape(el.Value()))
		case "before":
			//TODO lastModifiedBefore
		case "after":
			//TODO lastModifiedAfter
		case "page":
			arguments = append(arguments, "page="+url.QueryEscape(el.Value()))
		case "pagesize":
			arguments = append(arguments, "resultsPerPage="+url.QueryEscape(el.Value()))
		}
	}

	body, err := http.Read("/repository/query?" + strings.Join(arguments, "&"))
	list, err := readCiList(body)
	if err != nil {
		return "error", err
	}
	for _, el := range list.CIs {
		fmt.Println(el.CiRef)
	}

	return "", err
}
开发者ID:m1028639,项目名称:xld,代码行数:44,代码来源:list.go


示例8: undeploy

func undeploy(args intf.Command) (result string, err error) {
	subs := args.Subs()
	appToUndeploy := repo.AntiAbbreviate(subs[0])
	body, err := http.Read("/deployment/prepare/undeploy?deployedApplication=" + appToUndeploy)
	if err != nil {
		return
	}

	body, err = http.Create("/deployment", bytes.NewBuffer(body))
	if err != nil {
		return
	}

	taskId := string(body)

	body, err = http.Create("/task/"+string(body)+"/start", nil)
	if err != nil {
		return
	}

	displayStatus(taskId)

	return string(body), err
}
开发者ID:m1028639,项目名称:xld,代码行数:24,代码来源:undeploy.go


示例9: grant

func grant(args intf.Command) (result string, err error) {
	subs := args.Subs()

	ci := subs[0]
	roleToChange := subs[1]
	perms := subs[2:]

	// Get current permissions
	// (already works for global keyword :) )
	body, err := http.Read("/internal/security/roles/permissions/" + repo.AntiAbbreviate(ci))
	if err != nil {
		return
	}

	values, err := x2j.XmlToMap(body)
	if err != nil {
		return
	}

	arr := arrayFromMap(values["collection"], "rolePermissions")
	changed := false

	for _, elMap := range arr {
		role := elMap["role"].(map[string]interface{})
		if role["-name"] == roleToChange {

			oldPerms := elMap["permissions"].([]interface{})
			for _, el := range perms {
				oldPerms = append(oldPerms, el)
			}
			elMap["permissions"], changed = oldPerms, true
		}
	}

	if !changed {
		roleMap := map[string]string{"-id": strconv.Itoa(len(arr)), "-role": roleToChange}
		fmt.Println("Need to add it.... :( ", roleMap)
		fullMap := map[string]interface{}{"permissions": perms, "role": roleMap}
		arr = append(arr, fullMap)
		values["collection"].(map[string]interface{})["rolePermissions"] = arr
	}

	// TODO Make this a util?
	json, _ := j2x.MapToJson(values)
	xml, _ := j2x.JsonToXml(json)

	fmt.Println("modified(?) response = ", string(xml))

	/*
		body, err = http.Update("/internal/security/roles/permissions/" +
			repo.AntiAbbreviate(ci),
			bytes.NewBuffer(xml))
		if err != nil {
			return
		}

		fmt.Println("modified(?) response = ", body)
		//*/

	//fmt.Println("permset = ", permSet)

	// decode XML to ... JSON or marshall to objects?

	// is role already in there?
	// if not: add role

	// is permission already in there? -> ignore

	// add permission

	// encode as XML

	// post to http
	return
}
开发者ID:m1028639,项目名称:xld,代码行数:75,代码来源:grant.go


示例10: prepare

func prepare(args intf.Command, depType string) (result string, err error) {
	subs := args.Subs()
	appVersion := repo.AntiAbbreviate(subs[0])
	targetEnv := repo.AntiAbbreviate(subs[1])

	parts := strings.Split(appVersion, "/")

	app := parts[len(parts)-2]

	targetDeployed := targetEnv + "/" + app

	if depType == "*" {
		statusCode, _, err := http.Get("/repository/ci/" + targetDeployed)
		if err != nil {
			return "error", err
		} else if statusCode == 200 {
			depType = "UPDATE"
		} else if statusCode == 404 {
			depType = "INITIAL"
		} else {
			return "error", errors.New("Unexpected http status code " + strconv.Itoa(statusCode) + " while checking the existance of " + targetDeployed)
		}
	}

	deployedApplication := map[string]interface{}{
		"-id": targetDeployed,
		"version": map[string]interface{}{
			"-ref": appVersion,
		},
		"environment": map[string]interface{}{
			"-ref": targetEnv,
		},
		"optimizePlan": "true",
	}

	deployment := map[string]interface{}{
		"deployment": map[string]interface{}{
			"-type": depType,
			"application": map[string]interface{}{
				"udm.DeployedApplication": deployedApplication,
			},
		},
	}

	for _, arg := range args.Arguments() {
		if arg.Name() == "orchestrator" {
			deployedApplication["orchestrator"] =
				repo.MapSetOfStrings(arg.Values())
		}
	}

	// TODO Make this a util?
	json, _ := j2x.MapToJson(deployment)
	xml, _ := j2x.JsonToXml(json)

	body, err := http.Create("/deployment/prepare/deployeds", bytes.NewBuffer(xml))
	if err != nil {
		return "error", err
	}

	body, err = http.Create("/deployment", bytes.NewBuffer(body))

	return string(body), err
}
开发者ID:m1028639,项目名称:xld,代码行数:64,代码来源:common.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang collect.Measure函数代码示例发布时间:2022-05-24
下一篇:
Golang gocheck.C类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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