feat: update basic send function

main
ZGGSONG 2 years ago
parent 5d66434e11
commit b480e0daf0

@ -1,5 +1,43 @@
package main package main
import (
"log"
"sendmsg/config"
"sendmsg/global"
"sendmsg/message"
"sendmsg/model"
"sendmsg/service"
"time"
)
func init() {
global.GLO_CONF_CH = make(chan model.Config)
_conf, err := config.InitConfig()
if err != nil {
log.Fatalf("[init] Failed to initialize config: %v", err)
}
global.GLO_CONF = _conf
}
func main() { func main() {
//test
go func() {
var count int
for {
if count > 5 {
return
}
count++
var s = service.Service{Body: message.Body{
Title: "test title",
Content: "this is content, time is " + time.Now().Format("2006-01-02 15:04:05"),
}}
s.Run()
time.Sleep(time.Second * 2)
}
}()
for {
_conf := <-global.GLO_CONF_CH
global.GLO_CONF = _conf
}
} }

@ -5,6 +5,7 @@ import (
"sendmsg/config" "sendmsg/config"
"sendmsg/global" "sendmsg/global"
"testing" "testing"
"time"
) )
func TestSend(t *testing.T) { func TestSend(t *testing.T) {
@ -20,6 +21,6 @@ func TestSend(t *testing.T) {
} }
m.Send(Body{ m.Send(Body{
Title: "Hello", Title: "Hello",
Content: "World", Content: "World " + time.Now().Format("2006-01-02 15:04:05"),
}) })
} }

@ -5,11 +5,13 @@ import (
"sendmsg/message" "sendmsg/message"
) )
type Support struct{} type Service struct {
Body message.Body
func (s Support) Run() { }
log.Printf("[support] start excute...")
func (s Service) Run() {
log.Printf("[service] start excute...")
send(s.Body)
} }
func send(body message.Body) { func send(body message.Body) {

@ -0,0 +1,22 @@
package service
import (
"sendmsg/config"
"sendmsg/global"
"sendmsg/message"
"testing"
"time"
)
func TestService(t *testing.T) {
conf, err := config.InitConfig()
if err != nil {
t.Fatalf("Failed to initialize config: %v", err)
}
global.GLO_CONF = conf
var s = Service{Body: message.Body{
Title: "test title",
Content: "this is content, time is " + time.Now().Format("2006-01-02 15:04:05"),
}}
s.Run()
}
Loading…
Cancel
Save