A simple CloudSight API Client for Go programming language.
This package is currently in beta status. It means the API may still change in backwards incompatible way.
$ go get github.com/cloudsight/cloudsight-go
You need your API key and secret (if using OAuth1 authentication). They are available on CloudSight site after you sign up and create a project.
Import the cloudsight
package:
import (
...
"github.com/cloudsight/cloudsight-go"
)
Create a client instance using simple key-based authentication:
client, err := cloudsight.NewClientSimple("your-api-key")
Or, using OAuth1 authentication:
client, err := cloudsight.NewClientOAuth("your-api-key", "your-api-secret")
Send the image request using a file:
f, err := os.Open("your-file.jpg")
if err != nil {
panic(err)
}
defer f.Close()
params := cloudsight.Params{}
params.SetLocale("en")
job, err := client.ImageRequest(f, "your-file.jpg", params)
Or, you can send the image request using a URL:
params := cloudsight.Params{}
params.SetLocale("en")
job, err := client.RemoteImageRequest("http://www.example.com/image.jpg", params)
Then, update the job status to see if it's already processed:
err := client.UpdateJob(job)
if job != cloudsight.StatusNotCompleted {
// Done!
}
It usually takes 6-12 seconds to receive a completed response. You may use
WaitJob()
method to wait until the image is processed:
err := client.WaitJob(job, 30 * time.Second)
Note that Params
is just a map[string]string
so you may choose to use more
"dynamic" approach:
params := map[string]string{
"image_request[locale]": "en",
}
job, err := client.RemoteImageRequest("http://www.example.com/image.jpg", cloudsight.Params(params))
Consult the complete documentation.