mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-05-06 21:52:54 +08:00
fix(region): disk update tag (#23024)
This commit is contained in:
4
go.mod
4
go.mod
@@ -96,12 +96,12 @@ require (
|
||||
k8s.io/cri-api v0.22.17
|
||||
k8s.io/klog/v2 v2.20.0
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250801094022-e2b5a2bf4953
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250806071135-2a78d1b1ef8c
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0
|
||||
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
|
||||
yunion.io/x/pkg v1.10.4-0.20250715170922-d5b8a92716b6
|
||||
yunion.io/x/pkg v1.10.4-0.20250805171825-2431e10f90a9
|
||||
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20250531010554-ce98f840b833
|
||||
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
|
||||
|
||||
8
go.sum
8
go.sum
@@ -1408,8 +1408,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250801094022-e2b5a2bf4953 h1:zOp7bc/faMqWXBtsWoGWa5l/n7PiWxopUnV1WR0K1Q0=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250801094022-e2b5a2bf4953/go.mod h1:FXxAEbdNfWXX9gjME3K2nJhkydHY5EKEUZb+RLEzVwQ=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250806071135-2a78d1b1ef8c h1:tIiyoVwkYXhcu4wCnQLUDiB6NeqkuX92zvPOzB9vYz4=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250806071135-2a78d1b1ef8c/go.mod h1:FXxAEbdNfWXX9gjME3K2nJhkydHY5EKEUZb+RLEzVwQ=
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0 h1:msG4SiDSVU7CrXH06WuHlNEZXIooTcmNbfrIGHuIHBU=
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
@@ -1423,8 +1423,8 @@ yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVB
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc=
|
||||
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v1.10.4-0.20250715170922-d5b8a92716b6 h1:bcvKeB+j9oc1wS7/AjonkUlh+Dl6HSw/hfQuFI2JUXw=
|
||||
yunion.io/x/pkg v1.10.4-0.20250715170922-d5b8a92716b6/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
|
||||
yunion.io/x/pkg v1.10.4-0.20250805171825-2431e10f90a9 h1:8NuoKUPb3sHigChE6Mz6Nf9aZvM/TvORueIZAMYfPK0=
|
||||
yunion.io/x/pkg v1.10.4-0.20250805171825-2431e10f90a9/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
|
||||
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1 h1:1KJ3YYinydPHpDEQRXdr/T8SYcKZ5Er+m489H+PnaQ4=
|
||||
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20250531010554-ce98f840b833 h1:XTFC1naKYkciCQDLm9izpzHXfTenmmtYsTpVKrsN5hE=
|
||||
|
||||
@@ -36,6 +36,10 @@ import (
|
||||
type SBaseHostDriver struct {
|
||||
}
|
||||
|
||||
func (self *SBaseHostDriver) RequestRemoteUpdateDisk(ctx context.Context, userCred mcclient.TokenCredential, storage *models.SStorage, disk *models.SDisk, replaceTags bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SBaseHostDriver) RequestBaremetalUnmaintence(ctx context.Context, userCred mcclient.TokenCredential, baremetal *models.SHost, task taskman.ITask) error {
|
||||
return errors.Wrapf(cloudprovider.ErrNotSupported, "RequestBaremetalUnmaintence")
|
||||
}
|
||||
|
||||
@@ -56,6 +56,10 @@ func (self *SESXiHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb i
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SESXiHostDriver) RequestRemoteUpdateDisk(ctx context.Context, userCred mcclient.TokenCredential, storage *models.SStorage, disk *models.SDisk, replaceTags bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SESXiHostDriver) CheckAndSetCacheImage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storageCache *models.SStoragecache, task taskman.ITask) error {
|
||||
params := task.GetParams()
|
||||
imageId, err := params.GetString("image_id")
|
||||
|
||||
@@ -14,6 +14,55 @@
|
||||
|
||||
package hostdrivers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type SVirtualizationHostDriver struct {
|
||||
SBaseHostDriver
|
||||
}
|
||||
|
||||
func (self *SVirtualizationHostDriver) RequestRemoteUpdateDisk(ctx context.Context, userCred mcclient.TokenCredential, storage *models.SStorage, disk *models.SDisk, replaceTags bool) error {
|
||||
iDisk, err := disk.GetIDisk(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetIDisk")
|
||||
}
|
||||
|
||||
err = func() error {
|
||||
oldTags, err := iDisk.GetTags()
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, "iVM.GetTags()")
|
||||
}
|
||||
tags, err := disk.GetAllUserMetadata()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetAllUserMetadata")
|
||||
}
|
||||
tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags}
|
||||
|
||||
err = cloudprovider.SetTags(ctx, iDisk, storage.ManagerId, tags, replaceTags)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
return nil
|
||||
}
|
||||
logclient.AddSimpleActionLog(disk, logclient.ACT_UPDATE_TAGS, err, userCred, false)
|
||||
return errors.Wrap(err, "iVM.SetTags")
|
||||
}
|
||||
logclient.AddSimpleActionLog(disk, logclient.ACT_UPDATE_TAGS, tagsUpdateInfo, userCred, true)
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -768,12 +768,28 @@ func getDiskResourceRequirements(ctx context.Context, userCred mcclient.TokenCre
|
||||
return req
|
||||
}
|
||||
|
||||
/*func (manager *SDiskManager) convertToBatchCreateData(data jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
diskConfig, _ := data.Get("disk")
|
||||
newData := data.(*jsonutils.JSONDict).CopyExcludes("disk")
|
||||
newData.Add(diskConfig, "disk.0")
|
||||
return newData
|
||||
}*/
|
||||
func (disk *SDisk) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
if len(disk.ExternalId) == 0 || options.Options.KeepTagLocalization {
|
||||
return
|
||||
}
|
||||
err := disk.StartRemoteUpdateTask(ctx, userCred, true, "")
|
||||
if err != nil {
|
||||
log.Errorf("StartRemoteUpdateTask fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (disk *SDisk) StartRemoteUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, replaceTags bool, parentTaskId string) error {
|
||||
data := jsonutils.NewDict()
|
||||
if replaceTags {
|
||||
data.Add(jsonutils.JSONTrue, "replace_tags")
|
||||
}
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "DiskRemoteUpdateTask", disk, userCred, data, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Start DiskRemoteUpdateTask")
|
||||
}
|
||||
disk.SetStatus(ctx, userCred, apis.STATUS_UPDATE_TAGS, "StartRemoteUpdateTask")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (disk *SDisk) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
disk.SVirtualResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
@@ -2423,7 +2439,11 @@ func (self *SDisk) PerformSyncstatus(ctx context.Context, userCred mcclient.Toke
|
||||
return nil, httperrors.NewBadRequestError("Disk has %d task active, can't sync status", count)
|
||||
}
|
||||
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, self, "DiskSyncstatusTask", "")
|
||||
return nil, self.StartSyncstatus(ctx, userCred, "")
|
||||
}
|
||||
|
||||
func (disk *SDisk) StartSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
return StartResourceSyncStatusTask(ctx, userCred, disk, "DiskSyncstatusTask", parentTaskId)
|
||||
}
|
||||
|
||||
func (self *SDisk) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
|
||||
@@ -49,7 +49,7 @@ type IHostDriver interface {
|
||||
// create disk
|
||||
RequestAllocateDiskOnStorage(ctx context.Context, userCred mcclient.TokenCredential, host *SHost, storage *SStorage, disk *SDisk, task taskman.ITask, input api.DiskAllocateInput) error
|
||||
RequestRebuildDiskOnStorage(ctx context.Context, host *SHost, storage *SStorage, disk *SDisk, task taskman.ITask, input api.DiskAllocateInput) error
|
||||
|
||||
RequestRemoteUpdateDisk(ctx context.Context, userCred mcclient.TokenCredential, storage *SStorage, disk *SDisk, replaceTags bool) error
|
||||
// delete disk
|
||||
RequestDeallocateDiskOnHost(ctx context.Context, host *SHost, storage *SStorage, disk *SDisk, cleanSnapshots bool, task taskman.ITask) error
|
||||
RequestDeallocateBackupDiskOnHost(ctx context.Context, host *SHost, storage *SStorage, disk *SDisk, task taskman.ITask) error
|
||||
|
||||
99
pkg/compute/tasks/disk/disk_remote_update_tags_task.go
Normal file
99
pkg/compute/tasks/disk/disk_remote_update_tags_task.go
Normal file
@@ -0,0 +1,99 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type DiskRemoteUpdateTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(DiskRemoteUpdateTask{})
|
||||
}
|
||||
|
||||
func (self *DiskRemoteUpdateTask) taskFail(ctx context.Context, disk *models.SDisk, err error) {
|
||||
disk.SetStatus(ctx, self.UserCred, apis.STATUS_UPDATE_TAGS_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
|
||||
func (self *DiskRemoteUpdateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
disk := obj.(*models.SDisk)
|
||||
|
||||
var host *models.SHost
|
||||
storage, _ := disk.GetStorage()
|
||||
guest := disk.GetGuest()
|
||||
|
||||
if guest != nil {
|
||||
host, _ = guest.GetHost()
|
||||
} else {
|
||||
host, _ = storage.GetMasterHost()
|
||||
}
|
||||
|
||||
reason := "Cannot find host for disk"
|
||||
if host == nil || host.HostStatus != api.HOST_ONLINE {
|
||||
disk.SetStatus(ctx, self.GetUserCred(), api.DISK_READY, reason)
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(reason))
|
||||
logclient.AddActionLogWithStartable(self, disk, logclient.ACT_UPDATE_TAGS, reason, self.UserCred, false)
|
||||
return
|
||||
}
|
||||
|
||||
self.StartRemoteUpdateTask(ctx, host, storage, disk)
|
||||
}
|
||||
|
||||
func (self *DiskRemoteUpdateTask) StartRemoteUpdateTask(ctx context.Context, host *models.SHost, storage *models.SStorage, disk *models.SDisk) {
|
||||
self.SetStage("OnRemoteUpdateComplete", nil)
|
||||
replaceTags := jsonutils.QueryBoolean(self.Params, "replace_tags", false)
|
||||
taskman.LocalTaskRun(self, func() (jsonutils.JSONObject, error) {
|
||||
driver, err := host.GetHostDriver()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetHostDriver")
|
||||
}
|
||||
err = driver.RequestRemoteUpdateDisk(ctx, self.GetUserCred(), storage, disk, replaceTags)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "RequestRemoteUpdateDisk")
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
}
|
||||
|
||||
func (self *DiskRemoteUpdateTask) OnRemoteUpdateComplete(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) {
|
||||
self.SetStage("OnSyncStatusComplete", nil)
|
||||
disk.StartSyncstatus(ctx, self.UserCred, self.GetTaskId())
|
||||
}
|
||||
|
||||
func (self *DiskRemoteUpdateTask) OnRemoteUpdateCompleteFailed(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, disk, errors.Errorf(data.String()))
|
||||
}
|
||||
|
||||
func (self *DiskRemoteUpdateTask) OnSyncStatusComplete(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *DiskRemoteUpdateTask) OnSyncStatusCompleteFailed(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) {
|
||||
self.SetStageFailed(ctx, data)
|
||||
}
|
||||
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@@ -1852,7 +1852,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250801094022-e2b5a2bf4953
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250806071135-2a78d1b1ef8c
|
||||
## explicit; go 1.21
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
@@ -1949,7 +1949,7 @@ yunion.io/x/log/hooks
|
||||
yunion.io/x/ovsdb/cli_util
|
||||
yunion.io/x/ovsdb/schema/ovn_nb
|
||||
yunion.io/x/ovsdb/types
|
||||
# yunion.io/x/pkg v1.10.4-0.20250715170922-d5b8a92716b6
|
||||
# yunion.io/x/pkg v1.10.4-0.20250805171825-2431e10f90a9
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/pkg/appctx
|
||||
yunion.io/x/pkg/errors
|
||||
|
||||
4
vendor/yunion.io/x/cloudmux/pkg/multicloud/aliyun/disk.go
generated
vendored
4
vendor/yunion.io/x/cloudmux/pkg/multicloud/aliyun/disk.go
generated
vendored
@@ -164,6 +164,10 @@ func (self *SDisk) ChangeBillingType(billingType string) error {
|
||||
return self.storage.zone.region.ChangeDiskChargeType(self.InstanceId, self.DiskId, billingType)
|
||||
}
|
||||
|
||||
func (self *SDisk) SetTags(tags map[string]string, replace bool) error {
|
||||
return self.storage.zone.region.SetResourceTags(ALIYUN_SERVICE_ECS, "disk", self.DiskId, tags, replace)
|
||||
}
|
||||
|
||||
func (self *SRegion) ChangeDiskChargeType(vmId, diskId string, billingType string) error {
|
||||
params := make(map[string]string)
|
||||
params["RegionId"] = self.RegionId
|
||||
|
||||
4
vendor/yunion.io/x/cloudmux/pkg/multicloud/aws/disk.go
generated
vendored
4
vendor/yunion.io/x/cloudmux/pkg/multicloud/aws/disk.go
generated
vendored
@@ -198,6 +198,10 @@ func (self *SDisk) Delete(ctx context.Context) error {
|
||||
return self.storage.zone.region.DeleteDisk(self.VolumeId)
|
||||
}
|
||||
|
||||
func (self *SDisk) SetTags(tags map[string]string, replace bool) error {
|
||||
return self.storage.zone.region.setTags("volume", self.VolumeId, tags, replace)
|
||||
}
|
||||
|
||||
func (self *SDisk) CreateISnapshot(ctx context.Context, name string, desc string) (cloudprovider.ICloudSnapshot, error) {
|
||||
snapshot, err := self.storage.zone.region.CreateSnapshot(self.VolumeId, name, desc)
|
||||
if err != nil {
|
||||
|
||||
4
vendor/yunion.io/x/cloudmux/pkg/multicloud/qcloud/disk.go
generated
vendored
4
vendor/yunion.io/x/cloudmux/pkg/multicloud/qcloud/disk.go
generated
vendored
@@ -312,6 +312,10 @@ func (self *SDisk) GetExpiredAt() time.Time {
|
||||
return self.DeadlineTime.Add(time.Hour * -8)
|
||||
}
|
||||
|
||||
func (self *SDisk) SetTags(tags map[string]string, replace bool) error {
|
||||
return self.storage.zone.region.SetResourceTags("cvm", "volume", []string{self.DiskId}, tags, replace)
|
||||
}
|
||||
|
||||
func (self *SDisk) GetISnapshot(snapshotId string) (cloudprovider.ICloudSnapshot, error) {
|
||||
snapshots, total, err := self.storage.zone.region.GetSnapshots("", "", "", []string{snapshotId}, 0, 1)
|
||||
if err != nil {
|
||||
|
||||
14
vendor/yunion.io/x/pkg/util/httputils/httputils.go
generated
vendored
14
vendor/yunion.io/x/pkg/util/httputils/httputils.go
generated
vendored
@@ -284,13 +284,13 @@ func GetAddrPort(urlStr string) (string, int, error) {
|
||||
return "", 0, err
|
||||
}
|
||||
host := parts.Host
|
||||
commaPos := strings.IndexByte(host, ':')
|
||||
if commaPos > 0 {
|
||||
port, err := strconv.ParseInt(host[commaPos+1:], 10, 32)
|
||||
hostAddr, hostPortStr, err := net.SplitHostPort(host)
|
||||
if err == nil {
|
||||
hostPort, err := strconv.ParseInt(hostPortStr, 10, 32)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
return "", 0, errors.Wrapf(err, "strconv.ParseInt port string %s", hostPortStr)
|
||||
} else {
|
||||
return host[:commaPos], int(port), nil
|
||||
return hostAddr, int(hostPort), nil
|
||||
}
|
||||
} else {
|
||||
switch parts.Scheme {
|
||||
@@ -299,7 +299,7 @@ func GetAddrPort(urlStr string) (string, int, error) {
|
||||
case "https":
|
||||
return parts.Host, 443, nil
|
||||
default:
|
||||
return "", 0, fmt.Errorf("Unknown schema %s", parts.Scheme)
|
||||
return "", 0, errors.Wrapf(errors.ErrInvalidFormat, "Unknown schema %s", parts.Scheme)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -515,7 +515,7 @@ func request(client sClient, ctx context.Context, method THttpMethod, urlStr str
|
||||
var reqBody string
|
||||
if bodySeeker, ok := body.(io.ReadSeeker); ok {
|
||||
bodySeeker.Seek(0, io.SeekStart)
|
||||
reqBodyBytes, _ := ioutil.ReadAll(bodySeeker)
|
||||
reqBodyBytes, _ := io.ReadAll(bodySeeker)
|
||||
if reqBodyBytes != nil {
|
||||
reqBody = string(reqBodyBytes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user