Documentation ¶
Overview ¶
Example (Chain) ¶
text := "Alphabet city is haunted\n" text += "Constantina feels right at home\n" text += "She probably wont say youre wrong\n" text += "Youre already wrong\nYoure already wrong\n" filtercat := New() filtercat.Command = "cat" filtergrep := New() filtergrep.Command = "grep" filtergrep.Argument("wrong") filterxargs := New() filterxargs.Command = "xargs" filterxargs.Argument("-n") filterxargs.Argument("3") c := Chain{ Filters: []Filter{ filtercat, filtergrep, filterxargs, }, } exec, err := c.Exec() if err != nil { log.Print(err) } exec.SetInput(bytes.NewReader([]byte(text))) var buf bytes.Buffer exec.SetOutput(&buf) err = exec.Run() if err != nil { log.Print(err) } fmt.Print(buf.String())
Output: She probably wont say youre wrong Youre already wrong Youre already wrong
Example (Chainfile) ¶
text := "Alphabet city is haunted\n" text += "Constantina feels right at home\n" text += "She probably wont say youre wrong\n" text += "Youre already wrong\nYoure already wrong\n" c, err := ChainFile("chain.yml") if err != nil { log.Print(err) } exec, err := c.Exec() if err != nil { log.Print(err) } exec.SetInput(bytes.NewReader([]byte(text))) var buf bytes.Buffer exec.SetOutput(&buf) err = exec.Run() if err != nil { log.Print(err) } fmt.Print(buf.String())
Output: She probably wont say youre wrong Youre already wrong Youre already wrong
Example (Input) ¶
text := []byte("hello world\ngoodbye world") filter := New() filter.Command = "grep" filter.Argument("goodbye") var buf bytes.Buffer exec := filter.Exec() exec.SetInput(bytes.NewReader(text)) exec.SetOutput(&buf) err := exec.Run() if err != nil { log.Print(err) } fmt.Println(buf.String())
Output: goodbye world
Example (Simple) ¶
text := "hello world" filter := New() filter.Command = "echo" filter.Argument(text) var buf bytes.Buffer exec := filter.Exec() exec.SetOutput(&buf) err := exec.Run() if err != nil { log.Print(err) } fmt.Println(buf.String())
Output: hello world
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotPointer the passed in vvariable was not a pointer ErrNotPointer = errors.New("Unmarshal requires pointer") // ErrChainDoesNotExist the chain was not found in the list of chains ErrChainDoesNotExist = errors.New("Chain does not exist") )
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
Filters []Filter `yaml:"Chain"`
}
Chain of commands where each feeds into stdin of the next
type Chains ¶
Chains is a map of chains that can be retrieved by name
func ChainsFile ¶
ChainsFile returns Chains loaded with data from a file
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is a filter error
type Exec ¶
type Exec struct {
// contains filtered or unexported fields
}
Exec is a command and with input and output attached
type Filter ¶
type Filter struct { // Program name Name string `yaml:"Name"` // Domain of program Domain string `yaml:"Domain"` // Version number Version string `yaml:"Version"` // Command to execute Command string `yaml:"Command"` // Arguments to command Arguments []string `yaml:"Arguments"` // VCS where filter can be found VCS `yaml:"VCS"` }
Filter is one command to be used as a filter
func FilterFile ¶
FilterFile returns a new Filter from a file definitions
Click to show internal directories.
Click to hide internal directories.