package history import ( "fmt" "time" ) const ( ERROR = "ERROR" INFO = "INFO" ) type History struct { ID uint `gorm:"primaryKey"` CreatedAt time.Time Module string Type string Message string Body string Issuer string Caller string Trace string } var Tunnel chan *History var quit chan struct{} func init() { Tunnel = make(chan *History) quit = make(chan struct{}, 1) } func Start(r Receiver) { go func() { for { select { case h := <-Tunnel: r(h) case <-quit: return } } }() } func Stop() { quit <- struct{}{} } func Send(h *History) { Tunnel <- h } type Receiver func(*History) var DBReceiver Receiver = func(h *History) { } var ConsoleReceiver Receiver = func(h *History) { fmt.Printf("%+v\n", h) }