app/history/history.go

59 lines
714 B
Go

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{})
}
func Start(r Receiver) {
go func() {
select {
case h := <-Tunnel:
r(h)
case <-quit:
return
}
}()
}
func Stop() {
quit <- struct{}{}
}
type Receiver func(*History)
var DBReceiver Receiver = func(h *History) {
}
var ConsoleReceiver Receiver = func(h *History) {
fmt.Printf("%+v\n", h)
}