feat(storage): add keep field for servers

This commit is contained in:
Quentin McGaw
2022-06-06 03:04:58 +00:00
parent 85e9d7d522
commit 5e659dc5b3
3 changed files with 57 additions and 10 deletions

View File

@@ -1,8 +1,10 @@
package models
import (
"fmt"
"net"
"reflect"
"strings"
)
type Server struct {
@@ -25,6 +27,7 @@ type Server struct {
Free bool `json:"free,omitempty"`
Stream bool `json:"stream,omitempty"`
PortForward bool `json:"port_forward,omitempty"`
Keep bool `json:"keep,omitempty"`
IPs []net.IP `json:"ips,omitempty"`
}
@@ -52,3 +55,15 @@ func ipsAreEqual(a, b []net.IP) (equal bool) {
return true
}
func (s *Server) Key() (key string) {
var protocols []string
if s.TCP {
protocols = append(protocols, "tcp")
}
if s.UDP {
protocols = append(protocols, "udp")
}
return fmt.Sprintf("%s-%s-%s", s.VPN, strings.Join(protocols, "-"), s.Hostname)
}