Refactoring
This commit is contained in:
37
pkg/cloudapi/rg/enable.go
Normal file
37
pkg/cloudapi/rg/enable.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type EnableRequest struct {
|
||||
RGID uint64 `url:"rgId"`
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq EnableRequest) Validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r RG) Enable(ctx context.Context, req EnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/enable"
|
||||
res, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
||||
Reference in New Issue
Block a user