gitee.com/zhongguo168a/gocodes@v0.0.0-20230609140523-e1828349603f/datax/reflectx/ref-desc-type-map.go (about)

     1  package reflectx
     2  
     3  import (
     4  	"gitee.com/zhongguo168a/gocodes/datax/schemax"
     5  )
     6  
     7  type MapTypeRef struct {
     8  }
     9  
    10  func (f *MapTypeRef) RefHas(field string) bool {
    11  	switch field {
    12  	case "Key":
    13  		return true
    14  	case "Value":
    15  		return true
    16  	}
    17  	return false
    18  }
    19  func (f *MapTypeRef) RefGet(target IRefObject, MapType string) (val interface{}, isNil bool) {
    20  	obj := target.(*schemax.MapType)
    21  	switch MapType {
    22  	case "Key":
    23  		return obj.Key, obj.Key == nil
    24  	case "Value":
    25  		return obj.Value, obj.Value == nil
    26  	}
    27  	return nil, true
    28  }
    29  
    30  func (f *MapTypeRef) RefSet(target IRefObject, MapType string, val interface{}) {
    31  	obj := target.(*schemax.MapType)
    32  	switch MapType {
    33  	case "Key":
    34  		obj.Key = val.(schemax.IType)
    35  	case "Value":
    36  		obj.Value = val.(schemax.IType)
    37  	}
    38  	return
    39  }
    40  
    41  func (f *MapTypeRef) RefNew() IRefObject {
    42  	return &schemax.MapType{}
    43  }
    44  
    45  func (f *MapTypeRef) RefType() string {
    46  	return "map"
    47  }