本文整理匯總了Golang中github.com/adriaandejonge/xld/util/intf.Command.Main方法的典型用法代碼示例。如果您正苦於以下問題:Golang Command.Main方法的具體用法?Golang Command.Main怎麽用?Golang Command.Main使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/adriaandejonge/xld/util/intf.Command
的用法示例。
在下文中一共展示了Command.Main方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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())
}