本文整理匯總了Golang中github.com/mozilla-services/heka/pipeline.PipelinePack.Decoded方法的典型用法代碼示例。如果您正苦於以下問題:Golang PipelinePack.Decoded方法的具體用法?Golang PipelinePack.Decoded怎麽用?Golang PipelinePack.Decoded使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mozilla-services/heka/pipeline.PipelinePack
的用法示例。
在下文中一共展示了PipelinePack.Decoded方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
// Run runs the FileReadFilter filter, which inspects each message, and appends
// the content of the file named as the executed template to the existing payload.
// The resulting message will be injected back, and have newType type.
func (fr FileReadFilter) Run(r pipeline.FilterRunner, h pipeline.PluginHelper) (err error) {
if fr.tmpl == nil {
return errors.New("FileReadFilter: empty template")
}
var (
fh *os.File
inp io.Reader
npack, opack *pipeline.PipelinePack
)
out := bytes.NewBuffer(make([]byte, 0, 4096))
log.Printf("FileReadFilter: Starting with template %s", fr.tmpl)
for opack = range r.InChan() {
//log.Printf("opack=%v", opack)
//if opack.Decoded {
out.Reset()
if err = fr.tmpl.Execute(out, extendedMessage{opack.Message}); err != nil {
opack.Recycle()
return fmt.Errorf("FileReadFilter: error executing template %v with message %v: %v",
fr.tmpl, opack.Message, err)
}
//log.Printf("out=%q", out)
if fh, err = os.Open(out.String()); err != nil {
log.Printf("FileReadFilter: cannot read %q: %v", out, err)
opack.Recycle()
continue
}
out.Reset()
//if _, err = io.Copy(out, io.LimitedReader{R: fh, N: 65000}); err != nil && err != io.EOF {
inp = fh
if fr.decoder != nil {
inp = transform.NewReader(fh, fr.decoder)
}
if _, err = io.Copy(out, inp); err != nil && err != io.EOF {
log.Printf("FileReadFilter: error reading %q: %v", fh.Name(), err)
opack.Recycle()
fh.Close()
continue
}
fh.Close()
npack = h.PipelinePack(opack.MsgLoopCount)
if npack == nil {
opack.Recycle()
return errors.New("FileReadFilter: no output pack - infinite loop?")
}
npack.Decoded = true
npack.Message = message.CopyMessage(opack.Message)
npack.Message.SetType(fr.newType)
npack.Message.SetPayload(npack.Message.GetPayload() + "\n" + out.String())
if !r.Inject(npack) {
log.Printf("FileReadFilter: cannot inject new pack %v", npack)
}
//}
opack.Recycle()
}
return nil
}