Evan Chen 2021-12-16 14:25:57 +08:00
parent 0b0917b877
commit b232685b63
5 changed files with 75 additions and 1 deletions

58
history/history.go Normal file
View File

@ -0,0 +1,58 @@
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)
}

10
history/history_test.go Normal file
View File

@ -0,0 +1,10 @@
package history
import (
"testing"
"time"
)
func TestHistory(t *testing.T) {
time.Sleep(time.Second * 30)
}

5
messenger/messenger.go Normal file
View File

@ -0,0 +1,5 @@
package messenger
func init() {
}

View File

@ -42,6 +42,7 @@ func init() {
viper.SetEnvKeyReplacer(replacer)
viper.AutomaticEnv()
viper.SetConfigType("json")
setup()
}
func setup() {

View File

@ -98,7 +98,7 @@ func New() *System {
}
func (sys *System) Start() {
setup()
// setup()
sys.order()
sys.status = sys_init
go func() {