Exemple #1
0
func subsResp(detail bool, respbody []byte, repoitem string) {

	if detail {
		subs := ds.Data{}
		result := &ds.Result{Data: &subs}
		err := json.Unmarshal(respbody, &result)
		if err != nil {
			panic(err)
		}
		n, _ := fmt.Printf("%s\t%s\t%s\n", "REPOSITORY/ITEM[:TAG]", "UPDATETIME", "COMMENT")

		printDash(n + 20)
		for _, tag := range subs.Taglist {
			fmt.Printf("%s:%-8s\t%s\t%s\n", repoitem, tag.Tag, tag.Optime, tag.Comment)
		}
	} else {
		var itemStatus string
		subs := []ds.Data{}
		pages := ds.ResultPages{Results: &subs}
		result := &ds.Result{Data: &pages}
		err := json.Unmarshal(respbody, &result)
		if err != nil {
			panic(err)
		}

		citem := []string{"REPOSITORY/ITEM"}
		ctype := []string{"TYPE"}
		cstatus := []string{"STATUS"}
		for _, item := range subs {
			//crepo = append(crepo, item.Repository_name)
			citem = append(citem, item.Repository_name+"/"+item.Dataitem_name)
			ctype = append(ctype, "file")
			itemStatus, err = getItemStatus(item.Repository_name, item.Dataitem_name)
			if err != nil {
				//fmt.Println("Error :", err)
				cstatus = append(cstatus, "")
			}
			cstatus = append(cstatus, itemStatus)
			//fmt.Printf("%s/%-8s\t%s\t%s\n", item.Repository_name, item.Dataitem_name, "file", itemStatus)
		}
		utils.PrintFmt(citem, ctype, cstatus)
	}

}
Exemple #2
0
func repoResp(icmd int, respbody []byte, repo, item, tag string) {
	//fmt.Println(string(respbody))
	result := ds.Result{Code: ResultOK}
	if icmd == Repos {
		repos := []ds.Repositories{}
		result.Data = &repos
		err := json.Unmarshal(respbody, &result)
		if err != nil {
			panic(err)
		}
		fmt.Printf("%-16s\n", "REPOSITORY") //, "UPDATETIME", "COMMENT")

		for _, v := range repos {
			fmt.Printf("%-16s\n", v.RepositoryName) //, v.Optime, v.Comment)
		}
	} else if icmd == ReposReponame {
		onerepo := ds.Repository{}
		result.Data = &onerepo
		err := json.Unmarshal(respbody, &result)
		if err != nil {
			panic(err)
		}
		fmt.Printf("REPOSITORY/DATAITEM\n")

		for _, v := range onerepo.DataItems {
			fmt.Printf("%s/%s\n", repo, v)
		}

	} else if icmd == ReposReponameDataItem {
		itemStatus, err := getItemStatus(repo, item)
		if err != nil {
			fmt.Println("Error :", err)
			return
		}
		var tagStatus string
		repoitemtags := ds.Data{}
		result.Data = &repoitemtags
		err = json.Unmarshal(respbody, &result)
		if err != nil {
			fmt.Println("Error :", err)
			return
		}
		abnormalTags, err := getTagStatusOfItem(repo, item)
		if err != nil {
			fmt.Println("Error :", err)
			return
		}

		repoitemname := repo + "/" + item

		ctag := []string{"REPOSITORY/ITEM:TAG"}
		cupdatetime := []string{"UPDATETIME"}
		ccomment := []string{"COMMENT"}
		cstatus := []string{"STATUS"}

		if itemStatus == "offline" {
			for _, v := range repoitemtags.Taglist {
				//fmt.Printf("%s/%s:%s\t%s\t%s\t%s\n", repo, item, v.Tag, v.Optime, v.Comment, "ABNORMAL")
				ctag = append(ctag, repo+"/"+item+":"+v.Tag)
				cupdatetime = append(cupdatetime, v.Optime)
				ccomment = append(ccomment, v.Comment)
				cstatus = append(cstatus, "ABNORMAL")
			}
		} else {
			for _, v := range repoitemtags.Taglist {
				repoitemtag := repoitemname + ":" + v.Tag
				tagStatus = judgeTag(abnormalTags, repoitemtag)
				//fmt.Printf("%s/%s:%s\t%s\t%s\t%s\n", repo, item, v.Tag, v.Optime, v.Comment, tagStatus)
				ctag = append(ctag, repo+"/"+item+":"+v.Tag)
				cupdatetime = append(cupdatetime, v.Optime)
				ccomment = append(ccomment, v.Comment)
				cstatus = append(cstatus, tagStatus)
			}
		}
		utils.PrintFmt(ctag, cupdatetime, ccomment, cstatus)

	} else if icmd == ReposReponameDataItemTag {
		itemStatus, err := getItemStatus(repo, item)
		if err != nil {
			fmt.Println("Error :", err)
			return
		}
		tagStatus, err := getTagStatus(repo, item, tag)
		if err != nil {
			fmt.Println("Error :", err)
			return
		}
		onetag := ds.Tag{}
		result.Data = &onetag
		err = json.Unmarshal(respbody, &result)
		if err != nil {
			fmt.Println("Error :", err)
			return
		}
		//n, _ := fmt.Printf("%s\t%s\t%s\t\t%s\n", "REPOSITORY/ITEM:TAG", "UPDATETIME", "COMMENT", "STATUS")
		ctag := []string{"REPOSITORY/ITEM:TAG"}
		cupdatetime := []string{"UPDATETIME"}
		ccomment := []string{"COMMENT"}
		cstatus := []string{"STATUS"}
		if itemStatus == "offline" {
			//fmt.Printf("%s/%s:%s\t%s\t%s\t%s\n", repo, item, tag, onetag.Optime, onetag.Comment, "ABNORMAL")
			ctag = append(ctag, repo+"/"+item+":"+tag)
			cupdatetime = append(cupdatetime, onetag.Optime)
			ccomment = append(ccomment, onetag.Comment)
			cstatus = append(cstatus, "ABNORMAL")
		} else {
			//fmt.Printf("%s/%s:%s\t%s\t%s\t%s\n", repo, item, tag, onetag.Optime, onetag.Comment, tegStatus)
			ctag = append(ctag, repo+"/"+item+":"+tag)
			cupdatetime = append(cupdatetime, onetag.Optime)
			ccomment = append(ccomment, onetag.Comment)
			cstatus = append(cstatus, tagStatus)
		}
		utils.PrintFmt(ctag, cupdatetime, ccomment, cstatus)
	}
}