-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker-plugin.go
43 lines (42 loc) · 1.14 KB
/
worker-plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package ouretl
// WorkerPlugin defines a worker (or ETL `source`) that's always
// running, under ouretl-core. A worker plugin can choose
// to publish messages into the plugin pipeline, using
// the provided `target` function.
//
// Example:
// -----
// package main
//
// type pluginDef struct{
// portNumber string
// }
//
// func GetWorker(_ ouretl.Config, settings ouretl.PluginSettings) (ouretl.WorkerPlugin, error) {
// return &pluginDef{
// portNumber: settings.Get("PortSettings"),
// }
// }
//
// func (def *pluginDef) Start(target func([]byte)) error {
// router := httprouter.New()
// router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
// defer r.Body.Close()
//
// message, err := ioutil.ReadAll(r.Body)
// if err != nil {
// w.WriteHeader(http.StatusBadRequest)
// return
// }
//
// target(message)
// w.WriteHeader(http.StatusAccepted)
// })
//
// addr := fmt.Sprintf(":%s", def.portNumber)
// return http.ListenAndServe(addr, router)
// }
// -----
type WorkerPlugin interface {
Start(func([]byte)) error
}