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