JCS-pub/client/sdk/api/v1/pub_shards.go

73 lines
2.0 KiB
Go

package api
import (
"net/http"
"gitlink.org.cn/cloudream/common/sdks"
jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
)
type PubShardsService struct {
*Client
}
func (c *Client) PubShards() *PubShardsService {
return &PubShardsService{
Client: c,
}
}
const PubShardsCreatePath = "/pubShards/create"
type PubShardsCreate struct {
Name string `json:"name"`
Storage jcstypes.StorageType `json:"storage"`
Credential jcstypes.StorageCredential `json:"credential"`
ShardStore jcstypes.ShardStoreUserConfig `json:"shardStore"`
Features []jcstypes.StorageFeature `json:"features"`
WorkingDir string `json:"workingDir"`
Password string `json:"password"`
MasterHub jcstypes.HubID `json:"masterHub"`
}
func (r *PubShardsCreate) MakeParam() *sdks.RequestParam {
return sdks.MakeJSONParam(http.MethodPost, PubShardsCreatePath, r)
}
type PubShardsCreateResp struct {
PubShards jcstypes.PubShards `json:"pubShards"`
}
func (r *PubShardsCreateResp) ParseResponse(resp *http.Response) error {
return sdks.ParseCodeDataJSONResponse(resp, r)
}
func (c *PubShardsService) Create(req PubShardsCreate) (*PubShardsCreateResp, error) {
return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsCreateResp{})
}
const PubShardsJoinPath = "/pubShards/join"
type PubShardsJoin struct {
Name string `json:"name"`
PubShardsID jcstypes.PubShardsID `json:"pubShardID"`
Password string `json:"password"`
}
func (r *PubShardsJoin) MakeParam() *sdks.RequestParam {
return sdks.MakeJSONParam(http.MethodPost, PubShardsJoinPath, r)
}
type PubShardsJoinResp struct {
PubShards jcstypes.PubShards `json:"pubShards"`
UserSpace jcstypes.UserSpace `json:"userSpace"`
}
func (r *PubShardsJoinResp) ParseResponse(resp *http.Response) error {
return sdks.ParseCodeDataJSONResponse(resp, r)
}
func (c *PubShardsService) Join(req PubShardsJoin) (*PubShardsJoinResp, error) {
return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsJoinResp{})
}