Go SDK quickstart guide

In this quickstart guide you'll learn how to start delivering your media from Cloudinary using the cloudinary-go library.

Tip
To get a more in-depth understanding, you may want to start from the Go SDK introduction.

1. Install library

Copy to clipboard
go get github.com/cloudinary/cloudinary-go

2. Add Cloudinary to your code

Copy to clipboard
// 1. Import the required packages for upload and admin
//===================

import (
    "context"
    "github.com/cloudinary/cloudinary-go"
    "github.com/cloudinary/cloudinary-go/api/admin"
    "github.com/cloudinary/cloudinary-go/api/uploader"
    "log"
)

// 2. Add your Cloudinary credentials and create a context
//===================

cld, _ := cloudinary.NewFromParams("<your-cloud-name>", "<your-api-key>", "<your-api-secret>")
ctx := context.Background()

// 3. Upload an image
//===================

resp, err := cld.Upload.Upload(ctx, "apple.png", uploader.UploadParams{PublicID: "docs/sdk/go/apple",
    Transformation: "c_crop,g_center/q_auto/f_auto", Tags: []string{"fruit"}})

// 4. Get your image information
//===================

my_image, err := cld.Image("docs/sdk/go/apple")
if err != nil {
    fmt.Println("error")
}

// 5. Transform your image
//=========================

// Resize to 250 x 250 pixels using the 'fill' crop mode.
my_image.Transformation = "c_fill,h_250,w_250"


// 6. Generate your image URL
//=========================

url, err := my_image.String()
if err != nil {
    fmt.Println("error")
}


// 7. Deliver your image
//=========================

// Render the image in an HTML page.
tmpl := template.Must(template.ParseFiles("transformations.html"))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  tmpl.Execute(w, url)
})

3. See the result!

Ruby:
Copy to clipboard
cl_image_tag("docs/sdk/go/apple", :height=>250, :width=>250, :crop=>"fill")
PHP (cloudinary_php v2.x):
Copy to clipboard
(new ImageTag('docs/sdk/go/apple'))
  ->resize(Resize::fill()->width(250)
->height(250));
PHP (cloudinary_php v1.x (legacy)):
Copy to clipboard
cl_image_tag("docs/sdk/go/apple", array("height"=>250, "width"=>250, "crop"=>"fill"))
Python:
Copy to clipboard
CloudinaryImage("docs/sdk/go/apple").image(height=250, width=250, crop="fill")
Node.js:
Copy to clipboard
cloudinary.image("docs/sdk/go/apple", {height: 250, width: 250, crop: "fill"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().height(250).width(250).crop("fill")).imageTag("docs/sdk/go/apple");
JS (js-url-gen v1.x):
Copy to clipboard
new CloudinaryImage("docs/sdk/go/apple").resize(fill().width(250).height(250));
JS (cloudinary-core v2.x (legacy)):
Copy to clipboard
cloudinary.imageTag('docs/sdk/go/apple', {height: 250, width: 250, crop: "fill"}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("docs/sdk/go/apple", {height: 250, width: 250, crop: "fill"})
React:
Copy to clipboard
<Image publicId="docs/sdk/go/apple" >
  <Transformation height="250" width="250" crop="fill" />
</Image>
Vue.js:
Copy to clipboard
<cld-image public-id="docs/sdk/go/apple" >
  <cld-transformation height="250" width="250" crop="fill" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="docs/sdk/go/apple" >
  <cl-transformation height="250" width="250" crop="fill">
  </cl-transformation>
</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Height(250).Width(250).Crop("fill")).BuildImageTag("docs/sdk/go/apple")
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setHeight(250).setWidth(250).setCrop("fill")).generate("docs/sdk/go/apple")!, cloudinary: cloudinary)
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().height(250).width(250).crop("fill")).generate("docs/sdk/go/apple");
Kotlin:
Copy to clipboard
// This code example is not currently available.
Transformed image

4. Try it yourself

Here's the code in a fully functioning Go app, along with some other examples that you'll find throughout this guide. It's structured a little differently from above - each transformation example has its own Go file showing the imports and syntax required. Find those files in the go/src/lib folder of the project.

main.go imports all the functions to display the transformed images on a simple web page.

Experiment with images:

This code is also available in GitHub.

Experiment with videos:

This code is also available in GitHub

Ready to learn more?

  • Understand the architecture of the Go SDK and get a more detailed overview of the libraries.
  • Learn how to upload images and videos using @cloudinary/cloudinary-go.

✔️ Feedback sent!

Rate this page: