trpc.group/trpc-go/trpc-go@v1.0.3/client/client_linux.go (about)

     1  //go:build linux && amd64
     2  // +build linux,amd64
     3  
     4  package client
     5  
     6  import (
     7  	"trpc.group/trpc-go/trpc-go/log"
     8  	"trpc.group/trpc-go/trpc-go/transport"
     9  	"trpc.group/trpc-go/trpc-go/transport/tnet"
    10  )
    11  
    12  func attemptSwitchingTransport(o *Options) transport.ClientTransport {
    13  	// If the user doesn't explicitly set the transport (which is usually the case for trpc protocol),
    14  	// attempt to switch to the tnet transport.
    15  	if o.Transport == nil {
    16  		if check(o) {
    17  			cheer(o)
    18  			return tnet.DefaultClientTransport
    19  		}
    20  		sigh(o)
    21  		return transport.DefaultClientTransport
    22  	}
    23  	return o.Transport
    24  }
    25  
    26  func check(o *Options) bool {
    27  	// Only use tnet transport with TCP and trpc.
    28  	return (o.Network == "tcp" ||
    29  		o.Network == "tcp4" ||
    30  		o.Network == "tcp6") &&
    31  		o.Protocol == "trpc"
    32  }
    33  
    34  func cheer(o *Options) {
    35  	log.Infof("client %s is empowered with tnet! 🤩 ", o.ServiceName)
    36  }
    37  
    38  func sigh(o *Options) {
    39  	log.Infof("client: %s, tnet is not enabled by default 🧐 ", o.ServiceName)
    40  }