deprecated_overflow_gateway.../external/grpc/pool.go

50 lines
1.0 KiB
Go
Raw Permalink Normal View History

2017-11-09 09:14:57 +00:00
package grpc
import (
"fmt"
cgp "git.loafle.net/commons_go/grpc_pool"
"git.loafle.net/commons_go/logging"
ooas "git.loafle.net/overflow/overflow_api_server/golang"
"git.loafle.net/overflow/overflow_gateway_app/conf"
"google.golang.org/grpc"
)
var grpcPool cgp.Pool
func ExternalInit() {
ph := &grpcPoolHandlers{}
ph.MaxCapacity = conf.Config.GRPC.Pool.MaxCapacity
ph.MaxIdle = conf.Config.GRPC.Pool.MaxIdle
ph.IdleTimeout = conf.Config.GRPC.Pool.IdleTimeout
ph.Wait = conf.Config.GRPC.Pool.Wait
grpcPool = cgp.New(ph)
if err := grpcPool.Start(); nil != err {
logging.Logger().Panic(fmt.Sprintf("App: %v", err))
return
}
}
func ExternalDestroy() {
if nil != grpcPool {
grpcPool.Stop()
}
}
type grpcPoolHandlers struct {
cgp.PoolHandlers
}
func (h *grpcPoolHandlers) Dial() (*grpc.ClientConn, interface{}, error) {
var err error
conn, err := grpc.Dial(conf.Config.GRPC.Addr, grpc.WithInsecure())
if nil != err {
return nil, nil, err
}
c := ooas.NewOverflowApiServerClient(conn)
return conn, c, nil
}