更新推送方式
All checks were successful
代码更新通知 / update-server (push) Successful in 3s

This commit is contained in:
2024-12-18 17:46:37 +08:00
parent cf91676e99
commit 3df77f624a
3 changed files with 111 additions and 57 deletions

43
main.go
View File

@@ -2,13 +2,12 @@ package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/duke-git/lancet/v2/strutil"
"github.com/golang-cz/devslog"
"github.com/gotify/go-api-client/v2/auth"
"github.com/gotify/go-api-client/v2/client/message"
"github.com/gotify/go-api-client/v2/gotify"
"github.com/gotify/go-api-client/v2/models"
"github.com/imroc/req/v3"
"github.com/sethvargo/go-githubactions"
"github.com/spf13/cast"
"log"
@@ -106,17 +105,37 @@ func doPush() error {
func pushMessage(parsedURL *url.URL, token string, msg *models.MessageExternal) error {
client := gotify.NewClient(parsedURL, &http.Client{})
params := message.NewCreateMessageParams()
params.SetBody(msg)
res, err := client.Message.CreateMessage(params, auth.TokenAuth(token))
if err == nil {
logger.Info("推送结果", slog.Any("result", res))
return nil
} else {
res, err := req.R().
SetBodyJsonMarshal(msg).
SetQueryParam("token", token).
Post(parsedURL.String() + "/message")
if err != nil {
return err
}
var body string
if body, err = res.ToString(); err != nil {
slog.Error("解析结果失败", slog.Any("err", err))
return err
}
slog.Info("推送结果", slog.String("result", body))
if res.GetStatusCode() != http.StatusOK {
return errors.New(body)
}
return nil
//client := gotify.NewClient(parsedURL, &http.Client{})
//
//params := message.NewCreateMessageParams()
//params.SetBody(msg)
//res, err := client.Message.CreateMessage(params, auth.TokenAuth(token))
//if err == nil {
// logger.Info("推送结果", slog.Any("result", res))
// return nil
//} else {
// return err
//}
}
func getExtraMsg(ctx *githubactions.GitHubContext) (result string) {