Programmable Media

Configure the Go SDK (video tutorial)

Last updated: Dec-11-2024

Overview

Learn how to install and configure the Cloudinary Go SDK in your Go environment. This will enable you to utilize Cloudinary for uploading, managing, and displaying assets in your applications.

Video tutorial


Tutorial contents

This tutorial presents the following topics. Click a timestamp to jump to that part of the video.

Introduction

Jump to this spot in the video  0:00 The Cloudinary Go SDK gives you a way to handle images and videos at scale, providing transformation, optimization and delivery capabilities that you can integrate seamlessly into your Go applications.

Install the Go SDK

Jump to this spot in the video  0:17 To install the Cloudinary Go SDK, ensure you're in the directory where your Go module was initialized using go mod init. Use the go get command to add the Cloudinary Go library from GitHub to your project.

Configure Cloudinary

Jump to this spot in the video  0:29 To configure Cloudinary, begin by creating a Cloudinary instance. Import the Cloudinary library from GitHub and use the cloudinary.New function to create the instance. Store this instance in a variable, such as cld, and include error handling.

my_file.go

Add credentials

Jump to this spot in the video  0:48 To keep your credentials secure:
  1. Store them in a .env file.
  2. Install the library with go get github.com/joho/godotenv.
  3. Import the godotenv library in your code.
  4. Use godotenv.Load() to load the credentials into your Go file.
Retrieve your Cloudinary credentials from the API Keys page in the Cloudinary Console. Copy the provided API environment variable format (containing the Cloud Name, API Key, and API Secret) and paste it into your .env file, replacing the placeholder values with your actual credentials.

my_file.go

Retrieve an image delivery URL from Cloudinary

Jump to this spot in the video  2:03 With your Cloudinary instance configured, you can generate a delivery URL for an image in your product environment:
  1. Use the cld.Image function with the public ID of the desired image to create an image object. For this example, you can use the public ID of a sample image cld-sample provided with every new Cloudinary account.
  2. Store this object in a variable named img and handle any errors.
  3. Convert the image object to a string to generate the delivery URL. Include error handling and print the URL upon success.

my_file.go

Run the code

Jump to this spot in the video  2:51 After writing the code, run it to see the delivery URL for the cld-sample image. This confirms that your Cloudinary instance was successfully created and used. You can also open the URL in a browser to view the image in your product environment.

Keep learning

Related topics

If you like this, you might also like...

Optimization Tips
Tips for delivering optimized images
Create Upload Presets
Streamline media uploads using signed upload presets
Auto Upload
Automatically upload remote images and videos to Cloudinary

 

Cloudinary Academy

 

Check out the Cloudinary Academy for free self-paced Cloudinary courses on a variety of developer or DAM topics, or register for formal instructor-led courses, either virtual or on-site.

 

✔️ Feedback sent!

Rate this page: