new: Extensions v0
This commit is contained in:
@@ -8,7 +8,9 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"github.com/hiddify/hiddify-core/extension"
|
||||
pb "github.com/hiddify/hiddify-core/hiddifyrpc"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
@@ -23,16 +25,16 @@ type TunnelService struct {
|
||||
pb.UnimplementedTunnelServiceServer
|
||||
}
|
||||
|
||||
func StartGrpcServer(listenAddressG string, service string) error {
|
||||
|
||||
func StartGrpcServer(listenAddressG string, service string) (*grpc.Server, error) {
|
||||
lis, err := net.Listen("tcp", listenAddressG)
|
||||
if err != nil {
|
||||
log.Printf("failed to listen: %v", err)
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
s := grpc.NewServer()
|
||||
if service == "core" {
|
||||
pb.RegisterCoreServer(s, &CoreService{})
|
||||
pb.RegisterExtensionHostServiceServer(s, &extension.ExtensionHostService{})
|
||||
} else if service == "hello" {
|
||||
pb.RegisterHelloServer(s, &HelloService{})
|
||||
} else if service == "tunnel" {
|
||||
@@ -43,17 +45,20 @@ func StartGrpcServer(listenAddressG string, service string) error {
|
||||
if err := s.Serve(lis); err != nil {
|
||||
log.Printf("failed to serve: %v", err)
|
||||
}
|
||||
log.Printf("Server stopped")
|
||||
// cancel()
|
||||
}()
|
||||
return nil
|
||||
return s, nil
|
||||
}
|
||||
func StartCoreGrpcServer(listenAddressG string) error {
|
||||
|
||||
func StartCoreGrpcServer(listenAddressG string) (*grpc.Server, error) {
|
||||
return StartGrpcServer(listenAddressG, "core")
|
||||
}
|
||||
|
||||
func StartHelloGrpcServer(listenAddressG string) error {
|
||||
func StartHelloGrpcServer(listenAddressG string) (*grpc.Server, error) {
|
||||
return StartGrpcServer(listenAddressG, "hello")
|
||||
}
|
||||
|
||||
func StartTunnelGrpcServer(listenAddressG string) error {
|
||||
func StartTunnelGrpcServer(listenAddressG string) (*grpc.Server, error) {
|
||||
return StartGrpcServer(listenAddressG, "tunnel")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user