Add ipv6 support and enable go mod
This commit is contained in:
@@ -2,17 +2,19 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/glog"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
type MonitorType int
|
||||
|
||||
const (
|
||||
Monitor_PORT MonitorType = 1
|
||||
Monitor_EXEC MonitorType = 2
|
||||
Monitor_CONSUL MonitorType = 3
|
||||
Monitor_PORT MonitorType = 1
|
||||
Monitor_EXEC MonitorType = 2
|
||||
Monitor_CONSUL MonitorType = 3
|
||||
defaultFailThreshold = 3
|
||||
)
|
||||
|
||||
var MonitorMap = map[string]MonitorType{"port": Monitor_PORT, "exec": Monitor_EXEC, "consul": Monitor_CONSUL}
|
||||
@@ -27,10 +29,11 @@ func (m MonitorType) String() string {
|
||||
}
|
||||
|
||||
type Monitor struct {
|
||||
Type MonitorType
|
||||
Port string
|
||||
Protocol string
|
||||
Cmd string
|
||||
Type MonitorType
|
||||
Port string
|
||||
Protocol string
|
||||
Cmd string
|
||||
FailCount int
|
||||
}
|
||||
|
||||
func (m *Monitor) Equal(other *Monitor) bool {
|
||||
@@ -48,9 +51,19 @@ func (m Monitors) Contains(elem *Monitor) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type Vip struct {
|
||||
IP net.IP
|
||||
Net *net.IPNet
|
||||
Family string
|
||||
}
|
||||
|
||||
func (v *Vip) Equal(other *Vip) bool {
|
||||
return v.IP.Equal(other.IP)
|
||||
}
|
||||
|
||||
type App struct {
|
||||
Name string
|
||||
Vip *net.IPNet
|
||||
Vip *Vip
|
||||
Monitors Monitors
|
||||
Nats []string
|
||||
}
|
||||
@@ -64,7 +77,7 @@ func (a *App) Equal(other *App) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return a.Name == other.Name && a.Vip.String() == other.Vip.String()
|
||||
return a.Name == other.Name && a.Vip.Equal(other.Vip)
|
||||
}
|
||||
|
||||
func NewApp(appName, vip string, monitors []string, nats []string) (*App, error) {
|
||||
@@ -72,11 +85,16 @@ func NewApp(appName, vip string, monitors []string, nats []string) (*App, error)
|
||||
return nil, fmt.Errorf("Invalid app name")
|
||||
}
|
||||
app := &App{Name: appName, Nats: nats}
|
||||
_, ipnet, err := net.ParseCIDR(vip)
|
||||
ip, ipnet, err := net.ParseCIDR(vip)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Invalid VIP specified, need ip/mask")
|
||||
}
|
||||
app.Vip = ipnet
|
||||
app.Vip = &Vip{IP: ip, Net: ipnet}
|
||||
if ip.To4() != nil {
|
||||
app.Vip.Family = "4"
|
||||
} else {
|
||||
app.Vip.Family = "6"
|
||||
}
|
||||
for _, m := range monitors {
|
||||
// valid monitor formats:
|
||||
// "port:tcp:123" , "exec:/local/check.sh", "consul"
|
||||
|
||||
Reference in New Issue
Block a user