> ## Documentation Index
> Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# Go quick start


[readme-version-support-link]:https://github.com/cloudinary/cloudinary-go#Version-Support
This quick start lets you get an end-to-end implementation up and running using the Go SDK in 5 minutes or less.

#### Prerequisites **To perform this quick start, you'll need:**

* A Cloudinary account. If you don't have one yet, you can quickly [register for free](https://cloudinary.com/users/register_free).
* Your product environment credentials. You can find your [credentials](product_environment_settings#api_keys) on the [API Keys](https://console.cloudinary.com/app/settings/api-keys) page of the Cloudinary Console Settings. 
  * To use your **API environment variable**, copy the provided format and replace the `<your_api_key>` and `<your_api_secret>` placeholders with the actual values found on the page. Your cloud name will already be correctly included in the format.
* A working Go development environment with a [supported version][readme-version-support-link] of Go.

> **NOTES**:
>
> * This quick start is designed for quick onboarding.  It doesn't necessarily employ coding best practices and the code you create here isn't intended for production.  

> * If you aren't familiar with Cloudinary, you may want to first take a look at the [Developer Kickstart](dev_kickstart) for a hands-on, step-by-step introduction to Cloudinary features. You may also find our [Glossary](cloudinary_glossary) helpful to understand Cloudinary-specific terminology.
## 1. Set up and configure the SDK

Create a go.mod file in the directory where your Go program will be saved: 

```go
go mod init my_folder
```

In a terminal in your Go environment, run the following code:

```go
go get github.com/cloudinary/cloudinary-go/v2
```

In a terminal, set your `CLOUDINARY_URL` environment variable.

Replace `CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@CLOUD_NAME` with the  **API environment variable** copied from your product environment credentials:

* On Mac or Linux:

    ```
    export CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@CLOUD_NAME
    ```
* On Windows:

    ```
    set CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@CLOUD_NAME
    ```

> **INFO**:
>
> * When writing your own applications, follow your organization's policy on storing secrets and don't expose your API secret. * If you use a method that involves writing your environment variable to a file (e.g. `dotenv`), the file should be excluded from your version control system, so as not to expose it publicly.

In your project, create a new file called `my_file.go`. Copy and paste the following into this file:

my_file.go

```go
package main

// Import Cloudinary and other necessary libraries
//===================
import (
	"context"
	"fmt"
	"github.com/cloudinary/cloudinary-go/v2"
	"github.com/cloudinary/cloudinary-go/v2/api"
	"github.com/cloudinary/cloudinary-go/v2/api/admin"
	"github.com/cloudinary/cloudinary-go/v2/api/uploader"
)

func credentials() (*cloudinary.Cloudinary, context.Context) {
	// Add your Cloudinary credentials, set configuration parameter 
	// Secure=true to return "https" URLs, and create a context
	//===================
	cld, _ := cloudinary.New()
	cld.Config.URL.Secure = true
	ctx := context.Background()
	return cld, ctx
}
```

Tip...

You can set any [configuration parameters](cloudinary_sdks#configuration_parameters) in this way. In this case, you're setting the `Secure` parameter to ensure that `https` URLs are generated by the SDK.

## 2. Upload an image

Copy and paste this into `my_file.go`:

my_file.go (continued)

```go
func uploadImage(cld *cloudinary.Cloudinary, ctx context.Context) {

  // Upload the image.
  // Set the asset's public ID and allow overwriting the asset with new versions
	resp, err := cld.Upload.Upload(ctx, "https://cloudinary-devs.github.io/cld-docs-assets/assets/images/butterfly.jpeg", uploader.UploadParams{
		PublicID:       "quickstart_butterfly",
		UniqueFilename: api.Bool(false),
		Overwrite:      api.Bool(true)})
	if err != nil {
		fmt.Println("error")
	}

  // Log the delivery URL
	fmt.Println("****2. Upload an image****\nDelivery URL:", resp.SecureURL, "\n")
}
```

More info about upload...

* You can upload from various sources, including local files, but for this quick start we're using a remote file available at: 
[https://cloudinary-devs.github.io/cld-docs-assets/assets/images/butterfly.jpeg](https://cloudinary-devs.github.io/cld-docs-assets/assets/images/butterfly.jpeg).
* We've set the [public ID](cloudinary_glossary#public_id) in this example to `quickstart_butterfly`, `Overwrite` to `true`, and `UniqueFilename` to `false` so that if you run this quick start more than once, you'll still only have one file uploaded that overwrites the previous one. Without these parameters set, the default option of using a random public ID would be applied, and a new asset would be created each time.
* See the `upload` method of the [Upload API](image_upload_api_reference#upload).
* Learn more about [uploading assets](upload_images).

## 3. Get and use details of the image 

Copy and paste this into `my_file.go`:
 

my_file.go (continued)

```go
func getAssetInfo(cld *cloudinary.Cloudinary, ctx context.Context) {
	// Get and use details of the image
	// ==============================
	resp, err := cld.Admin.Asset(ctx, admin.AssetParams{PublicID: "quickstart_butterfly"})
	if err != nil {
		fmt.Println("error")
	}
	fmt.Println("****3. Get and use details of the image****\nDetailed response:\n", resp, "\n")

	// Assign tags to the uploaded image based on its width. Save the response to the update in the variable 'update_resp'.
	if resp.Width > 900 {
		update_resp, err := cld.Admin.UpdateAsset(ctx, admin.UpdateAssetParams{
			PublicID: "quickstart_butterfly",
			Tags:     []string{"large"}})
		if err != nil {
			fmt.Println("error")
		} else {
			// Log the new tag to the console.
			fmt.Println("New tag: ", update_resp.Tags, "\n")
		}
	} else {
		update_resp, err := cld.Admin.UpdateAsset(ctx, admin.UpdateAssetParams{
			PublicID: "quickstart_butterfly",
			Tags:     []string{"small"}})
		if err != nil {
			fmt.Println("error")
		} else {
			// Log the new tag to the console.
			fmt.Println("New tag: ", update_resp.Tags, "\n")
		}
	}

}
```

More info about getting details of an asset...

* This code snippet retrieves information about the uploaded image and tags the image accordingly.
* Use the `resource` method of the [Admin API](admin_api#resources) to get the details of your image and tag it.

## 4. Transform the image

Copy and paste this into `my_file.go`:

my_file.go (continued)

```go 
func transformImage(cld *cloudinary.Cloudinary, ctx context.Context) {
	// Instantiate an object for the asset with public ID "my_image"
	qs_img, err := cld.Image("quickstart_butterfly")
	if err != nil {
		fmt.Println("error")
	}

	// Add the transformation
	qs_img.Transformation = "r_max/e_sepia"

	// Generate and log the delivery URL
	new_url, err := qs_img.String()
	if err != nil {
		fmt.Println("error")
	} else {
		print("****4. Transform the image****\nTransfrmation URL: ", new_url, "\n")
	}
}
```

More info about transformations...

* [Transformations](transformation_reference) create a modified copy of your original image. In this case, `radius="max"` creates a copy with rounded edges and `effect="sepia"` applies a special effect. 
* Optimize your image quality and format by adding [q_auto](transformation_reference#q_auto) and [f_auto](transformation_reference#f_auto) to your transformations.

## 5. Run your code

Copy and paste this into `my_file.go`:

my_file.go (continued)

```go 
func main() {
	cld, ctx := credentials()
	uploadImage(cld, ctx)
	getAssetInfo(cld, ctx)
	transformImage(cld, ctx)
}
```

In the terminal, run the following command: 

```
go run my_file.go
``` 

The following original image is uploaded to your Cloudinary account, tagged appropriately and accessible via the URL shown below. 

The transformed version of the image is accessible via the URL shown below.  

Original imagehttp://res.cloudinary.com/&ltcloud-name&gt/image/upload/v1/quickstart_butterfly

Transformed imagehttp://res.cloudinary.com/&ltcloud-name&gt/image/upload/e_sepiar_max/v1/quickstart_butterfly

Check your code...

When you run your file, you'll see the following as they occur:

**1. Set up and configure the SDK**: Your cloud name and API key is displayed.

**2. Upload an image**: The delivery URL of the uploaded asset is displayed. Copy the URL in a browser tab to see the generated image.

**3. Get and use details of the image**: The full JSON response of the `resources` method, listing attributes of the asset you uploaded, is displayed. It should look something like this: 
  
```
****3. Get and use details of the image****
Detailed response:
 {
  "asset_id": "5df5df5df5df5df5df5df5df5df5df5d",
  "public_id": "quickstart_butterfly",
  "format": "jpg",
  "version": 1616161616,
   ...
   ...
  "secure_url": "https://res.cloudinary.com/yelenik/image/upload/v1646750443/quickstart_butterfly.jpg",
  "tags": [
  ],
  "metadata": {}
} 
```

The tag that was added using the `update` method is also displayed: 

```
New tag:  ['small'] 
```
**4. Transform the image**: The HTML image tag for your transformed image is displayed. You can use this on an HTML page, and your transformed image will be generated on the fly.

## View the completed code

You can find the full code example for this quick start on [GitHub](https://github.com/cloudinary-devs/go-sdk-quickstart).

## Next steps
* Learn more about the Go SDK by visiting the other pages in this SDK guide.
* Get comprehensive details about Cloudinary features and capabilities:
    * [Upload guide](upload_images): Provides details and examples of the upload options.
    * [Image transformations guide](image_transformations): Provides details and examples of the transformations you can apply to image assets.
    * [Video transformations guide](video_manipulation_and_delivery): Provides details and examples of the transformations you can apply to video assets.
    * [Transformation URL API Reference](transformation_reference): Provides details and examples of all available transformation parameters. 
    * [Admin API guide](admin_api): Provides details and examples of the methods available for managing and organizing your media assets.