2017-11-10 13:24:10 +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"
|
2017-11-14 03:42:55 +00:00
|
|
|
"git.loafle.net/overflow/overflow_gateway_websocket/config"
|
2017-11-10 13:24:10 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
var grpcPool cgp.Pool
|
|
|
|
|
|
|
|
func ExternalInit() {
|
|
|
|
ph := &grpcPoolHandlers{}
|
2017-11-14 03:42:55 +00:00
|
|
|
ph.MaxCapacity = config.Config.GRPC.Pool.MaxCapacity
|
|
|
|
ph.MaxIdle = config.Config.GRPC.Pool.MaxIdle
|
|
|
|
ph.IdleTimeout = config.Config.GRPC.Pool.IdleTimeout
|
|
|
|
ph.Wait = config.Config.GRPC.Pool.Wait
|
2017-11-10 13:24:10 +00:00
|
|
|
|
|
|
|
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
|
2017-11-14 03:42:55 +00:00
|
|
|
conn, err := grpc.Dial(config.Config.GRPC.Addr, grpc.WithInsecure())
|
2017-11-10 13:24:10 +00:00
|
|
|
if nil != err {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
c := ooas.NewOverflowApiServerClient(conn)
|
|
|
|
|
|
|
|
return conn, c, nil
|
|
|
|
}
|