This commit is contained in:
43
main.go
43
main.go
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user