Files
gluetun/internal/models/alias.go

68 lines
1.6 KiB
Go
Raw Normal View History

package models
2020-07-19 14:26:24 +00:00
import (
"fmt"
"strings"
)
type (
2020-10-20 02:45:28 +00:00
// VPNDevice is the device name used to tunnel using Openvpn.
VPNDevice string
2020-10-20 02:45:28 +00:00
// DNSProvider is a DNS over TLS server provider name.
DNSProvider string
2020-10-20 02:45:28 +00:00
// DNSHost is the DNS host to use for TLS validation.
DNSHost string
2020-10-20 02:45:28 +00:00
// URL is an HTTP(s) URL address.
URL string
2020-10-20 02:45:28 +00:00
// Filepath is a local filesytem file path.
Filepath string
2020-10-20 02:45:28 +00:00
// VPNProvider is the name of the VPN provider to be used.
2020-07-19 14:26:24 +00:00
VPNProvider string
2020-10-20 02:45:28 +00:00
// NetworkProtocol contains the network protocol to be used to communicate with the VPN servers.
NetworkProtocol string
// Loop status such as stopped or running.
LoopStatus string
)
2020-07-19 14:26:24 +00:00
func (ls LoopStatus) String() string {
return string(ls)
}
2020-07-19 14:26:24 +00:00
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
}