🐛 Bug fixes on connection and package naming
This commit is contained in:
15
pkg/internal/gap/net.go
Normal file
15
pkg/internal/gap/net.go
Normal file
@ -0,0 +1,15 @@
|
||||
package gap
|
||||
|
||||
import "net"
|
||||
|
||||
func GetOutboundIP() (net.IP, error) {
|
||||
conn, err := net.Dial("udp", "1.1.1.1:80")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer conn.Close()
|
||||
}
|
||||
|
||||
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||||
return localAddr.IP, nil
|
||||
}
|
@ -17,21 +17,23 @@ func Register() error {
|
||||
return err
|
||||
}
|
||||
|
||||
bind := strings.SplitN(viper.GetString("consul.srv_serve"), ":", 2)
|
||||
baseAddr := viper.GetString("consul.srv_http")
|
||||
httpBind := strings.SplitN(viper.GetString("bind"), ":", 2)
|
||||
grpcBind := strings.SplitN(viper.GetString("grpc_bind"), ":", 2)
|
||||
|
||||
port, _ := strconv.Atoi(bind[1])
|
||||
outboundIp, _ := GetOutboundIP()
|
||||
port, _ := strconv.Atoi(httpBind[1])
|
||||
|
||||
registration := new(api.AgentServiceRegistration)
|
||||
registration.ID = viper.GetString("id")
|
||||
registration.Name = "Hydrogen.Passport"
|
||||
registration.Address = bind[0]
|
||||
registration.Address = outboundIp.String()
|
||||
registration.Port = port
|
||||
registration.Check = &api.AgentServiceCheck{
|
||||
HTTP: fmt.Sprintf("%s/.well-known", baseAddr),
|
||||
GRPC: fmt.Sprintf("%s:%s", outboundIp, grpcBind[1]),
|
||||
HTTP: fmt.Sprintf("%s:%s/.well-known", outboundIp, httpBind[1]),
|
||||
Timeout: "5s",
|
||||
Interval: "5s",
|
||||
DeregisterCriticalServiceAfter: "10s",
|
||||
Interval: "1m",
|
||||
DeregisterCriticalServiceAfter: "3m",
|
||||
}
|
||||
|
||||
return client.Agent().ServiceRegister(registration)
|
||||
|
Reference in New Issue
Block a user