From b232685b63175cdde1dee8980b1afc6b1810e0c0 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Thu, 16 Dec 2021 14:25:57 +0800 Subject: [PATCH] save --- history/history.go | 58 +++++++++++++++++++++++++++++++++++++++++ history/history_test.go | 10 +++++++ messenger/messenger.go | 5 ++++ system/setup.go | 1 + system/system.go | 2 +- 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 history/history.go create mode 100644 history/history_test.go create mode 100644 messenger/messenger.go diff --git a/history/history.go b/history/history.go new file mode 100644 index 0000000..99af2d1 --- /dev/null +++ b/history/history.go @@ -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) +} diff --git a/history/history_test.go b/history/history_test.go new file mode 100644 index 0000000..e522f6b --- /dev/null +++ b/history/history_test.go @@ -0,0 +1,10 @@ +package history + +import ( + "testing" + "time" +) + +func TestHistory(t *testing.T) { + time.Sleep(time.Second * 30) +} diff --git a/messenger/messenger.go b/messenger/messenger.go new file mode 100644 index 0000000..8393a7d --- /dev/null +++ b/messenger/messenger.go @@ -0,0 +1,5 @@ +package messenger + +func init() { + +} diff --git a/system/setup.go b/system/setup.go index 753f44e..e2d099f 100644 --- a/system/setup.go +++ b/system/setup.go @@ -42,6 +42,7 @@ func init() { viper.SetEnvKeyReplacer(replacer) viper.AutomaticEnv() viper.SetConfigType("json") + setup() } func setup() { diff --git a/system/system.go b/system/system.go index 01fea71..c6302a9 100644 --- a/system/system.go +++ b/system/system.go @@ -98,7 +98,7 @@ func New() *System { } func (sys *System) Start() { - setup() + // setup() sys.order() sys.status = sys_init go func() {