-
Notifications
You must be signed in to change notification settings - Fork 3
/
input.go
50 lines (42 loc) · 1007 Bytes
/
input.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
44
45
46
47
48
49
50
package inputs
import (
"log"
"reflect"
"github.com/hexbotio/hex/models"
)
// Input interface
type Input interface {
Read(inputMsgs chan<- models.Message, service models.Service)
}
// List of Inputs
var List = make(map[string]reflect.Type)
func init() {
List["cli"] = reflect.TypeOf(Cli{})
List["file"] = reflect.TypeOf(File{})
List["rss"] = reflect.TypeOf(Rss{})
List["scheduler"] = reflect.TypeOf(Scheduler{})
List["slack"] = reflect.TypeOf(Slack{})
List["twitter"] = reflect.TypeOf(Twitter{})
List["webhook"] = reflect.TypeOf(Webhook{})
}
// Exists function
func Exists(connType string) (exists bool) {
_, exists = List[connType]
return exists
}
// MakeService
func Make(connType string) interface{} {
if ct, ok := List[connType]; ok {
c := (reflect.New(ct).Elem().Interface())
return c
} else {
return nil
}
}
// Recovery
func Recovery(service models.Service) {
msg := "Panic - " + service.Name + " " + service.Type
if r := recover(); r != nil {
log.Print(msg, r)
}
}