Skip to content

synthient/go-synthient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-synthient

godoc go.mod version report card

synthient sdk for golang

Installation

You can add this sdk to your project with the following terminal command:

go get -u github.com/synthient/go-synthient

Creating a synthient.Client

When using this SDK all requests are made with a synthient.Client. You can create this struct manually or with the synthient.NewClient function:

package main

import "github.com/synthient/go-synthient"

func main() {
    client := synthient.NewClient("SECRET TOKEN")
}

Getting IP data

One of the first things you can do with your new client is get IP data. Here is an example of getting IP data for a given IP using client.GetIP(...):

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/synthient/go-synthient"
)

func main() {
	client := synthient.NewClient(os.Getenv("SYNTHIENT_API_KEY"))
	resp, err := client.GetIP("213.149.183.127", nil)
	if err != nil {
		log.Fatalf("failed to get ip address: %s", err)
	}
	fmt.Println(resp.IP)
}

client.GetIP returns a synthient.IP value, along with the error if there is one, of course.

Anonymizer Feed Data

Streaming

You can stream the feed using client.StreamAnonymizersFeed(...):

package main

import (
	"io"
	"log"
	"os"

	"github.com/synthient/go-synthient"
)

func main() {
	client := synthient.NewClient(os.Getenv("SYNTHIENT_API_KEY"))
	stream, err := client.StreamAnonymizersFeed(synthient.AnonymizersQuery{
		Provider:     "BIRDPROXIES",
		Type:         "RESIDENTIAL_PROXY",
		LastObserved: "7D",
		Format:       "CSV",
		CountryCode:  "US",
		Full:         false,
		Order:        "desc",
	}, nil)
	if err != nil {
		log.Fatalf("failed to stream feed: %s", err)
	}
	defer func() { _ = stream.Close() }() // important! make sure to close stream

	_, err = io.Copy(os.Stdout, stream)
	if err != nil {
		log.Fatalf("failed to read stream: %s", err)
	}
}

Downloading

Using client.DownloadAnonymizersFeed(...) you can easily stream a feed to a file. This will save it to a file called feed.csv in this example:

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/synthient/go-synthient"
)

func main() {
	client := synthient.NewClient(os.Getenv("SYNTHIENT_API_KEY"))
	n, err := client.DownloadAnonymizersFeed(synthient.AnonymizersQuery{
		Provider:     "BIRDPROXIES",
		Type:         "RESIDENTIAL_PROXY",
		LastObserved: "7D",
		Format:       "CSV",
		CountryCode:  "US",
		Full:         false,
		Order:        "desc",
	}, "feed.csv", nil)
	if err != nil {
		log.Fatalf("failed to download feed: %s", err)
	}

	fmt.Println(n, "bytes downloaded")
}

Client Customization

The synthient.Client can be customized to use a self-hosted endpoint for example. Here is an example:

package main

import "github.com/synthient/go-synthient"

func main() {
    client := synthient.NewClient("SECRET TOKEN")
    client.BaseAPI.Host = "synthient.myserver.com"
}