github.com/batchcorp/thrift-iterator@v0.0.0-20220918180557-4c4a158fc6e9/general/general_object.go (about)

     1  package general
     2  
     3  import "github.com/batchcorp/thrift-iterator/protocol"
     4  
     5  type Object interface {
     6  	Get(path ...interface{}) interface{}
     7  }
     8  
     9  type List []interface{}
    10  
    11  func (obj List) Get(path ...interface{}) interface{} {
    12  	if len(path) == 0 {
    13  		return obj
    14  	}
    15  	elem := obj[path[0].(int)]
    16  	if len(path) == 1 {
    17  		return elem
    18  	}
    19  	return elem.(Object).Get(path[1:]...)
    20  }
    21  
    22  type Map map[interface{}]interface{}
    23  
    24  func (obj Map) Get(path ...interface{}) interface{} {
    25  	if len(path) == 0 {
    26  		return obj
    27  	}
    28  	elem := obj[path[0]]
    29  	if len(path) == 1 {
    30  		return elem
    31  	}
    32  	return elem.(Object).Get(path[1:]...)
    33  }
    34  
    35  type Struct map[protocol.FieldId]interface{}
    36  
    37  func (obj Struct) Get(path ...interface{}) interface{} {
    38  	if len(path) == 0 {
    39  		return obj
    40  	}
    41  	elem := obj[path[0].(protocol.FieldId)]
    42  	if len(path) == 1 {
    43  		return elem
    44  	}
    45  	return elem.(Object).Get(path[1:]...)
    46  }
    47  
    48  type Message struct {
    49  	protocol.MessageHeader
    50  	Arguments Struct
    51  }