Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
23 changes: 6 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,21 @@ jobs:
test:
strategy:
matrix:
go-version: [1.13.x]
go-version: ['1.25']
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v1
- name: Restore Cache
uses: actions/cache@preview
id: cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-${{ hashFiles('**/go.sum') }}
- name: Install tooling deps
run: go get golang.org/x/lint/golint@v0.0.0-20201208152925-83fdc39ff7b5
uses: actions/checkout@v4
- name: Vet
run: go vet ./...
- name: Test
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
PUBLIC_KEY: ${{ secrets.PUBLIC_KEY }}
CUSTOM_STORAGE_BUCKET: ${{ secrets.CUSTOM_STORAGE_BUCKET }}
run: |
# TODO: move this to env block
export GOPATH="$(go env GOPATH)"
export PATH="$GOPATH/bin:$PATH"

make test-full
run: go test -v -race ./...
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
## 0.2.0

BREAKING CHANGES:

* Target REST API v0.7 (previously v0.5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Target REST API v0.7 (previously v0.5)
* Change client for REST API to use v0.7 (previously v0.5)

* Remove `ImageInfo` and `VideoMeta` fields from `file.BasicFileInfo` — use `ContentInfo.Image` and `ContentInfo.Video`
* Remove `RecognitionInfo` field from `file.Info` — use `AppData`
* Add `Metadata` and `AppData` fields to `file.Info`
* Remove `group.Store()` method (endpoint removed in v0.7)
* Remove `file.Copy()` method and `file.CopyParams` type — use `LocalCopy()` and `RemoteCopy()`
* Remove `file.OrderBySizeAsc` and `file.OrderBySizeDesc` constants (not supported in v0.7)
* Remove `APIv05` and `APIv06` constants
* Minimum Go version is now 1.25
Comment on lines +5 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good practice to group your actions.
Changes, Adds, Removals together, not in a seemingly random order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will organize it before 2.0.0 release

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Minimum Go version is now 1.25
* Change Go version to 1.25


IMPROVEMENTS:

* Add `UserAgent` field to `ucare.Config` for custom agent identification
* Replace `http.NewRequest` + `WithContext` with `http.NewRequestWithContext`
* Throttle retry loops now respect context cancellation
* Replace `ioutil` usage with `io` equivalents
* Replace `go-env` dependency with `os.Getenv`
* Update `stretchr/testify` to v1.10.0
* Update CI: Go 1.25, modern GitHub Actions versions, remove deprecated golint
* Integration tests skip gracefully when credentials are not set
* Fix errors in package documentation examples

## 1.2.1 (September 1, 2020)

IMPROVEMENTS:
Expand Down
15 changes: 5 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
GO ?= go

vet:
@$(GO) vet ./...
.PHONY: vet

lint: vet
@golint -set_exit_status ./...
.PHONY: lint

test: lint
test: vet
@$(GO) test -v -race -short ./...
.PHONY: test

test-full: lint
test-full: vet
@$(GO) test -v -race ./...
.PHONY: test-full

vet:
@$(GO) vet ./...
.PHONY: vet
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Golang API client for Uploadcare

![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)
[![GoDoc](http://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/uploadcare/uploadcare-go/ucare)
![](https://github.com/uploadcare/uploadcare-go/workflows/test/badge.svg)
[![GoDoc](http://img.shields.io/badge/godoc-reference-blue.svg)](http://pkg.go.dev/github.com/uploadcare/uploadcare-go/v2/ucare)
![](https://github.com/uploadcare/uploadcare-go/v2/workflows/test/badge.svg)

Uploadcare Golang API client that handles uploads and further operations with files by wrapping Uploadcare Upload and REST APIs.

Expand All @@ -14,25 +14,25 @@ Uploadcare Golang API client that handles uploads and further operations with fi

## Requirements

go1.13
Go 1.25

## Installation

Install uploadcare-go with:

```
go get -u -v github.com/uploadcare/uploadcare-go/...
go get -u -v github.com/uploadcare/uploadcare-go/v2/...
```

Then import it using:

```go
import (
"github.com/uploadcare/uploadcare-go/ucare"
"github.com/uploadcare/uploadcare-go/file"
"github.com/uploadcare/uploadcare-go/group"
"github.com/uploadcare/uploadcare-go/upload"
"github.com/uploadcare/uploadcare-go/conversion"
"github.com/uploadcare/uploadcare-go/v2/ucare"
"github.com/uploadcare/uploadcare-go/v2/file"
"github.com/uploadcare/uploadcare-go/v2/group"
"github.com/uploadcare/uploadcare-go/v2/upload"
"github.com/uploadcare/uploadcare-go/v2/conversion"
)
```

Expand All @@ -48,7 +48,6 @@ creds := ucare.APICreds{

conf := &ucare.Config{
SignBasedAuthentication: true,
APIVersion: ucare.APIv06,
}

client, err := ucare.NewClient(creds, conf)
Expand All @@ -59,7 +58,7 @@ if err != nil {

## Usage

For a comprehensive list of examples, check out the [API documentation](https://godoc.org/github.com/uploadcare/uploadcare-go/ucare).
For a comprehensive list of examples, check out the [API documentation](https://pkg.go.dev/github.com/uploadcare/uploadcare-go/v2/ucare).
Below are a few usage examples:

Getting a list of files:
Expand All @@ -69,7 +68,7 @@ fileSvc := file.NewService(client)

listParams := file.ListParams{
Stored: ucare.Bool(true),
OrderBy: ucare.String(file.OrderBySizeAsc),
OrderBy: ucare.String(file.OrderByUploadedAtDesc),
}

fileList, err := fileSvc.List(context.Background(), listParams)
Expand Down Expand Up @@ -98,9 +97,9 @@ if err != nil {
// handle error
}

if file.IsImage {
h := file.ImageInfo.Height
w := file.ImageInfo.Width
if file.IsImage && file.ContentInfo != nil && file.ContentInfo.Image != nil {
h := file.ContentInfo.Image.Height
w := file.ContentInfo.Image.Width
fmt.Printf("image size: %dx%d\n", h, w)
}
```
Expand Down Expand Up @@ -128,11 +127,11 @@ if err != nil {

## Useful links

[Golang API client documentation](https://godoc.org/github.com/uploadcare/uploadcare-go/ucare)
[Golang API client documentation](https://pkg.go.dev/github.com/uploadcare/uploadcare-go/v2/ucare)
[Uploadcare documentation](https://uploadcare.com/docs/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-go)
[Upload API reference](https://uploadcare.com/api-refs/upload-api/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-go)
[REST API reference](https://uploadcare.com/api-refs/rest-api/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-go)
[Changelog](https://github.com/uploadcare/uploadcare-go/blob/master/CHANGELOG.md)
[Changelog](https://github.com/uploadcare/uploadcare-go/v2/blob/master/CHANGELOG.md)
[Contributing guide](https://github.com/uploadcare/.github/blob/master/CONTRIBUTING.md)
[Security policy](https://github.com/uploadcare/uploadcare-go/security/policy)
[Security policy](https://github.com/uploadcare/uploadcare-go/v2/security/policy)
[Support](https://github.com/uploadcare/.github/blob/master/SUPPORT.md)
2 changes: 1 addition & 1 deletion conversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"net/http"

"github.com/uploadcare/uploadcare-go/internal/codec"
"github.com/uploadcare/uploadcare-go/v2/internal/codec"
)

// Params holds conversion job params
Expand Down
2 changes: 1 addition & 1 deletion conversion/log.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package conversion

import (
"github.com/uploadcare/uploadcare-go/uclog"
"github.com/uploadcare/uploadcare-go/v2/uclog"
)

var log uclog.Logger
Expand Down
6 changes: 3 additions & 3 deletions conversion/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package conversion
import (
"context"

"github.com/uploadcare/uploadcare-go/internal/config"
"github.com/uploadcare/uploadcare-go/internal/svc"
"github.com/uploadcare/uploadcare-go/ucare"
"github.com/uploadcare/uploadcare-go/v2/internal/config"
"github.com/uploadcare/uploadcare-go/v2/internal/svc"
"github.com/uploadcare/uploadcare-go/v2/ucare"
)

// Service describes all conversion related API
Expand Down
2 changes: 1 addition & 1 deletion file/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"net/http"

"github.com/uploadcare/uploadcare-go/internal/codec"
"github.com/uploadcare/uploadcare-go/v2/internal/codec"
)

type batchParams []string
Expand Down
43 changes: 2 additions & 41 deletions file/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,10 @@ import (
"context"
"net/http"

"github.com/uploadcare/uploadcare-go/internal/codec"
"github.com/uploadcare/uploadcare-go/ucare"
"github.com/uploadcare/uploadcare-go/v2/internal/codec"
"github.com/uploadcare/uploadcare-go/v2/ucare"
)

// CopyParams is used when copy original files or their modified
// versions to default storage. Source files MAY either be stored or just
// uploaded and MUST NOT be deleted
type CopyParams struct {
LocalCopyParams

// Target identifies a custom storage name related to your project.
// Implies you are copying a file to a specified custom storage. Keep in
// mind you can have multiple storages associated with a single S3
// bucket.
Target *string `json:"target"`

// Pattern is used to specify file names Uploadcare passes to a custom
// storage. In case the parameter is omitted, we use pattern of your
// custom storage. Use any combination of allowed values:
// file.PatternDefault = ${uuid}/${auto_filename}
// file.PatternAutoFileName = ${filename} ${effects} ${ext}
// file.PatternEffects = processing operations put into a CDN URL
// file.PatternFileName = original filename, no extension
// file.PatternID = file UUID
// file.PatternExt = file extension, leading dot, e.g. .jpg
Pattern *string `json:"pattern"`
}

// LocalCopyParams is used when copy original files or their modified
// versions to default storage
type LocalCopyParams struct {
Expand All @@ -57,21 +33,6 @@ func (d *LocalCopyParams) EncodeReq(req *http.Request) error {
return codec.EncodeReqBody(d, req)
}

// Copy is the APIv05 version of the LocalCopy and RemoteCopy, use them instead
func (s service) Copy(
ctx context.Context,
params CopyParams,
) (data LocalCopyInfo, err error) {
err = s.svc.ResourceOp(
ctx,
http.MethodPost,
copyPathFormat,
&params,
&data,
)
return
}

// LocalCopy is used to copy original files or their modified versions to
// default storage. Source files MAY either be stored or just uploaded and MUST
// NOT be deleted
Expand Down
24 changes: 10 additions & 14 deletions file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package file

import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/uploadcare/uploadcare-go/internal/config"
"github.com/uploadcare/uploadcare-go/v2/internal/config"
)

// Info acquires some file-specific info
Expand Down Expand Up @@ -58,15 +59,7 @@ type BasicFileInfo struct {
// ID is a file unique id (UUID)
ID string `json:"uuid"`

// ImageInfo holds image metadata
ImageInfo *ImageInfo `json:"image_info"`

// VideoMeta holds video metadata
VideoMeta *VideoMeta `json:"video_info"`

// ContentInfo holds information about file content.
// ImageInfo and VideoMeta are duplicates of this data,
// left for compatibility.
// ContentInfo holds information about file content
ContentInfo *ContentInfo `json:"content_info"`

// MimeType specifies file MIME-type
Expand Down Expand Up @@ -110,13 +103,16 @@ type Info struct {
// gphotos, etc
Source *string `json:"source"`

// Variatios is a dictionary of other files that has been created using
// Variations is a dictionary of other files that has been created using
// this file as source. Used for video, document and etc. conversion
Variations *map[string]string `json:"variations"`

// RecognitionInfo is a dictionary of file categories with it"s
// confidence
RecognitionInfo map[string]float64 `json:"rekognition_info"`
// Metadata is a user-defined key-value metadata for the file
Metadata map[string]string `json:"metadata"`

// AppData holds application-specific data from add-ons (e.g. recognition results).
// The structure varies per add-on, so values are raw JSON.
AppData map[string]json.RawMessage `json:"appdata"`
}

// Image color mode contants
Expand Down
2 changes: 1 addition & 1 deletion file/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"time"

"github.com/uploadcare/uploadcare-go/internal/codec"
"github.com/uploadcare/uploadcare-go/v2/internal/codec"
)

// ListParams holds all possible params for for the List method
Expand Down
2 changes: 1 addition & 1 deletion file/log.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package file

import (
"github.com/uploadcare/uploadcare-go/uclog"
"github.com/uploadcare/uploadcare-go/v2/uclog"
)

var log uclog.Logger
Expand Down
12 changes: 4 additions & 8 deletions file/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ package file
import (
"context"

"github.com/uploadcare/uploadcare-go/internal/config"
"github.com/uploadcare/uploadcare-go/internal/svc"
"github.com/uploadcare/uploadcare-go/ucare"
"github.com/uploadcare/uploadcare-go/v2/internal/config"
"github.com/uploadcare/uploadcare-go/v2/internal/svc"
"github.com/uploadcare/uploadcare-go/v2/ucare"
)

// Service describes all file related API
Expand All @@ -23,7 +23,6 @@ type Service interface {
Delete(ctx context.Context, id string) (Info, error)
BatchStore(ctx context.Context, ids []string) (BatchInfo, error)
BatchDelete(ctx context.Context, ids []string) (BatchInfo, error)
Copy(context.Context, CopyParams) (LocalCopyInfo, error)
LocalCopy(context.Context, LocalCopyParams) (LocalCopyInfo, error)
RemoteCopy(context.Context, RemoteCopyParams) (RemoteCopyInfo, error)
}
Expand All @@ -41,17 +40,14 @@ const (
batchStorePathFormat = "/files/storage/"
batchDeletePathFormat = "/files/storage/"

copyPathFormat = "/files/"
localCopyPathFormat = "/files/local_copy/"
remoteCopyPathFormat = "/files/remote_copy/"
)

// OrderBy predefined constants to be used in request params
// OrderBy predefined constants to be used in request params.
const (
OrderByUploadedAtAsc = "datetime_uploaded"
OrderByUploadedAtDesc = "-datetime_uploaded"
OrderBySizeAsc = "size"
OrderBySizeDesc = "-size"
)

// Copy file params constants
Expand Down
Loading
Loading