mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-18 17:46:37 +08:00
- Updated error handling across multiple files with `Laisky/errors/v2` package - Replaced hardcoded error messages with `Laisky/errors` in relay/channel/tencent/adaptor.go - Added a function to check if a request should be retried in relay/controller/relay.go - Removed unused imports and variables, and updated comments in various files - Changed Redis cache handling in model/cache.go - Refactored error handling in relay/channel/tencent/main.go and relay/channel/baidu/main.go - Updated import paths and error handling in model/user.go, model/redemption.go, and controller/github.go - Added import for tiktoken-go package in relay/channel/openai/token.go - Added GetSign and ParseConfig functions in relay/channel/tencent/main.go - Replaced specific error imports with a more general one in relay/channel/ali/adaptor.go - Updated import comments and function calls in relay/channel/ali/adaptor.go - Added checks and custom error messages in model/token.go - Removed unused functions and variables in relay/channel/baidu/adaptor.go - Imported "github.com/Laisky/errors/v2" package in controller/channel-billing.go - Removed unused import packages in [relay/channel/tencent/adaptor.go](http://relay/channel/tencent/adaptor.go) and relay/channel/palm/adaptor.go - Updated go.mod and go.sum files with new dependencies and versions
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package message
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"github.com/Laisky/errors/v2"
|
|
"github.com/songquanpeng/one-api/common/config"
|
|
"net/http"
|
|
)
|
|
|
|
type request struct {
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Content string `json:"content"`
|
|
URL string `json:"url"`
|
|
Channel string `json:"channel"`
|
|
Token string `json:"token"`
|
|
}
|
|
|
|
type response struct {
|
|
Success bool `json:"success"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
func SendMessage(title string, description string, content string) error {
|
|
if config.MessagePusherAddress == "" {
|
|
return errors.New("message pusher address is not set")
|
|
}
|
|
req := request{
|
|
Title: title,
|
|
Description: description,
|
|
Content: content,
|
|
Token: config.MessagePusherToken,
|
|
}
|
|
data, err := json.Marshal(req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
resp, err := http.Post(config.MessagePusherAddress,
|
|
"application/json", bytes.NewBuffer(data))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var res response
|
|
err = json.NewDecoder(resp.Body).Decode(&res)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !res.Success {
|
|
return errors.New(res.Message)
|
|
}
|
|
return nil
|
|
}
|