Refactoring
This commit is contained in:
45
pkg/cloudapi/flipgroup/compute_add.go
Normal file
45
pkg/cloudapi/flipgroup/compute_add.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package flipgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ComputeAddRequest struct {
|
||||
FlipGroupID uint64 `url:"flipgroupId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (frq ComputeAddRequest) Validate() error {
|
||||
if frq.FlipGroupID == 0 {
|
||||
return errors.New("field FlipGroupID can not be empty or equal to 0")
|
||||
}
|
||||
if frq.ComputeID == 0 {
|
||||
return errors.New("field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f FlipGroup) ComputeAdd(ctx context.Context, req ComputeAddRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/flipgroup/computeAdd"
|
||||
res, err := f.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user