Passport/pkg/internal/gap/server.go

50 lines
1.1 KiB
Go
Raw Normal View History

2024-06-16 14:16:09 +00:00
package gap
import (
"fmt"
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/nexus/pkg/proto"
2024-10-26 16:06:23 +00:00
"git.solsynth.dev/hypernet/pusher/pkg/pushkit/pushcon"
"github.com/rs/zerolog/log"
"strings"
2024-06-16 14:16:09 +00:00
"github.com/spf13/viper"
)
var Nx *nex.Conn
2024-10-26 16:06:23 +00:00
var Px *pushcon.Conn
2024-06-16 14:16:09 +00:00
func InitializeToNexus() error {
grpcBind := strings.SplitN(viper.GetString("grpc_bind"), ":", 2)
httpBind := strings.SplitN(viper.GetString("bind"), ":", 2)
2024-06-16 14:16:09 +00:00
2024-10-26 16:06:23 +00:00
outboundIp, _ := nex.GetOutboundIP()
2024-06-16 14:16:09 +00:00
grpcOutbound := fmt.Sprintf("%s:%s", outboundIp, grpcBind[1])
httpOutbound := fmt.Sprintf("%s:%s", outboundIp, httpBind[1])
var err error
2024-10-26 16:06:23 +00:00
Nx, err = nex.NewNexusConn(viper.GetString("nexus_addr"), &proto.ServiceInfo{
Id: viper.GetString("id"),
Type: nex.ServiceTypeAuth,
Label: "Passport",
GrpcAddr: grpcOutbound,
HttpAddr: &httpOutbound,
})
if err == nil {
go func() {
err := Nx.RunRegistering()
if err != nil {
log.Error().Err(err).Msg("An error occurred while registering service...")
}
}()
}
2024-10-26 16:06:23 +00:00
Px, err = pushcon.NewConn(Nx)
if err != nil {
return fmt.Errorf("error during initialize pushcon: %v", err)
}
return err
2024-06-16 14:16:09 +00:00
}