Maintenance: remove some type aliases
This commit is contained in:
@@ -1,23 +1,6 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
// VPNDevice is the device name used to tunnel using Openvpn.
|
||||
VPNDevice string
|
||||
// DNSHost is the DNS host to use for TLS validation.
|
||||
DNSHost string
|
||||
// URL is an HTTP(s) URL address.
|
||||
URL string
|
||||
// Filepath is a local filesytem file path.
|
||||
Filepath string
|
||||
// VPNProvider is the name of the VPN provider to be used.
|
||||
VPNProvider string
|
||||
// NetworkProtocol contains the network protocol to be used to communicate with the VPN servers.
|
||||
NetworkProtocol string
|
||||
// LoopStatus status such as stopped or running.
|
||||
LoopStatus string
|
||||
)
|
||||
@@ -25,41 +8,3 @@ type (
|
||||
func (ls LoopStatus) String() string {
|
||||
return string(ls)
|
||||
}
|
||||
|
||||
func marshalJSONString(s string) (data []byte, err error) {
|
||||
return []byte(fmt.Sprintf("%q", s)), nil
|
||||
}
|
||||
|
||||
func unmarshalJSONString(data []byte) (s string) {
|
||||
s = string(data)
|
||||
s = strings.TrimPrefix(s, "\"")
|
||||
s = strings.TrimSuffix(s, "\"")
|
||||
return s
|
||||
}
|
||||
|
||||
func (v *VPNProvider) MarshalJSON() ([]byte, error) {
|
||||
return marshalJSONString(string(*v))
|
||||
}
|
||||
|
||||
func (v *VPNProvider) UnmarshalJSON(data []byte) error {
|
||||
*v = VPNProvider(unmarshalJSONString(data))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NetworkProtocol) MarshalJSON() ([]byte, error) {
|
||||
return marshalJSONString(string(*n))
|
||||
}
|
||||
|
||||
func (n *NetworkProtocol) UnmarshalJSON(data []byte) error {
|
||||
*n = NetworkProtocol(unmarshalJSONString(data))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *Filepath) MarshalJSON() ([]byte, error) {
|
||||
return marshalJSONString(string(*f))
|
||||
}
|
||||
|
||||
func (f *Filepath) UnmarshalJSON(data []byte) error {
|
||||
*f = Filepath(unmarshalJSONString(data))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_VPNProvider_JSON(t *testing.T) {
|
||||
t.Parallel()
|
||||
v := VPNProvider("name")
|
||||
data, err := v.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []byte{0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22}, data)
|
||||
err = v.UnmarshalJSON(data)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, VPNProvider("name"), v)
|
||||
}
|
||||
|
||||
func Test_NetworkProtocol_JSON(t *testing.T) {
|
||||
t.Parallel()
|
||||
v := NetworkProtocol("name")
|
||||
data, err := v.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []byte{0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22}, data)
|
||||
err = v.UnmarshalJSON(data)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, NetworkProtocol("name"), v)
|
||||
}
|
||||
|
||||
func Test_Filepath_JSON(t *testing.T) {
|
||||
t.Parallel()
|
||||
v := Filepath("name")
|
||||
data, err := v.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []byte{0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22}, data)
|
||||
err = v.UnmarshalJSON(data)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, Filepath("name"), v)
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package models
|
||||
|
||||
import "net"
|
||||
|
||||
// DNSProviderData contains information for a DNS provider.
|
||||
type DNSProviderData struct {
|
||||
IPs []net.IP
|
||||
SupportsTLS bool
|
||||
SupportsIPv6 bool
|
||||
SupportsDNSSec bool
|
||||
Host DNSHost
|
||||
}
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
)
|
||||
|
||||
type OpenVPNConnection struct {
|
||||
IP net.IP `json:"ip"`
|
||||
Port uint16 `json:"port"`
|
||||
Protocol NetworkProtocol `json:"protocol"`
|
||||
Hostname string `json:"hostname"` // Privado for tls verification
|
||||
IP net.IP `json:"ip"`
|
||||
Port uint16 `json:"port"`
|
||||
Protocol string `json:"protocol"`
|
||||
Hostname string `json:"hostname"` // Privado for tls verification
|
||||
}
|
||||
|
||||
func (o *OpenVPNConnection) Equal(other OpenVPNConnection) bool {
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
)
|
||||
|
||||
type PIAServer struct {
|
||||
Region string `json:"region"`
|
||||
ServerName string `json:"server_name"`
|
||||
Protocol NetworkProtocol `json:"protocol"`
|
||||
PortForward bool `json:"port_forward"`
|
||||
IP net.IP `json:"ip"`
|
||||
Region string `json:"region"`
|
||||
ServerName string `json:"server_name"`
|
||||
Protocol string `json:"protocol"`
|
||||
PortForward bool `json:"port_forward"`
|
||||
IP net.IP `json:"ip"`
|
||||
}
|
||||
|
||||
func (p *PIAServer) String() string {
|
||||
|
||||
Reference in New Issue
Block a user