Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ jobs:
fail-fast: false
matrix:
go-version:
- 1.20.x
- 1.21.x
- 1.22.x
- 1.23.x
- 1.24.x
- 1.25.x
- 1.26.x
- 1.27.x

steps:
- name: 🔄 Checkout Repository
Expand All @@ -36,7 +35,7 @@ jobs:
echo "cloud_name: $(echo $CLOUDINARY_URL | cut -d'@' -f2)"

- name: 🧰 Install gotestsum
run: go install gotest.tools/gotestsum@v1.11.0
run: go install gotest.tools/gotestsum@v1.13.0

- name: 🧪 Run Tests
run: |
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ For the complete documentation, see the [Go SDK Guide](https://cloudinary.com/do

## Version Support

| **SDK Version** | **Go 1.13 - 1.19** | **Go 1.20** | **Go 1.21** | **Go 1.22** | **Go 1.23** |
|-----------------|--------------------|-------------|-------------|-------------|-------------|
| **2.8 & Up** | ❌ | ✔️ | ✔️ | ✔️ | ✔️ |
| **2.7** | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| **1.x** | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| **SDK Version** | **Go 1.13 - 1.19** | **Go 1.20 - 1.23** | **Go 1.24 - 1.27** |
|-----------------|--------------------|--------------------|--------------------|
| **2.8 & Up** | ❌ | ✔️ | ✔️ |
| **2.7** | ✔️ | ✔️ | ✔️ |
| **1.x** | ✔️ | ✔️ | ✔️ |

## Installation

Expand Down
6 changes: 5 additions & 1 deletion api/admin/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
"github.com/cloudinary/cloudinary-go/v2/api"
)

type contextKey string

const apiVersionKey contextKey = "api_version"

const (
analysis api.EndPoint = "analysis"
analyze api.EndPoint = "analyze"
Expand Down Expand Up @@ -46,7 +50,7 @@ Currently supports the following analysis options:
* Custom
*/
func (a *API) Analyze(ctx context.Context, params AnalyzeParams) (*AnalyzeResult, error) {
v2APICtx := context.WithValue(ctx, "api_version", "2")
v2APICtx := context.WithValue(ctx, apiVersionKey, "2")
res := &AnalyzeResult{}
_, err := a.post(v2APICtx, api.BuildPath(analysis, analyze, uri), params, res)

Expand Down
5 changes: 2 additions & 3 deletions api/admin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
Expand Down Expand Up @@ -168,7 +167,7 @@ func (a *API) postFile(ctx context.Context, path interface{}, file interface{},
func (a *API) executeRequest(ctx context.Context, method string, path interface{}, body io.Reader, queryParams string,
headers map[string]string, result interface{}) (*http.Response, error) {
apiVersion := ""
if apiVersionRaw := ctx.Value("api_version"); apiVersionRaw != nil {
if apiVersionRaw := ctx.Value(apiVersionKey); apiVersionRaw != nil {
apiVersion = apiVersionRaw.(string)
}

Expand Down Expand Up @@ -205,7 +204,7 @@ func (a *API) executeRequest(ctx context.Context, method string, path interface{

defer api.DeferredClose(resp.Body)

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion api/admin/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ type UpdateAssetParams struct {
BackgroundRemoval string `json:"background_removal,omitempty"`
QualityOverride int `json:"quality_override,omitempty"`
NotificationURL string `json:"notification_url,omitempty"`
Tags api.CldAPIArray `json:"tags,omitempty,omitempty"`
Tags api.CldAPIArray `json:"tags,omitempty"`
Context api.CldAPIMap `json:"context,omitempty"`
AdminContext []api.AdminContext `json:"admin_context,omitempty"`
FaceCoordinates api.Coordinates `json:"face_coordinates,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func BaseURL(uploadPrefix string, apiVer string) string {
}

// base64DataRegex is the regular expression for detecting base64 encoded strings.
var base64DataRegex = regexp.MustCompile("^data:([\\w-]+/[\\w\\-+.]+)?(;[\\w-]+=[\\w-]+)*;base64,([a-zA-Z0-9/+\\n=]+)$")
var base64DataRegex = regexp.MustCompile(`^data:([\w-]+/[\w\-+.]+)?(;[\w-]+=[\w-]+)*;base64,([a-zA-Z0-9/+\n=]+)$`)

// AssetType is the type of the asset.
type AssetType string
Expand Down
3 changes: 1 addition & 2 deletions api/uploader/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -358,7 +357,7 @@ func (u *API) postBody(ctx context.Context, urlPath interface{}, bodyReader io.R

defer api.DeferredClose(resp.Body)

return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

func setAuth(u *API, req *http.Request) {
Expand Down
3 changes: 3 additions & 0 deletions api/uploader/upload_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ func getAutoVideoDetailsTestCases() []UploadAPIAcceptanceTestCase {
AutoVideoDetails: &api.AutoVideoDetails{
Fields: []string{"title", "description"},
},
Unsigned: api.Bool(true),
Timestamp: 123456789,
})
},
ResponseTest: func(response interface{}, t *testing.T) {},
Expand Down Expand Up @@ -292,6 +294,7 @@ func TestUploadAPI_Acceptance(t *testing.T) {
testUploadAPIByTestCases(getAuthorizationTestCases(), t)
testUploadAPIByTestCases(getFolderDecouplingTestCases(), t)
testUploadAPIByTestCases(getAutoTranscriptionTestCases(), t)
testUploadAPIByTestCases(getAutoVideoDetailsTestCases(), t)
testUploadAPIByTestCases(getBooleanValuesTestCases(), t)
testUploadAPIByTestCases(getVariousValuesTestCases(), t)
testUploadAPIByTestCases(getUploadConfigTestCases(), t)
Expand Down
2 changes: 1 addition & 1 deletion api/uploader/upload_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (u *API) Upload(ctx context.Context, file interface{}, uploadParams UploadP
}

err = api.HandleRawResponse(body, result)
return result, nil
return result, err
}

// Eager contains information about eagerly transformed derived assets.
Expand Down
27 changes: 16 additions & 11 deletions api/uploader/upload_asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"runtime"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -310,7 +310,7 @@ func TestUploader_UploadWithResponsiveBreakpoints(t *testing.T) {
}

if eResp == nil {
t.Error(resp)
t.Fatal(resp)
}

assert.Len(t, eResp.ResponsiveBreakpoints, 2)
Expand Down Expand Up @@ -364,7 +364,7 @@ func populateLargeImage() string {
"\xFC\x00\x00\x00\x00\x00\x00\x00\x00fff\xFC\x00\x00\x00\x00\x00\x00\x00\x00\xC4\xF5(\xFF\x00\x00\x00" +
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

tmpFile, err := ioutil.TempFile(cldtest.TestDataDir(), largeImagePublicID+".*.bmp")
tmpFile, err := os.CreateTemp(cldtest.TestDataDir(), largeImagePublicID+".*.bmp")
if err != nil {
log.Fatal(err)
}
Expand All @@ -390,24 +390,29 @@ func readMemoryAlloc() uint64 {
}

func watchMemoryAllocation() func() uint64 {
var maxAlloc uint64
proceed := true
var maxAlloc atomic.Uint64
var proceed atomic.Bool
proceed.Store(true)
initialRead := readMemoryAlloc()
go func() {
for i := 0; i < 10000; i++ {
if !proceed {
if !proceed.Load() {
return
}
read := readMemoryAlloc()
if read-initialRead > maxAlloc {
maxAlloc = read - initialRead
// Alloc is the live heap, which can drop below the baseline once the
// GC collects. Only consider growth, otherwise the unsigned
// subtraction underflows.
if read := readMemoryAlloc(); read > initialRead {
if grown := read - initialRead; grown > maxAlloc.Load() {
maxAlloc.Store(grown)
}
}
time.Sleep(time.Millisecond * 500)
}
}()

return func() uint64 {
proceed = false
return maxAlloc
proceed.Store(false)
return maxAlloc.Load()
}
}
3 changes: 0 additions & 3 deletions asset/auth_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import (
)

const authTokenKey = "00112233FF99"
const authTokenAltKey = "CCBB2233FF00"

const duration = 300
const startTime = 11111111

const authTokenTestImage = "sample.jpg"
const authTokenTestConfigACL = "/*/t_foobar"
const authTokenTestPath = "http://res.cloudinary.com/test123/image/upload/v1486020273/sample.jpg"

var authTokenConfig = config.AuthToken{
Duration: duration,
Expand Down
2 changes: 1 addition & 1 deletion cloudinary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestCloudinary_CreateInstance(t *testing.T) {
t.Error("Failed creating Cloudinary instance from Cloudinary URL.")
}

c, err := NewFromURL("")
_, err := NewFromURL("")
if err == nil || err.Error() != "must provide CLOUDINARY_URL" {
t.Error("Error expected, got: ", err)
}
Expand Down
2 changes: 1 addition & 1 deletion config/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestConfiguration_CreateInstance(t *testing.T) {
assert.Equal(t, cldtest.CloudName, c.Cloud.CloudName)
assert.Equal(t, signature.SHA256, c.Cloud.SignatureAlgorithm)

c, err = config.NewFromURL("")
_, err = config.NewFromURL("")
if err == nil || err.Error() != "must provide CLOUDINARY_URL" {
t.Error("Error expected, got: ", err)
}
Expand Down
3 changes: 2 additions & 1 deletion gen/generate_setters/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"strings"
"text/template"
"unicode"
)

// Generate template for setters file
Expand All @@ -31,7 +32,7 @@ func ({{ .Receiver}} *{{ .StructName}}) <<index .FuncName %d>>(<<index .ParamNam

for i, t := range setters {
stringTemplate += fmt.Sprintf(functionTemplate, i, i, i, i, i)
templateData.FuncName[i] = strings.Title(t.Param) + t.Suffix
templateData.FuncName[i] = string(unicode.ToUpper(rune(t.Param[0]))) + t.Param[1:] + t.Suffix
templateData.Type[i] = t.Type
templateData.ParamName[i] = t.Param
}
Expand Down
7 changes: 2 additions & 5 deletions internal/cldtest/cldtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/cloudinary/cloudinary-go/v2/api"
"io"
"io/ioutil"
"math/rand"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -218,9 +217,7 @@ func GetTestSuffix() string {
testSuffix := os.Getenv("GITHUB_RUN_ID")

if testSuffix == "" {
rand.Seed(time.Now().UnixNano())
// Generate a random number between 100000 and 999999 to ensure 6 digits
testSuffix = strconv.Itoa(rand.Intn(900000) + 100000)
testSuffix = strconv.Itoa(rand.New(rand.NewSource(time.Now().UnixNano())).Intn(900000) + 100000)
}

return testSuffix
Expand Down Expand Up @@ -310,7 +307,7 @@ func GetTestHandler(response string, t *testing.T, callCounter *int, ep Expected

if r.Method == http.MethodPost || r.Method == http.MethodPut || r.Method == http.MethodDelete {
if r.Body != nil && ep.Body != nil {
bodyString, err := ioutil.ReadAll(r.Body)
bodyString, err := io.ReadAll(r.Body)

if err != nil {
t.Error(err)
Expand Down
4 changes: 2 additions & 2 deletions scripts/allocate_test_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
Expand All @@ -26,7 +26,7 @@ func main() {

defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)

if nil != err {
log.Fatal("error happened reading the body", err)
Expand Down
Loading