gitee.com/h79/goutils@v1.22.10/discovery/resolver/thrift/connector.go (about)

     1  package thrift
     2  
     3  import (
     4  	"gitee.com/h79/goutils/discovery/resolver/builder"
     5  	thriftresolver "gitee.com/h79/goutils/thrift/resolver"
     6  )
     7  
     8  // connector
     9  // 一个与thrift桥接的实现
    10  type connector struct {
    11  	cc thriftresolver.Connector
    12  }
    13  
    14  // UpdateState builder.Connector interface
    15  func (cr *connector) UpdateState(state builder.State) {
    16  	if cr.cc == nil {
    17  		return
    18  	}
    19  	s := thriftresolver.State{
    20  		Addresses:  toThriftAddress(state.Addresses),
    21  		Attributes: state.Attributes,
    22  	}
    23  	cr.cc.UpdateState(s)
    24  }
    25  
    26  // ReportError builder.Connector interface
    27  func (cr *connector) ReportError(er error) {
    28  	if cr.cc == nil {
    29  		return
    30  	}
    31  	cr.cc.ReportError(er)
    32  }
    33  
    34  func toThriftAddress(addr []builder.Address) []thriftresolver.Address {
    35  	thriftAddress := make([]thriftresolver.Address, 0)
    36  	for _, a := range addr {
    37  		aa := thriftresolver.Address{
    38  			Addr:       a.Addr,
    39  			ServerName: a.ServerName,
    40  			Attributes: a.Attributes,
    41  		}
    42  		thriftAddress = append(thriftAddress, aa)
    43  	}
    44  	return thriftAddress
    45  }