spec.go raw

   1  package api
   2  
   3  import (
   4  	"reflect"
   5  )
   6  
   7  type Object interface {
   8  	DeepCopyObject() Object
   9  }
  10  
  11  type Spec interface {
  12  	Object
  13  	GetName() string
  14  	GetGroup() string
  15  	GetPathMethod(Action) (string, string)
  16  }
  17  
  18  type ListSpec interface {
  19  	Spec
  20  	Initializer
  21  	GetItems() interface{}
  22  	Len() int
  23  	Index(int) interface{}
  24  }
  25  
  26  type CountableListSpec interface {
  27  	ListSpec
  28  	SetCount(int32)
  29  	GetCount() int32
  30  	GetMaxLimit() int32
  31  	AddItem(interface{}) bool
  32  	ClearItems()
  33  }
  34  
  35  type Initializer interface {
  36  	Init()
  37  }
  38  
  39  func DeepCopySpec(s Spec) Spec {
  40  	if s == nil || reflect.ValueOf(s).IsNil() {
  41  		return nil
  42  	}
  43  	ret, ok := s.DeepCopyObject().(Spec)
  44  	if !ok {
  45  		panic("s is not Spec")
  46  	}
  47  	return ret
  48  }
  49  
  50  func DeepCopyListSpec(s ListSpec) ListSpec {
  51  	if s == nil || reflect.ValueOf(s).IsNil() {
  52  		return nil
  53  	}
  54  	ret, ok := s.DeepCopyObject().(ListSpec)
  55  	if !ok {
  56  		panic("s is not ListSpec")
  57  	}
  58  	return ret
  59  }
  60  
  61  func DeepCopyCountableListSpec(s CountableListSpec) CountableListSpec {
  62  	if s == nil || reflect.ValueOf(s).IsNil() {
  63  		return nil
  64  	}
  65  	ret, ok := s.DeepCopyObject().(CountableListSpec)
  66  	if !ok {
  67  		panic("s is not CountableListSpec")
  68  	}
  69  	return ret
  70  }
  71