imagekit

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2020 License: MIT Imports: 14 Imported by: 0

README

imagekit-go

A Go client library for accessing the ImageKit.io API.

Installation

Use the following command to download this module:

go get github.com/vlepeshev/imagekit-go

Usage

import "github.com/vlepeshev/imagekit-go"

Construct a new API client, then use to access the ImageKit.io API. For example:

opts := imagekit.Options{
    PublicKey:  "Your API Private Key",
    PrivateKey: "Your API Public Key",
}

ik, err := imagekit.NewClient(&opts)
if err != nil {
    // error handling
}

Upload image to your ImageKit.io Media Library:

ur := imagekit.UploadRequest{
    File:              file, // []byte OR *url.URL OR url.URL OR base64 string
    FileName:          "file name",
    UseUniqueFileName: false,
    Tags:              []string{},
    Folder:            "/",
    IsPrivateFile:     false,
    CustomCoordinates: "",
    ResponseFields:    nil,
}

ctx := context.Background()

upr, err := ik.Upload.ServerUpload(ctx, &ur)
if err != nil {
    // error handling
}

Other methods are pretty straightforward and doesn't need extra explanations. For more info please read library's documentation from go.dev and ImageKit.io API documentation.

Documentation

Overview

Package imagekit provides Go client to work with Imagekit.io image processing service API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	// Upload API.
	Upload *UploadService
	// Media API.
	Media *MediaService
	// Metadata API.
	Metadata *MetadataService
	// contains filtered or unexported fields
}

Client manages communication with the API.

func NewClient

func NewClient(opts *Options) (*Client, error)

NewClient returns a new API client.

type DeleteFilesRequest

type DeleteFilesRequest struct {
	// FileIDs is the list of unique ID of the uploaded files.
	FileIDs []string `json:"fileIds"`
}

type DeleteFilesResponse

type DeleteFilesResponse struct {
	// SuccessfullyDeletedFileIDs is the array of fileIds which are successfully deleted.
	SuccessfullyDeletedFileIDs []string `json:"successfullyDeletedFileIds"`
}

type ErrorResponse

type ErrorResponse struct {
	Response       *http.Response
	Message        string   `json:"message"`
	Help           string   `json:"help"`
	MissingFileIDs []string `json:"missingFileIds,omitempty"`
}

ErrorResponse reports error caused by an API request.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

Errors provides string error of error repsponse r.

type GetFileDetailsResponse

type GetFileDetailsResponse struct {
	// FileID is the unique ID of the uploaded file.
	FileID string `json:"fileId"`
	// Type of item. It can be either file or imageFolder.
	Type string `json:"type"`
	// Name of the file or imageFolder.
	Name string `json:"name"`
	// FilePath of the file. In the case of an image, you can use this path to construct different transform.
	FilePath string `json:"filePath"`
	// Tags is array of tags associated with the image.
	Tags []string `json:"tags"`
	// IsPrivateFile is the file marked as private. It can be either "true" or "false".
	IsPrivateFile bool `json:"isPrivateFile"`
	// CustomCoordinates is the value of custom coordinates associated with the image in format "x,y,width,height".
	CustomCoordinates string `json:"customCoordinates"`
	// URL of the file.
	URL string `json:"url"`
	// Thumbnail is a small thumbnail URL in case of an image.
	Thumbnail string `json:"thumbnail"`
	// FileType of the file, it could be either image or non-image.
	FileType string `json:"fileType"`
}

type ListAndSearchFileRequest

type ListAndSearchFileRequest struct {
	// Path if you want to limit the search within a specific imageFolder.
	//
	// For example, /sales-banner/ will only search in imageFolder sales-banner.
	Path string
	// FileType to include in result set.
	//
	// Accepts three values:
	// all - include all types of files in result set
	// image - only search in image type files
	// non-image - only search in files which are not image, e.g., JS or CSS or video files.
	// Default value - all.
	FileType string
	// Files matching any of the Tags are included in result response.
	//
	// If no tag is matched, the file is not included in result set.
	Tags []string
	// IncludeFolder in search results or not. By default only files are searched.
	//
	// Accepts true and false. If this is set to true then tags and FileType parameters are ignored.
	IncludeFolder bool
	// Name of the file or imageFolder.
	Name string
	// Limit the maximum number of results to return in response.
	//
	// Minimum value - 1
	// Maximum value - 1000
	// Default value - 1000
	Limit int
	// Skip the number of results before returning results.
	//
	// Minimum value - 0
	// Default value - 0
	Skip int
}

type ListAndSearchFileResponse

type ListAndSearchFileResponse struct {
	// FileID is the unique ID of the uploaded file.
	FileID string `json:"fileId"`
	// Type of item. It can be either file or imageFolder.
	Type string `json:"type"`
	// Name of the file or imageFolder.
	Name string `json:"name"`
	// FilePath of the file. In the case of an image, you can use this path to construct different transform.
	FilePath string `json:"filePath"`
	// Tags is array of tags associated with the image.
	Tags []string `json:"tags"`
	// IsPrivateFile is the file marked as private. It can be either "true" or "false".
	IsPrivateFile bool `json:"isPrivateFile"`
	// CustomCoordinates is the value of custom coordinates associated with the image in format "x,y,width,height".
	CustomCoordinates string `json:"customCoordinates"`
	// URL of the file.
	URL string `json:"url"`
	// Thumbnail is a small thumbnail URL in case of an image.
	Thumbnail string `json:"thumbnail"`
	// FileType of the file, it could be either image or non-image.
	FileType string `json:"fileType"`
}

type MediaService

type MediaService service

MediaService handles communication with the media related methods of the Imagekit.io API.

func (*MediaService) DeleteFile

func (s *MediaService) DeleteFile(ctx context.Context, fid string) error

DeleteFile deletes file with id and all its transform.

func (*MediaService) DeleteFiles

DeleteFiles deletes multiple files uploaded in media library using bulk file delete API.

When you delete a file, all its transform are also deleted. However, if a file or specific transformation has been requested in the past, then the response is cached in CDN. You can purge the cache from the CDN using purge API.

func (*MediaService) GetFileDetails

func (s *MediaService) GetFileDetails(ctx context.Context, fid string) (*GetFileDetailsResponse, error)

GetFileDetails such as tags, customCoordinates, and isPrivate properties using get file detail API.

func (*MediaService) ListAndSearchFile

ListAndSearchFile lists all the uploaded files in your Imagekit.io media library.

func (*MediaService) PurgeCache

PurgeCache will purge CDN and Imagekit.io internal cache.

func (*MediaService) PurgeCacheStatus

func (s *MediaService) PurgeCacheStatus(ctx context.Context, rid string) (*PurgeCacheStatusResponse, error)

PurgeCacheStatus gets the status of submitted purge request.

func (*MediaService) UpdateFileDetails

GetFileDetails such as tags, customCoordinates, and isPrivate properties using get file detail API.

type MetadataEXIF

type MetadataEXIF struct {
	ApertureValue            float32 `json:"ApertureValue"`
	ColorSpace               int     `json:"ColorSpace"`
	CreateDate               string  `json:"CreateDate"`
	CustomRendered           int     `json:"CustomRendered"`
	DateTimeOriginal         string  `json:"DateTimeOriginal"`
	ExifImageHeight          int     `json:"ExifImageHeight"`
	ExifImageWidth           int     `json:"ExifImageWidth"`
	ExifVersion              string  `json:"ExifVersion"`
	ExposureCompensation     int     `json:"ExposureCompensation"`
	ExposureMode             int     `json:"ExposureMode"`
	ExposureProgram          int     `json:"ExposureProgram"`
	ExposureTime             float32 `json:"ExposureTime"`
	FNumber                  float32 `json:"FNumber"`
	Flash                    int     `json:"Flash"`
	FlashpixVersion          string  `json:"FlashpixVersion"`
	FocalLength              int     `json:"FocalLength"`
	FocalPlaneResolutionUnit int     `json:"FocalPlaneResolutionUnit"`
	FocalPlaneXResolution    float32 `json:"FocalPlaneXResolution"`
	FocalPlaneYResolution    float32 `json:"FocalPlaneYResolution"`
	ISO                      int     `json:"ISO"`
	InteropOffset            int     `json:"InteropOffset"`
	MeteringMode             int     `json:"MeteringMode"`
	SceneCaptureType         int     `json:"SceneCaptureType"`
	ShutterSpeedValue        float32 `json:"ShutterSpeedValue"`
	SubSecTime               string  `json:"SubSecTime"`
	SubSecTimeDigitized      string  `json:"SubSecTimeDigitized"`
	SubSecTimeOriginal       string  `json:"SubSecTimeOriginal"`
	WhiteBalance             int     `json:"WhiteBalance"`
}

type MetadataGPS

type MetadataGPS struct {
	GPSVersionID []int `json:"GPSVersionID"`
}

type MetadataImage

type MetadataImage struct {
	EXIFOffset       int    `json:"ExifOffset"`
	GPSInfo          int    `json:"GPSInfo"`
	Make             string `json:"Make"`
	Model            string `json:"Model"`
	ModifyDate       string `json:"ModifyDate"`
	Orientation      int    `json:"Orientation"`
	ResolutionUnit   int    `json:"ResolutionUnit"`
	Software         string `json:"Software"`
	XResolution      int    `json:"XResolution"`
	YCbCrPositioning int    `json:"YCbCrPositioning"`
	YResolution      int    `json:"YResolution"`
}

type MetadataInteroperability

type MetadataInteroperability struct {
	InteropIndex   string `json:"InteropIndex"`
	InteropVersion string `json:"InteropVersion"`
}

type MetadataMakernote

type MetadataMakernote struct {
}

type MetadataResponse

type MetadataResponse struct {
	Density         int                   `json:"density"`
	EXIF            *MetadataResponseEXIF `json:"exif"`
	Format          string                `json:"format"`
	HasColorProfile bool                  `json:"hasColorProfile"`
	HasTransparency bool                  `json:"hasTransparency"`
	Height          int                   `json:"height"`
	PHash           string                `json:"pHash"`
	Quality         int                   `json:"quality"`
	Size            int                   `json:"size"`
	Width           int                   `json:"width"`
}

type MetadataResponseEXIF

type MetadataResponseEXIF struct {
	EXIF             *MetadataEXIF             `json:"exif"`
	GPS              *MetadataGPS              `json:"gps"`
	Image            *MetadataImage            `json:"image"`
	Interoperability *MetadataInteroperability `json:"interoperability"`
	Makernote        *MetadataMakernote        `json:"makernote"`
	Thumbnail        *MetadataThumbnail        `json:"thumbnail"`
}

type MetadataService

type MetadataService service

MetadataService handles communication with the metadata related methods of the ImageKit API.

func (*MetadataService) GetForUploaded

func (s *MetadataService) GetForUploaded(ctx context.Context, fid string) (*MetadataResponse, error)

GetForUploaded gets image exif, pHash and other metadata for uploaded files in Imagekit.io media library using this API.

func (*MetadataService) GetFromRemote

func (s *MetadataService) GetFromRemote(ctx context.Context, URL string) (*MetadataResponse, error)

GetFromRemote gets image exif, pHash and other metadata from Imagekit.io powered remote URL using this API.

type MetadataThumbnail

type MetadataThumbnail struct {
	Compression     int `json:"Compression"`
	ResolutionUnit  int `json:"ResolutionUnit"`
	ThumbnailLength int `json:"ThumbnailLength"`
	ThumbnailOffset int `json:"ThumbnailOffset"`
	XResolution     int `json:"XResolution"`
	YResolution     int `json:"YResolution"`
}

type Options

type Options struct {
	PublicKey  string
	PrivateKey string
}

Options contains all necessary data to make requests to the API.

type PurgeCacheRequest

type PurgeCacheRequest struct {
	// URL is the exact URL of the file to be purged.
	//
	// For example - https://ik.imageki.io/your_imagekit_id/rest-of-the-file-path.jpg.
	URL string `json:"url"`
}

type PurgeCacheResponse

type PurgeCacheResponse struct {
	// RequestID which can be used to get the purge request status.
	RequestID string `json:"requestId"`
}

type PurgeCacheStatusResponse

type PurgeCacheStatusResponse struct {
	// Status is the current status of a submitted purge request.
	//
	// It can be either:
	// Pending - The request has been successfully submitted, and purging is in progress.
	// Complete - The purge request has been successfully completed. And now you should get a fresh object. Check the Age header in response to confirm this.
	Status string `json:"status"`
}

type UpdateFileDetailsRequest

type UpdateFileDetailsRequest struct {
	// Tags associated with the file.
	Tags []string `json:"tags"`
	// CustomCoordinates define an important area in the image. This is only relevant for image type files.
	CustomCoordinates string `json:"customCoordinates"`
}

type UpdateFileDetailsResponse

type UpdateFileDetailsResponse struct {
	// FileID is the unique ID of the uploaded file.
	FileID string `json:"fileId"`
	// Type of item. It can be either file or imageFolder.
	Type string `json:"type"`
	// Name of the file or imageFolder.
	Name string `json:"name"`
	// FilePath of the file. In the case of an image, you can use this path to construct different transform.
	FilePath string `json:"filePath"`
	// Tags is array of tags associated with the image.
	Tags []string `json:"tags"`
	// IsPrivateFile is the file marked as private. It can be either "true" or "false".
	IsPrivateFile bool `json:"isPrivateFile"`
	// CustomCoordinates is the value of custom coordinates associated with the image in format "x,y,width,height".
	CustomCoordinates string `json:"customCoordinates"`
	// URL of the file.
	URL string `json:"url"`
	// Thumbnail is a small thumbnail URL in case of an image.
	Thumbnail string `json:"thumbnail"`
	// FileType of the file, it could be either image or non-image.
	FileType string `json:"fileType"`
}

type UploadRequest

type UploadRequest struct {
	// File to upload.
	File interface{}
	// FileName with which the file has to be uploaded.
	FileName string
	// UseUniqueFileName to whether to use a unique filename for this file or not.
	UseUniqueFileName bool
	// Tags while uploading the file.
	Tags []string
	// Folder path (e.g. /images/imageFolder/) in which the image has to be uploaded. If the imageFolder(s) didn't exist before, a new imageFolder(s) is created.
	Folder string
	// IsPrivateFile to whether to mark the file as private or not. This is only relevant for image type files.
	IsPrivateFile bool
	// CustomCoordinates define an important area in the image. This is only relevant for image type files.
	CustomCoordinates string
	// ResponseFields contains values of the fields that you want ImageKit.io to return in response.
	ResponseFields []string
}

type UploadResponse

type UploadResponse struct {
	// FileID is unique.
	//
	// Store this fileld in your database, as this will be used to perform update action on this file.
	FileID string `json:"fileId"`
	// Name of the uploaded file.
	Name string `json:"name"`
	// URL of the file.
	URL string `json:"url"`
	// Thumbnail is a small thumbnail URL in case of an image.
	Thumbnail string `json:"thumbnail"`
	// Height of the uploaded image file.
	//
	// Only applicable when file type is image.
	Height int `json:"height"`
	// Width of the uploaded image file.
	//
	// Only applicable when file type is image.
	Width int `json:"width"`
	// Size of the uploaded file in bytes.
	Size int `json:"size"`
	// FileType can either be "image" or "non-image".
	FileType string `json:"fileType"`
	// FilePath is the path of the file uploaded.
	//
	// It includes any imageFolder that you specified while uploading.
	FilePath string `json:"filePath"`
	// Tags is array of tags associated with the image.
	Tags []string `json:"tags"`
	// IsPrivateFile is the file marked as private.
	//
	// It can be either "true" or "false".
	IsPrivateFile bool `json:"isPrivateFile"`
	// CustomCoordinates is the value of custom coordinates associated with the image in format "x,y,width,height".
	CustomCoordinates string `json:"customCoordinates"`
	// Metadata of the upload file.
	//
	// Use responseFields property in request to get the metadata returned in response of upload API.
	Metadata interface{} `json:"metadata"`
}

type UploadService

type UploadService service

UploadService handles communication with the upload related methods of the ImageKit API.

func (*UploadService) ServerUpload

func (s *UploadService) ServerUpload(ctx context.Context, r *UploadRequest) (*UploadResponse, error)

ServerUpload uploads file to ImageKit.io.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL