func (s krpcServer) randomPort() int {
	intranetIp, err := gipv4.GetIntranetIp()
	if err != nil {
		panic(err)
	}
	for i := randomPortMin; i <= randomPortMax; i++ {
		conn, err := net.Dial("tcp", fmt.Sprintf(`%s:%d`, intranetIp, i))
		if err != nil {
			return i
		} else {
			conn.Close()
		}
	}
	return randomPortNotAvailable
}
randomPort returns a random port that is not used by other processes.
package krpc
import (
	"fmt"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/gipv4"
	"github.com/gogf/gf/os/gcmd"
	"github.com/gogf/gf/os/glog"
	"github.com/gogf/gf/os/gproc"
	"github.com/gogf/gf/text/gstr"
	"github.com/gogf/katyusha/discovery"
	"google.golang.org/grpc"
	"net"
	"os"
	"os/signal"
	"sync"
	"syscall"
	"time"
)
type GrpcServer struct {
	Server    *grpc.Server
	Logger    *glog.Logger
	config    *GrpcServerConfig
	services  []*discovery.Service
	waitGroup sync.WaitGroup
}
func (s krpcServer) NewGrpcServer(conf ...*GrpcServerConfig) *GrpcServer {
	var config *GrpcServerConfig
	if len(conf) > 0 {
		config = conf[0]
	} else {
		config = s.NewGrpcServerConfig()
	}
	if config.Address == "" {
		randomPort := s.randomPort()
		if randomPort == randomPortNotAvailable {
			g.Log().Fatal("server address is empty and random port retrieving failed")
		}
		config.Address = fmt.Sprintf(`:%d`, randomPort)
	}
	if !gstr.Contains(config.Address, ":") {
		g.Log().Fatal("invalid service address, should contain listening port")
	}
	if config.Logger == nil {
		config.Logger = glog.New()
	}
	grpcServer := &GrpcServer{
		Logger: config.Logger,
		config: config,
	}
	grpcServer.config.Options = append([]grpc.ServerOption{
		s.ChainUnary(
			grpcServer.UnaryLogger,
			s.UnaryError,
			s.UnaryRecover,
		),
	}, grpcServer.config.Options...)
	grpcServer.Server = grpc.NewServer(grpcServer.config.Options...)
	return grpcServer
}