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

Golang dot.Marshal函数代码示例

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

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



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

示例1: RunGraph

// RunGraph contains all the necessary functionality for the OpenShift cli graph command
func RunGraph(f *clientcmd.Factory, out io.Writer) error {
	client, kclient, err := f.Clients()
	if err != nil {
		return err
	}

	config, err := f.OpenShiftClientConfig.ClientConfig()
	if err != nil {
		return err
	}

	namespace, _, err := f.DefaultNamespace()
	if err != nil {
		return err
	}

	describer := &describe.ProjectStatusDescriber{K: kclient, C: client, Server: config.Host}
	g, _, err := describer.MakeGraph(namespace)
	if err != nil {
		return err
	}

	data, err := dot.Marshal(g, namespace, "", "  ", false)
	if err != nil {
		return err
	}

	fmt.Fprintf(out, "%s", string(data))
	return nil
}
开发者ID:ncantor,项目名称:origin,代码行数:31,代码来源:status.go


示例2: Describe

// Describe returns the output of the graph starting from the provided
// image stream tag (name:tag) in namespace. Namespace is needed here
// because image stream tags with the same name can be found across
// different namespaces.
func (d *ChainDescriber) Describe(ist *imageapi.ImageStreamTag, includeInputImages bool) (string, error) {
	g, err := d.MakeGraph()
	if err != nil {
		return "", err
	}

	// Retrieve the imageStreamTag node of interest
	istNode := g.Find(imagegraph.ImageStreamTagNodeName(ist))
	if istNode == nil {
		return "", NotFoundErr(fmt.Sprintf("%q", ist.Name))
	}

	buildInputEdgeKinds := []string{buildedges.BuildTriggerImageEdgeKind}
	if includeInputImages {
		buildInputEdgeKinds = append(buildInputEdgeKinds, buildedges.BuildInputImageEdgeKind)
	}

	// Partition down to the subgraph containing the ist of interest
	partitioned := partition(g, istNode, buildInputEdgeKinds)

	switch strings.ToLower(d.outputFormat) {
	case "dot":
		data, err := dot.Marshal(partitioned, fmt.Sprintf("%q", ist.Name), "", "  ", false)
		if err != nil {
			return "", err
		}
		return string(data), nil
	case "":
		return d.humanReadableOutput(partitioned, istNode), nil
	}

	return "", fmt.Errorf("unknown specified format %q", d.outputFormat)
}
开发者ID:patrykattc,项目名称:origin,代码行数:37,代码来源:chaindescriber.go


示例3: rend_db

func rend_db(w http.ResponseWriter, r *http.Request) {
	g, n, db, err1 := get_graph(w, r)
	if err1 != nil {
		return // Already rendered
	}
	labels, err3 := db.GetLabels()
	if err3 != nil {
		t_error.Execute(w, err3)
		return
	}
	data, err2 := dot.Marshal(dbViewGraph{UndirectedGraph: g.(*simple.UndirectedGraph), dbName: n, labels: labels}, "", "", "", false)
	if err2 != nil {
		t_error.Execute(w, err2)
		return
	}
	//fmt.Println(string(data))
	buf := bytes.NewBuffer(data)
	dotter := exec.Command("dot", "-Tsvg")
	dotin, _ := dotter.StdinPipe()
	dotout, _ := dotter.StdoutPipe()
	w.Header().Set("Content-type", "image/svg+xml")
	dotter.Start()
	io.Copy(dotin, buf)
	dotin.Close()
	io.Copy(w, dotout)
}
开发者ID:Grissess,项目名称:sdnd16,代码行数:26,代码来源:webintf.go


示例4: RunStatus

// RunStatus contains all the necessary functionality for the OpenShift cli status command.
func (o StatusOptions) RunStatus() error {
	var (
		s   string
		err error
	)

	switch o.outputFormat {
	case "":
		s, err = o.describer.Describe(o.namespace, "")
		if err != nil {
			return err
		}
	case "dot":
		g, _, err := o.describer.MakeGraph(o.namespace)
		if err != nil {
			return err
		}
		data, err := dot.Marshal(g, o.namespace, "", "  ", false)
		if err != nil {
			return err
		}
		s = string(data)
	default:
		return fmt.Errorf("invalid output format provided: %s", o.outputFormat)
	}

	fmt.Fprintf(o.out, s)
	return nil
}
开发者ID:rrati,项目名称:origin,代码行数:30,代码来源:status.go


示例5: rend_path

func rend_path(w http.ResponseWriter, r *http.Request) {
	g, n, db, err1 := get_graph(w, r)
	if err1 != nil {
		return // Already rendered
	}
	labels, err3 := db.GetLabels()
	if err3 != nil {
		t_error.Execute(w, err3)
		return
	}
	path := strings.Split(r.URL.Path, "/")
	nodes := path[4:]
	pathnodes := make(map[int]bool)
	pathslice := make([]int, len(nodes))
	for idx, s := range nodes {
		nid, err4 := strconv.Atoi(s)
		if err4 != nil {
			t_error.Execute(w, err4)
			return
		}
		pathnodes[nid] = true
		pathslice[idx] = nid
	}
	first := pathslice[0]
	last := pathslice[len(pathslice)-1]
	ng := dbPathGraph{UndirectedGraph: g.(*simple.UndirectedGraph), dbName: n, labels: labels, pathnodes: pathnodes, pathslice: pathslice, first: first, last: last}
	data, err2 := dot.Marshal(ng, "", "", "", false)
	//fmt.Println("dot:")
	//fmt.Println(string(data))
	if err2 != nil {
		t_error.Execute(w, err2)
		return
	}
	buf := bytes.NewBuffer(data)
	dotter := exec.Command("dot", "-Tsvg")
	dotin, _ := dotter.StdinPipe()
	dotout, _ := dotter.StdoutPipe()
	w.Header().Set("Content-type", "image/svg+xml")
	dotter.Start()
	io.Copy(dotin, buf)
	dotin.Close()
	io.Copy(w, dotout)
	//	dotter := exec.Command("dot", "-Tsvg")
	//	dotin, _ := dotter.StdinPipe()
	//	dotout, _ := dotter.StdoutPipe()
	//	w.Header().Set("Content-type", "image/svg+xml")
	//	dotter.Start()
	//	io.WriteString(dotin, "digraph {\n")
	//	for i := 0; i < len(nodes)-1; i++ {
	//		io.WriteString(dotin, fmt.Sprintf("%s -> %s\n", nodes[i], nodes[i+1]))
	//	}
	//	io.WriteString(dotin, "}")
	//	dotin.Close()
	//	io.Copy(w, dotout)
}
开发者ID:Grissess,项目名称:sdnd16,代码行数:55,代码来源:webintf.go


示例6: DumpDotFile

func DumpDotFile(g Graph) {
	b, err := dot.Marshal(g, "dump", "", "  ", true)
	if err != nil {
		Error.Println(err)
		return
	}
	err = ioutil.WriteFile("/tmp/hover.dot", b, 0644)
	if err != nil {
		Error.Println(err)
	}
}
开发者ID:iovisor,项目名称:iomodules,代码行数:11,代码来源:graph.go


示例7: Describe

// Describe returns the output of the graph starting from the provided
// image stream tag (name:tag) in namespace. Namespace is needed here
// because image stream tags with the same name can be found across
// different namespaces.
func (d *ChainDescriber) Describe(ist *imageapi.ImageStreamTag, includeInputImages, reverse bool) (string, error) {
	g, err := d.MakeGraph()
	if err != nil {
		return "", err
	}

	// Retrieve the imageStreamTag node of interest
	istNode := g.Find(imagegraph.ImageStreamTagNodeName(ist))
	if istNode == nil {
		return "", NotFoundErr(fmt.Sprintf("%q", ist.Name))
	}

	markers := buildanalysis.FindCircularBuilds(g, d.namer)
	if len(markers) > 0 {
		for _, marker := range markers {
			if strings.Contains(marker.Message, ist.Name) {
				return marker.Message, nil
			}
		}
	}

	buildInputEdgeKinds := []string{buildedges.BuildTriggerImageEdgeKind}
	if includeInputImages {
		buildInputEdgeKinds = append(buildInputEdgeKinds, buildedges.BuildInputImageEdgeKind)
	}

	// Partition down to the subgraph containing the imagestreamtag of interest
	var partitioned osgraph.Graph
	if reverse {
		partitioned = partitionReverse(g, istNode, buildInputEdgeKinds)
	} else {
		partitioned = partition(g, istNode, buildInputEdgeKinds)
	}

	switch strings.ToLower(d.outputFormat) {
	case "dot":
		data, err := dot.Marshal(partitioned, dotutil.Quote(ist.Name), "", "  ", false)
		if err != nil {
			return "", err
		}
		return string(data), nil
	case "":
		return d.humanReadableOutput(partitioned, d.namer, istNode, reverse), nil
	}

	return "", fmt.Errorf("unknown specified format %q", d.outputFormat)
}
开发者ID:Xmagicer,项目名称:origin,代码行数:51,代码来源:chaindescriber.go


示例8: main

func main() {
	g, labels, err1 := utils.ReadFileToGraph("topology.txt")
	if err1 != nil {
		fmt.Println("ReadFileToGraph:")
		fmt.Println(err1)
		return
	}
	labels = labels
	// fmt.Println(g);
	bytes, err2 := dot.Marshal(g, "", "", "  ", false)
	if err2 != nil {
		fmt.Println("dot.Marshall:")
		fmt.Println(err1)
		return
	}
	fmt.Println(string(bytes))
}
开发者ID:Grissess,项目名称:sdnd16,代码行数:17,代码来源:kshortest.go


示例9: rend_node

func rend_node(w http.ResponseWriter, r *http.Request) {
	g, n, db, err1 := get_graph(w, r)
	if err1 != nil {
		return // Already rendered
	}
	parts := strings.Split(r.URL.Path, "/")
	srcid, err3 := strconv.Atoi(parts[4])
	if err3 != nil {
		t_error.Execute(w, err3)
		return
	}
	labels, err4 := db.GetLabels()
	if err4 != nil {
		t_error.Execute(w, err4)
	}
	ng := dbNodeGraph{UndirectedGraph: simple.NewUndirectedGraph(0, math.Inf(1)), dbName: n, labels: labels}
	ng.AddNode(dbNodeNode{Node: simple.Node(srcid), dbName: n, label: labels[srcid]})
	for _, dst := range g.From(simple.Node(srcid)) {
		ng.AddNode(dbNodeNode{Node: simple.Node(dst.ID()), dbName: n, label: labels[dst.ID()]})
		ng.SetEdge(dbNodeEdge{simple.Edge{F: simple.Node(srcid), T: simple.Node(dst.ID()), W: g.Edge(simple.Node(srcid), dst).Weight()}})
	}
	data, err2 := dot.Marshal(ng, "", "", "", false)
	if err2 != nil {
		t_error.Execute(w, err2)
		return
	}
	//fmt.Println(string(data))
	buf := bytes.NewBuffer(data)
	dotter := exec.Command("dot", "-Tsvg")
	dotin, _ := dotter.StdinPipe()
	dotout, _ := dotter.StdoutPipe()
	w.Header().Set("Content-type", "image/svg+xml")
	dotter.Start()
	io.Copy(dotin, buf)
	dotin.Close()
	io.Copy(w, dotout)
}
开发者ID:Grissess,项目名称:sdnd16,代码行数:37,代码来源:webintf.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang path.AllShortest类代码示例发布时间:2022-05-23
下一篇:
Golang concrete.Node函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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