github.com/awesome-flow/flow@v0.0.3-0.20190918184116-508d75d68a2c/web/app/agent/graphviz.go (about)

     1  package agent
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	core "github.com/awesome-flow/flow/pkg/corev1alpha1"
     8  	"github.com/awesome-flow/flow/pkg/types"
     9  	explain "github.com/awesome-flow/flow/pkg/util/explain"
    10  )
    11  
    12  type DescribePage struct {
    13  	Title    string
    14  	GraphViz string
    15  }
    16  
    17  func init() {
    18  	RegisterWebAgent(
    19  		func(ctx *core.Context) (WebAgent, error) {
    20  			cfgppl, ok := ctx.Config().Get(types.NewKey("pipeline"))
    21  			if !ok {
    22  				return nil, fmt.Errorf("failed to get `pipeline` config")
    23  			}
    24  			e := new(explain.Pipeline)
    25  			expl, err := e.Explain(cfgppl)
    26  			if err != nil {
    27  				return nil, err
    28  			}
    29  
    30  			return NewDummyWebAgent(
    31  				"/pipeline/describe",
    32  				func(rw http.ResponseWriter, req *http.Request) {
    33  					respondWith(rw, RespHtml, "graphviz", &DescribePage{
    34  						Title:    "Flow Pipeline",
    35  						GraphViz: string(expl),
    36  					})
    37  				},
    38  			), nil
    39  		},
    40  	)
    41  }