Skip to content

Commit

Permalink
Add missing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mtojek committed Mar 4, 2019
1 parent 433c674 commit 911653e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: go

go:
- tip
17 changes: 11 additions & 6 deletions ipapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"net/http"
)

const baseUri = "http://ip-api.com/json"
const baseURI = "http://ip-api.com/json"

type IPApi struct{}
// Client is responsible for calling IP-API.
type Client struct{}

// GeoIPData stores geolocation data.
type GeoIPData struct {
As string
City string
Expand All @@ -20,17 +22,20 @@ type GeoIPData struct {
Zip string
}

// String method returns string representative of the struct.
func (g *GeoIPData) String() string {
return fmt.Sprintf("%s\t%s\t%s\t%s\t\t%s\t%s\t%s", g.As, g.City, g.Country, g.ISP, g.Org, g.RegionName,
g.Zip)
}

func NewIPApi() *IPApi {
return new(IPApi)
// NewClient creates new instance of the IP-API client.
func NewClient() *Client {
return new(Client)
}

func (api *IPApi) GeoIP(ip string) (*GeoIPData, error) {
response, err := http.Get(baseUri + "/" + ip)
// GeoIP method returns geolocation data.
func (c *Client) GeoIP(ip string) (*GeoIPData, error) {
response, err := http.Get(baseURI + "/" + ip)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
flag.BoolVar(&geoIP, "g", false, "check GeoIP data")
flag.Parse()

ipApiClient := ipapi.NewIPApi()
ipAPIClient := ipapi.NewClient()
vpnClient := vpn.NewClient()
err := vpnClient.Initialize()
if err != nil {
Expand All @@ -41,7 +41,7 @@ func main() {
fmt.Print(tunnel.String())

if geoIP {
geoIPData, err := ipApiClient.GeoIP(tunnel.Host)
geoIPData, err := ipAPIClient.GeoIP(tunnel.Host)
if err != nil {
fmt.Printf("\terror checking GeoIP data: %v", err)
} else {
Expand Down
17 changes: 12 additions & 5 deletions vpn/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,35 @@ import (
)

const (
baseUri = "https://client.hola.org/client_cgi"
baseURI = "https://client.hola.org/client_cgi"

browser = "chrome"
extVer = "1.125.157"
rmtVer = "1.2.676"
)

// Client is responsible for calling Hola VPN API.
type Client struct {
uuid string
key string
}

// Tunnels stores information about proxy servers
type Tunnels struct {
Login string
Password string

Servers []TunnelSettings
}

// TunnelSettings stores tunnel related settings.
type TunnelSettings struct {
Host string
Port string
Proto string
}

// String method returns string representative of the struct.
func (ts *TunnelSettings) String() string {
return fmt.Sprintf("%s\t%s:%s", ts.Proto, ts.Host, ts.Port)
}
Expand All @@ -51,14 +55,16 @@ type zGetTunnelsResponse struct {
AgentKey string `json:"agent_key"`
}

// NewClient creates new instance of the VPN client.
func NewClient() *Client {
return &Client{
uuid: strings.Replace(uuid.New().String(), "-", "", -1),
}
}

// Initialize method opens new session with the remote API.
func (c *Client) Initialize() error {
response, err := http.PostForm(baseUri+"/background_init", url.Values{
response, err := http.PostForm(baseURI+"/background_init", url.Values{
"login": []string{"1"},
"flags": []string{"0"},
"ver": []string{extVer},
Expand All @@ -80,8 +86,9 @@ func (c *Client) Initialize() error {
return nil
}

// FindTunnels method returns available proxy servers.
func (c *Client) FindTunnels(countryCode string, limit int) (*Tunnels, error) {
u := baseUri + "/zgettunnels?" + "uuid=" + c.uuid + "&session_key=" + c.key +
u := baseURI + "/zgettunnels?" + "uuid=" + c.uuid + "&session_key=" + c.key +
"&country=" + countryCode + "&rmt_ver=" + rmtVer + "&ext_ver=" + extVer + "&browser=" + browser +
"&product=cws" + "&lccgi=1" + fmt.Sprintf("&limit=%d", limit)
response, err := http.Get(u)
Expand Down Expand Up @@ -109,8 +116,8 @@ func (c *Client) FindTunnels(countryCode string, limit int) (*Tunnels, error) {
hostname := hostPortSplit[0]
port := hostPortSplit[1]

ipAddress, foundIpAddress := r.IPList[hostname]
if !foundIpAddress {
ipAddress, foundIPAddress := r.IPList[hostname]
if !foundIPAddress {
return nil, fmt.Errorf("IP address not found (hostname: %s)", hostname)
}

Expand Down

0 comments on commit 911653e

Please sign in to comment.