1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
package apis
import (
"fmt"
"github.com/mimuret/golang-iij-dpf/pkg/api"
"github.com/mimuret/golang-iij-dpf/pkg/utils"
)
type Params interface {
SetPathParams(...interface{}) error
}
// for ctl.
func SetPathParams(args []interface{}, ids ...interface{}) error {
if len(args) == 0 {
return nil
}
if len(args) != len(ids) {
return fmt.Errorf("SetPathParams: args need %d items, but args len is %d", len(ids), len(args))
}
for i := range ids {
switch v := ids[i].(type) {
case *int64:
val, err := utils.ToInt64(args[i])
if err != nil {
return fmt.Errorf("failed to cast to int64 `%s`: %w", args[i], err)
}
*v = val
case *string:
val, err := utils.ToString(args[i])
if err != nil {
return fmt.Errorf("failed to cast to string `%s`: %w", args[i], err)
}
*v = val
default:
panic(fmt.Sprintf("ids[%d] is not int64 or string", i))
}
}
return nil
}
type Spec interface {
api.Spec
Params
}
type ListSpec interface {
api.ListSpec
Spec
}
type CountableListSpec interface {
api.CountableListSpec
Spec
}
|