🎨 自动添加http前缀到baseUrl以确保URL格式正确

This commit is contained in:
李寻欢 2025-04-18 11:28:40 +08:00
parent ba4b5792f7
commit 578531cb13

View File

@ -13,6 +13,7 @@ import (
"gitee.ltd/lxh/xybot/user"
"github.com/go-resty/resty/v2"
"slices"
"strings"
)
type Client struct {
@ -43,6 +44,10 @@ func NewClient(wxId, baseUrl string, debug bool) (cli *Client, err error) {
err = errors.New("baseUrl 不得为空,格式为: http://10.0.0.11:9001")
return
}
// 如果URL没有以http://或https://开头自动添加http://
if !strings.HasPrefix(baseUrl, "http://") && !strings.HasPrefix(baseUrl, "https://") {
baseUrl = "http://" + baseUrl
}
// 设置一下机器人微信Id的值
core.WxId = wxId