Esempio n. 1
0
// ChunkFileScanAdaptor provides a Stacks for parser.Parser
func ChunkFileScanAdaptor() flux.Reactor {
	return flux.Reactive(func(v flux.Reactor, err error, d interface{}) {
		if err != nil {
			v.ReplyError(err)
			return
		}
		var data string
		var ok bool

		if data, ok = d.(string); !ok {
			v.ReplyError(ErrInputTytpe)
			return
		}

		var fs *os.File

		if fs, err = os.Open(data); err != nil {
			v.ReplyError(err)
			return
		}

		if err = parser.ScanChunks(parser.NewScanner(fs), func(query string) {
			v.Reply(query)
		}); err != nil {
			v.ReplyError(err)
		}
	})
}
Esempio n. 2
0
// ChunkScanAdaptor provides a Stacks for parser.Parser and scans strings inputs for query
func ChunkScanAdaptor() flux.Reactor {
	return flux.Reactive(func(v flux.Reactor, err error, d interface{}) {
		if err != nil {
			v.ReplyError(err)
			return
		}

		var data string
		var ok bool

		if data, ok = d.(string); !ok {
			v.ReplyError(ErrInputTytpe)
			return
		}

		scan := parser.NewScanner(bytes.NewBufferString(data))

		if err = parser.ScanChunks(scan, func(query string) {
			v.Reply(query)
		}); err != nil {
			v.ReplyError(err)
		}
	})
}