trpc.group/trpc-go/trpc-go@v1.0.3/server/service_linux.go (about)

     1  //go:build linux && amd64
     2  // +build linux,amd64
     3  
     4  package server
     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.ServerTransport {
    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  		// Only use tnet transport with TCP and trpc.
    17  		if (o.network == "tcp" ||
    18  			o.network == "tcp4" ||
    19  			o.network == "tcp6") &&
    20  			o.protocol == "trpc" {
    21  			log.Infof("service %s with network %s and protocol %s is empowered with tnet! 🤩 "+
    22  				"you can set 'transport: go-net' in your trpc_go.yaml's service configuration "+
    23  				"to switch to the golang net framework",
    24  				o.ServiceName, o.network, o.protocol)
    25  			return tnet.DefaultServerTransport
    26  		}
    27  		log.Infof("service: %s, tnet is not enabled by default for the network %s and protocol %s, 🧐 "+
    28  			"fallback to go-net transport, it is either because tnet does not support them or "+
    29  			"we haven't fully test for some third-party protocols, you can set 'transport: tnet' "+
    30  			"in your service configuration to force using tnet and test it at your own risk",
    31  			o.ServiceName, o.network, o.protocol)
    32  		return transport.DefaultServerStreamTransport
    33  	}
    34  	return o.Transport
    35  }