github.com/jtzjtz/kit@v1.0.2/conn/rpc_pool/default.go (about)

     1  package rpc_pool
     2  
     3  import (
     4  	"sync"
     5  	"time"
     6  
     7  	"github.com/jtzjtz/kit/conn/grpc_pool"
     8  )
     9  
    10  var pool *RpcPool
    11  
    12  func Default() *RpcPool {
    13  	return pool
    14  }
    15  
    16  var once sync.Once
    17  
    18  // InitP 初始化,失败时panic
    19  func InitP(host string, maxCap int) {
    20  	once.Do(func() {
    21  		p, err := RpcPool{}.Connect(&grpc_pool.Options{
    22  			InitTargets: []string{host},
    23  			InitCap:     5,
    24  			MaxCap:      maxCap,
    25  			DialTimeout: time.Second * 30,
    26  			IdleTimeout: time.Second * 60 * 60,
    27  		})
    28  		if err != nil {
    29  			panic(err)
    30  		}
    31  
    32  		pool = &p
    33  	})
    34  }