diff --git a/README.md b/README.md index d8f6188..8703a36 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,15 @@ # message-demo 用golang实现读取配置发送消息 -支持自动刷新配置文件 \ No newline at end of file +支持自动刷新配置文件 + +# debug + +- 非 debug 入口文件行首添加 `//go:build !debug` +- debug 入口文件行首添加 `//go:build debug` + +```shell +go build -tags "debug" + +go run main_debug.go +``` \ No newline at end of file diff --git a/main.go b/main.go index 5c4dd7b..6c81012 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,5 @@ +//go:build !debug + package main import ( diff --git a/main_debug.go b/main_debug.go new file mode 100644 index 0000000..a3ae90b --- /dev/null +++ b/main_debug.go @@ -0,0 +1,40 @@ +//go:build debug + +package main + +import ( + "encoding/json" + "log" + "math/rand" + "message-demo/config" + "message-demo/global" + "message-demo/model" + "message-demo/support" +) + +// 部分代码参考: https://github.com/hb0730/auto-sign + +func init() { + global.GLO_CONF_CH = make(chan model.Config) + global.GLO_CONF = config.InitialConfig() + bytes, _ := json.Marshal(global.GLO_CONF) + log.Println(string(bytes)) +} + +func main() { + send() + for { + global.GLO_CONF = <-global.GLO_CONF_CH + bytes, _ := json.Marshal(global.GLO_CONF) + log.Println(string(bytes)) + send() + } +} + +func send() { + var s support.Support + tests := []string{"debug_test1", "debug_test2", "debug_test4", "debug_test5", "debug_test6", "debug_test7"} + num := rand.Intn(5) + s.Name = tests[num] + s.Run() +} diff --git a/message/bark.go b/message/bark.go index 32b82e5..b56db96 100644 --- a/message/bark.go +++ b/message/bark.go @@ -2,9 +2,9 @@ package message import ( "bytes" - "message-demo/global" "encoding/json" "log" + "message-demo/global" "net/http" ) @@ -27,12 +27,10 @@ func initBark() { func (m Bark) Send(message MessageBody) { log.Println("[bark] Sending by bark...") var reqBody = Request{ - //Badge: 2, DeviceKey: b.key, Title: message.Title, Body: message.Content, - Icon: "https://m.luxshare-ict.com/favicon.ico", - Url: "https:////github.com/zggsong", + // Url: "https:////github.com/zggsong", } req, _ := json.Marshal(reqBody) resp, err := http.Post(m.url, "application/json; charset=utf-8", bytes.NewReader(req))