| @@ -15,7 +15,7 @@ type HubGetHubsReq struct { | |||
| } | |||
| type HubGetHubsResp struct { | |||
| Hubs []cdssdk.Hub `json:"hubs"` | |||
| Hubs []*cdssdk.Hub `json:"hubs"` | |||
| } | |||
| func (c *Client) HubGetHubs(req HubGetHubsReq) (*HubGetHubsResp, error) { | |||
| @@ -135,15 +135,15 @@ type PackageCreateLoad struct { | |||
| Files UploadObjectIterator `json:"-"` | |||
| } | |||
| type PackageCreateLoadInfo struct { | |||
| UserID cdssdk.UserID `json:"userID" binding:"required"` | |||
| BucketID cdssdk.BucketID `json:"bucketID" binding:"required"` | |||
| Name string `json:"name" binding:"required"` | |||
| LoadTo []cdssdk.StorageID `json:"loadTo" binding:"required"` | |||
| UserID cdssdk.UserID `json:"userID" binding:"required"` | |||
| BucketID cdssdk.BucketID `json:"bucketID" binding:"required"` | |||
| Name string `json:"name" binding:"required"` | |||
| LoadTo []cdssdk.StorageID `json:"loadTo"` | |||
| LoadToPath []string `json:"loadToPath"` | |||
| } | |||
| type PackageCreateLoadResp struct { | |||
| Package cdssdk.Package `json:"package"` | |||
| Objects []cdssdk.Object `json:"objects"` | |||
| LoadedDirs []string `json:"loadedDirs"` | |||
| Package cdssdk.Package `json:"package"` | |||
| Objects []cdssdk.Object `json:"objects"` | |||
| } | |||
| func (c *PackageService) CreateLoad(req PackageCreateLoad) (*PackageCreateLoadResp, error) { | |||
| @@ -329,38 +329,3 @@ func (c *PackageService) GetCachedStorages(req PackageGetCachedStoragesReq) (*Pa | |||
| return nil, codeResp.ToError() | |||
| } | |||
| const PackageGetLoadedStoragesPath = "/package/getLoadedStorages" | |||
| type PackageGetLoadedStoragesReq struct { | |||
| PackageID cdssdk.PackageID `form:"packageID" json:"packageID" binding:"required"` | |||
| UserID cdssdk.UserID `form:"userID" json:"userID" binding:"required"` | |||
| } | |||
| type PackageGetLoadedStoragesResp struct { | |||
| StorageIDs []cdssdk.StorageID `json:"storageIDs"` | |||
| } | |||
| func (c *PackageService) GetLoadedStorages(req PackageGetLoadedStoragesReq) (*PackageGetLoadedStoragesResp, error) { | |||
| url, err := url.JoinPath(c.baseURL, PackageGetLoadedStoragesPath) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| resp, err := http2.GetJSON(url, http2.RequestParam{ | |||
| Query: req, | |||
| }) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| codeResp, err := ParseJSONResponse[response[PackageGetLoadedStoragesResp]](resp) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| if codeResp.Code == errorcode.OK { | |||
| return &codeResp.Data, nil | |||
| } | |||
| return nil, codeResp.ToError() | |||
| } | |||
| @@ -17,13 +17,9 @@ type StorageLoadPackageReq struct { | |||
| UserID cdssdk.UserID `json:"userID" binding:"required"` | |||
| PackageID cdssdk.PackageID `json:"packageID" binding:"required"` | |||
| StorageID cdssdk.StorageID `json:"storageID" binding:"required"` | |||
| RootPath string `json:"rootPath"` | |||
| } | |||
| type StorageLoadPackageResp struct { | |||
| FullPath string `json:"fullPath"` // TODO 临时保留给中期测试的前端使用,后续会删除 | |||
| PackagePath string `json:"packagePath"` | |||
| LocalBase string `json:"localBase"` | |||
| RemoteBase string `json:"remoteBase"` | |||
| } | |||
| type StorageLoadPackageResp struct{} | |||
| func (c *Client) StorageLoadPackage(req StorageLoadPackageReq) (*StorageLoadPackageResp, error) { | |||
| url, err := url.JoinPath(c.baseURL, StorageLoadPackagePath) | |||
| @@ -245,24 +245,3 @@ func Test_Cache(t *testing.T) { | |||
| So(err, ShouldBeNil) | |||
| }) | |||
| } | |||
| func Test_GetHubInfos(t *testing.T) { | |||
| Convey("测试获取hub信息", t, func() { | |||
| cli := NewClient(&Config{ | |||
| URL: "http://localhost:7890", | |||
| }) | |||
| resp1, err := cli.Package().GetCachedStorages(PackageGetCachedStoragesReq{ | |||
| PackageID: 11, | |||
| UserID: 1, | |||
| }) | |||
| So(err, ShouldBeNil) | |||
| fmt.Printf("resp1: %v\n", resp1) | |||
| resp2, err := cli.Package().GetLoadedStorages(PackageGetLoadedStoragesReq{ | |||
| PackageID: 11, | |||
| UserID: 1, | |||
| }) | |||
| So(err, ShouldBeNil) | |||
| fmt.Printf("resp2: %v\n", resp2) | |||
| }) | |||
| } | |||
| @@ -327,7 +327,7 @@ func (Bucket) TableName() string { | |||
| type HubConnectivity struct { | |||
| FromHubID HubID `gorm:"column:FromHubID; primaryKey; type:bigint" json:"fromHubID"` | |||
| ToHubID HubID `gorm:"column:ToHubID; primaryKey; type:bigint" json:"ToHubID"` | |||
| Delay *float32 `gorm:"column:Delay; type:float" json:"delay"` | |||
| Latency *float32 `gorm:"column:Latency; type:float" json:"latency"` | |||
| TestTime time.Time `gorm:"column:TestTime; type:datetime" json:"testTime"` | |||
| } | |||
| @@ -0,0 +1,99 @@ | |||
| package math2 | |||
| type Range struct { | |||
| Offset int64 | |||
| Length *int64 | |||
| } | |||
| // length为-1时Range.Length为nil | |||
| func NewRange(offset int64, length int64) Range { | |||
| if length == -1 { | |||
| return Range{Offset: offset, Length: nil} | |||
| } | |||
| return Range{Offset: offset, Length: &length} | |||
| } | |||
| // 不包含end | |||
| func RangeFromStartEnd(start int64, end int64) Range { | |||
| length := end - start | |||
| return Range{Offset: start, Length: &length} | |||
| } | |||
| // 给Length设置一个具体值 | |||
| func (r *Range) Fix(totalLen int64) { | |||
| len := totalLen - r.Offset | |||
| r.Length = &len | |||
| } | |||
| // 如果Length为nil,则end为-1 | |||
| func (r *Range) ToStartEnd() (start int64, end int64) { | |||
| if r.Length == nil { | |||
| return r.Offset, -1 | |||
| } | |||
| end = r.Offset + *r.Length | |||
| return r.Offset, end | |||
| } | |||
| // 将范围限制在totalLen内。会同时设置Length的值 | |||
| func (r *Range) Clamp(totalLen int64) { | |||
| r.Offset = Min(r.Offset, totalLen) | |||
| if r.Length == nil { | |||
| len := totalLen - r.Offset | |||
| r.Length = &len | |||
| } else { | |||
| *r.Length = Min(*r.Length, totalLen-r.Offset) | |||
| } | |||
| } | |||
| func (r *Range) Extend(other Range) { | |||
| newOffset := Min(r.Offset, other.Offset) | |||
| if r.Length == nil { | |||
| r.Offset = newOffset | |||
| return | |||
| } | |||
| if other.Length == nil { | |||
| r.Offset = newOffset | |||
| r.Length = nil | |||
| return | |||
| } | |||
| otherEnd := other.Offset + *other.Length | |||
| rEnd := r.Offset + *r.Length | |||
| newEnd := Max(otherEnd, rEnd) | |||
| r.Offset = newOffset | |||
| *r.Length = newEnd - newOffset | |||
| } | |||
| func (r *Range) ExtendStart(start int64) { | |||
| r.Offset = Min(r.Offset, start) | |||
| } | |||
| func (r *Range) ExtendEnd(end int64) { | |||
| if r.Length == nil { | |||
| return | |||
| } | |||
| rEnd := r.Offset + *r.Length | |||
| newLen := Max(end, rEnd) - r.Offset | |||
| r.Length = &newLen | |||
| } | |||
| func (r *Range) Equals(other Range) bool { | |||
| if r.Offset != other.Offset { | |||
| return false | |||
| } | |||
| if r.Length == nil && other.Length == nil { | |||
| return true | |||
| } | |||
| if r.Length == nil || other.Length == nil { | |||
| return false | |||
| } | |||
| return *r.Length == *other.Length | |||
| } | |||