diff --git a/api.go b/api.go new file mode 100644 index 0000000..3b6aaef --- /dev/null +++ b/api.go @@ -0,0 +1,38 @@ +package mullsox + +type MyIPDetails struct { + Ip string `json:"ip"` + Country string `json:"country"` + City string `json:"city"` + Longitude float64 `json:"longitude"` + Latitude float64 `json:"latitude"` + MullvadExitIp bool `json:"mullvad_exit_ip"` + MullvadExitIpHostname string `json:"mullvad_exit_ip_hostname"` + MullvadServerType string `json:"mullvad_server_type"` + Blacklisted struct { + Blacklisted bool `json:"blacklisted"` + Results []struct { + Name string `json:"name"` + Link string `json:"link"` + Blacklisted bool `json:"blacklisted"` + } `json:"results"` + } `json:"blacklisted"` + Organization string `json:"organization"` +} + +type MullvadServer struct { + Hostname string `json:"hostname"` + CountryCode string `json:"country_code"` + CountryName string `json:"country_name"` + CityCode string `json:"city_code"` + CityName string `json:"city_name"` + Active bool `json:"active"` + Owned bool `json:"owned"` + Provider string `json:"provider"` + Ipv4AddrIn string `json:"ipv4_addr_in"` + Ipv6AddrIn string `json:"ipv6_addr_in"` + NetworkPortSpeed int `json:"network_port_speed"` + Pubkey string `json:"pubkey"` + MultihopPort int `json:"multihop_port"` + SocksName string `json:"socks_name"` +} diff --git a/mullvad.go b/check.go similarity index 55% rename from mullvad.go rename to check.go index 34a163d..c5205da 100644 --- a/mullvad.go +++ b/check.go @@ -1,4 +1,4 @@ -package main +package mullsox import ( "context" @@ -9,9 +9,9 @@ import ( "time" ) -const AimHost = "am.i.mullvad.net" -const Ipv4Endpoint = `https://ipv4.` + AimHost -const Ipv6Endpoint = `https://ipv6.` + AimHost +const baseEndpoint = "am.i.mullvad.net" +const Ipv4Endpoint = `https://ipv4.` + baseEndpoint +const Ipv6Endpoint = `https://ipv6.` + baseEndpoint func CheckIP4(ctx context.Context, h *http.Client) (details *MyIPDetails, err error) { return checkIP(ctx, h, false) @@ -102,40 +102,3 @@ func checkIP(ctx context.Context, h *http.Client, ipv6 bool) (details *MyIPDetai err = json.Unmarshal(cytes, &details) return } - -type MyIPDetails struct { - Ip string `json:"ip"` - Country string `json:"country"` - City string `json:"city"` - Longitude float64 `json:"longitude"` - Latitude float64 `json:"latitude"` - MullvadExitIp bool `json:"mullvad_exit_ip"` - MullvadExitIpHostname string `json:"mullvad_exit_ip_hostname"` - MullvadServerType string `json:"mullvad_server_type"` - Blacklisted struct { - Blacklisted bool `json:"blacklisted"` - Results []struct { - Name string `json:"name"` - Link string `json:"link"` - Blacklisted bool `json:"blacklisted"` - } `json:"results"` - } `json:"blacklisted"` - Organization string `json:"organization"` -} - -type MullvadServer struct { - Hostname string `json:"hostname"` - CountryCode string `json:"country_code"` - CountryName string `json:"country_name"` - CityCode string `json:"city_code"` - CityName string `json:"city_name"` - Active bool `json:"active"` - Owned bool `json:"owned"` - Provider string `json:"provider"` - Ipv4AddrIn string `json:"ipv4_addr_in"` - Ipv6AddrIn string `json:"ipv6_addr_in"` - NetworkPortSpeed int `json:"network_port_speed"` - Pubkey string `json:"pubkey"` - MultihopPort int `json:"multihop_port"` - SocksName string `json:"socks_name"` -} diff --git a/mullvad_test.go b/check_test.go similarity index 98% rename from mullvad_test.go rename to check_test.go index 48f83c2..083b1a6 100644 --- a/mullvad_test.go +++ b/check_test.go @@ -1,4 +1,4 @@ -package main +package mullsox import ( "context"