Documentation ¶
Overview ¶
Package graph manages programs stored as graphs.
Index ¶
- Variables
- type Channel
- type Graph
- func (g *Graph) AllImports() []string
- func (g *Graph) Build() error
- func (g *Graph) DeclaredChannels(chans []string) []*Channel
- func (g *Graph) Definitions() string
- func (g *Graph) GeneratePackage() (string, error)
- func (g *Graph) Install() error
- func (g *Graph) PackageName() string
- func (g *Graph) RecomputeDegrees()
- func (g *Graph) RecomputeNode(n *Node) error
- func (g *Graph) Run(stdout, stderr io.Writer) error
- func (g *Graph) SaveJSONFile() error
- func (g *Graph) WriteDotTo(dst io.Writer) error
- func (g *Graph) WriteGoTo(w io.Writer) error
- func (g *Graph) WriteJSONTo(w io.Writer) error
- func (g *Graph) WriteRawGoTo(w io.Writer) error
- type Node
- func (n *Node) Channels() (read, written source.StringSet)
- func (n *Node) ChannelsRead() []string
- func (n *Node) ChannelsWritten() []string
- func (n *Node) Copy() *Node
- func (n *Node) ImplBody() string
- func (n *Node) ImplHead() string
- func (n *Node) ImplTail() string
- func (n *Node) MarshalJSON() ([]byte, error)
- func (n *Node) RenameChannel(from, to string)
- func (n *Node) String() string
- func (n *Node) UnmarshalJSON(j []byte) error
- type Part
- type PartFactory
Constants ¶
This section is empty.
Variables ¶
var PartFactories = map[string]PartFactory{ "Aggregator": func() Part { return new(parts.Aggregator) }, "Broadcast": func() Part { return new(parts.Broadcast) }, "Code": func() Part { return new(parts.Code) }, "Filter": func() Part { return new(parts.Filter) }, "HTTPServer": func() Part { return new(parts.HTTPServer) }, "StaticSend": func() Part { return new(parts.StaticSend) }, "TextFileReader": func() Part { return new(parts.TextFileReader) }, "Unslicer": func() Part { return new(parts.Unslicer) }, }
PartFactories translates part type strings into part factories.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct { Name string `json:"name"` Type string `json:"type"` Cap int `json:"cap"` // contains filtered or unexported fields }
Channel models a channel. It can be marshalled and unmarshalled to JSON sensibly.
func (*Channel) IsSimple ¶
IsSimple returns true if its in-degree and out-degree are both 1. This causes the channel to appear as a single arrow instead of an intermediate node. Only correct after calling ComputeDegrees.
type Graph ¶
type Graph struct { SourcePath string `json:"-"` // path to the JSON source. Name string `json:"name"` PackagePath string `json:"package_path"` Imports []string `json:"imports"` IsCommand bool `json:"is_command"` Nodes map[string]*Node `json:"nodes"` Channels map[string]*Channel `json:"channels"` }
Graph describes a Go program as a graph. It can be marshalled and unmarshalled to JSON sensibly.
func LoadJSONFile ¶
LoadJSONFile loads a JSON-encoded Graph from a file at a given path.
func (*Graph) AllImports ¶
AllImports combines all desired imports into one slice. It doesn't fix conflicting names, but dedupes any whole lines. TODO: Put nodes in separate files to solve all import issues.
func (*Graph) DeclaredChannels ¶
DeclaredChannels returns the given channels which exist in g.Channels.
func (*Graph) Definitions ¶
Definitions returns the imports and channel var blocks from the Go program. This is useful for advanced parsing and typechecking.
func (*Graph) GeneratePackage ¶
GeneratePackage writes the Go view of the graph to a file called generated.go in ${GOPATH}/src/${g.PackagePath}/, returning the full path.
func (*Graph) PackageName ¶
PackageName extracts the name of the package from the package path ("full" package name).
func (*Graph) RecomputeDegrees ¶
func (g *Graph) RecomputeDegrees()
RecomputeDegrees analyses how nodes and channels are related.
func (*Graph) RecomputeNode ¶
RecomputeNode gets the node to figure out what channels it uses.
func (*Graph) Run ¶
Run saves the graph as Go source code, creates a temporary runner, and tries to run it. The stdout and stderr pipes are copied to the given io.Writers.
func (*Graph) SaveJSONFile ¶
SaveJSONFile saves the JSON-encoded Graph to the SourcePath.
func (*Graph) WriteDotTo ¶
WriteDotTo writes the Dot language view of the graph to the io.Writer.
func (*Graph) WriteJSONTo ¶
WriteJSONTo writes nicely-formatted JSON to the given Writer.
type Node ¶
type Node struct { Part Name string Multiplicity uint Wait bool // contains filtered or unexported fields }
Node models a goroutine. It can be marshalled and unmarshalled to JSON sensibly.
func (*Node) ChannelsRead ¶
ChannelsRead returns the channels read from by this node. It is a convenience function for the templates, which can't do multiple returns.
func (*Node) ChannelsWritten ¶
ChannelsWritten returns the channels written to by this node. It is a convenience function for the templates, which can't do multiple returns.
func (*Node) Copy ¶
Copy returns a copy of this node, but with an empty name and a clone of the Part.
func (*Node) MarshalJSON ¶
MarshalJSON encodes the node and part as JSON.
func (*Node) RenameChannel ¶
RenameChannel renames any uses of channel "from" to channel "to".
func (*Node) UnmarshalJSON ¶
UnmarshalJSON decodes the node and part as JSON.
type Part ¶
type Part interface { // AssociateEditor associates a template called "part_view" with the given template. AssociateEditor(*template.Template) error // Channels returns any additional channels the part thinks it uses. // This should be unnecessary. Channels() (read, written source.StringSet) // Clone returns a copy of this part. Clone() interface{} // Help returns a helpful description of what this part can do. Help() template.HTML // Impl returns Go source code implementing the part. // The head is executed, then the body is executed (# Multiplicity // instances of the body concurrently), then the tail (once the body/bodies // are finished). // // This allows cleanly closing channels for nodes with Multiplicity > 1. // The tail is deferred so that the body can use "return" and it is still // executed. Impl() (head, body, tail string) // Imports returns any extra import lines needed for the Part. Imports() []string // RenameChannel informs the part that a channel has been renamed. RenameChannel(from, to string) // TypeKey returns the "type" of part. TypeKey() string // Update sets fields in the part based on info in the given Request. Update(*http.Request) error }
Part abstracts the implementation of a node. Concrete implementations should be able to be marshalled to and unmarshalled from JSON sensibly.