master
zggsong 2 years ago
parent 0b870a850e
commit 8d7a325d0a

@ -2,3 +2,14 @@
用golang实现读取配置发送消息 用golang实现读取配置发送消息
支持自动刷新配置文件 支持自动刷新配置文件
# debug
- 非 debug 入口文件行首添加 `//go:build !debug`
- debug 入口文件行首添加 `//go:build debug`
```shell
go build -tags "debug"
go run main_debug.go
```

@ -1,3 +1,5 @@
//go:build !debug
package main package main
import ( import (

@ -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()
}

@ -2,9 +2,9 @@ package message
import ( import (
"bytes" "bytes"
"message-demo/global"
"encoding/json" "encoding/json"
"log" "log"
"message-demo/global"
"net/http" "net/http"
) )
@ -27,12 +27,10 @@ func initBark() {
func (m Bark) Send(message MessageBody) { func (m Bark) Send(message MessageBody) {
log.Println("[bark] Sending by bark...") log.Println("[bark] Sending by bark...")
var reqBody = Request{ var reqBody = Request{
//Badge: 2,
DeviceKey: b.key, DeviceKey: b.key,
Title: message.Title, Title: message.Title,
Body: message.Content, 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) req, _ := json.Marshal(reqBody)
resp, err := http.Post(m.url, "application/json; charset=utf-8", bytes.NewReader(req)) resp, err := http.Post(m.url, "application/json; charset=utf-8", bytes.NewReader(req))

Loading…
Cancel
Save