2024-06-16 14:16:09 +00:00
|
|
|
package gap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-07-14 16:01:17 +00:00
|
|
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
|
|
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
|
|
|
"github.com/rs/zerolog/log"
|
2024-06-22 04:14:15 +00:00
|
|
|
"strings"
|
|
|
|
|
2024-06-16 14:16:09 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2024-07-14 16:01:17 +00:00
|
|
|
var H *hyper.HyperConn
|
2024-06-16 14:16:09 +00:00
|
|
|
|
2024-07-14 16:01:17 +00:00
|
|
|
func RegisterService() error {
|
2024-06-17 14:21:34 +00:00
|
|
|
grpcBind := strings.SplitN(viper.GetString("grpc_bind"), ":", 2)
|
2024-07-14 16:01:17 +00:00
|
|
|
httpBind := strings.SplitN(viper.GetString("bind"), ":", 2)
|
2024-06-16 14:16:09 +00:00
|
|
|
|
2024-06-17 14:21:34 +00:00
|
|
|
outboundIp, _ := GetOutboundIP()
|
2024-06-16 14:16:09 +00:00
|
|
|
|
2024-07-14 16:01:17 +00:00
|
|
|
grpcOutbound := fmt.Sprintf("%s:%s", outboundIp, grpcBind[1])
|
|
|
|
httpOutbound := fmt.Sprintf("%s:%s", outboundIp, httpBind[1])
|
|
|
|
|
|
|
|
var err error
|
|
|
|
H, err = hyper.NewHyperConn(viper.GetString("dealer.addr"), &proto.ServiceInfo{
|
|
|
|
Id: viper.GetString("id"),
|
|
|
|
Type: hyper.ServiceTypeAuthProvider,
|
|
|
|
Label: "Passport",
|
|
|
|
GrpcAddr: grpcOutbound,
|
|
|
|
HttpAddr: &httpOutbound,
|
|
|
|
})
|
|
|
|
if err == nil {
|
|
|
|
go func() {
|
|
|
|
err := H.KeepRegisterService()
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("An error occurred while registering service...")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2024-06-19 15:25:40 +00:00
|
|
|
|
2024-07-14 16:01:17 +00:00
|
|
|
return err
|
2024-06-16 14:16:09 +00:00
|
|
|
}
|