silverdile

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const MaxResizeSize = 2560
View Source
const MinResizeSize = 0

Variables

View Source
var ErrCloudStorage = &Error{
	Code:    "CloudStorage",
	Message: "failed cloud storage access",
	KV:      map[string]interface{}{},
}

ErrCloudStorage is Cloud Storage への API Request でエラーが発生した時に返す

View Source
var ErrInternalError = &Error{
	Code:    "InternalError",
	Message: "internal error",
	KV:      map[string]interface{}{},
}

ErrInternalError is 何らかのエラーが発生した時に返す

View Source
var ErrInvalidArgument = &Error{
	Code:    "InvalidArgument",
	Message: "invalid argument",
	KV:      map[string]interface{}{},
}

ErrInvalidArgument is 引数に問題がある時に返す

View Source
var ErrNeedConvert = &Error{
	Code:    "NeedConvert",
	Message: "need to convert the object",
	KV:      map[string]interface{}{},
}

ErrNeedConvert is Cloud Storage に キャッシュが見つからず、変換を行う必要がある時に返す

View Source
var ErrNotFound = &Error{
	Code:    "NotFound",
	Message: "not found",
	KV:      map[string]interface{}{},
}

ErrNotFound is 見つからなかった時に返す

Functions

func NewErrCloudStorage

func NewErrCloudStorage(message string, kv map[string]interface{}, err error) error

NewErrCloudStorage is return ErrCloudStorage

func NewErrInternalError

func NewErrInternalError(message string, kv map[string]interface{}, err error) error

NewErrInternalError is return ErrInternalError

func NewErrInvalidArgument

func NewErrInvalidArgument(message string, kv map[string]interface{}, err error) error

NewErrInvalidArgument is return InvalidArgument

func NewErrNeedConvert

func NewErrNeedConvert(message string, kv map[string]interface{}) error

NewErrNeedConvert is return ErrNeedConvert

func NewErrNotFound

func NewErrNotFound(key string, err error) error

NewErrNotFound is return ErrNotFound

Types

type Error

type Error struct {
	Code    string
	Message string
	KV      map[string]interface{}
	// contains filtered or unexported fields
}

Error is Error情報を保持する struct

func (*Error) Error

func (e *Error) Error() string

Error is error interface func

func (*Error) Is

func (e *Error) Is(target error) bool

Is is err equal check

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap is return unwrap error

type ImageHandlers

type ImageHandlers struct {
	// contains filtered or unexported fields
}

func NewImageHandlers

func NewImageHandlers(ctx context.Context, basePath string, imageService *ImageService) *ImageHandlers

func (*ImageHandlers) ResizeHandler

func (h *ImageHandlers) ResizeHandler(w http.ResponseWriter, r *http.Request)

type ImageOption

type ImageOption struct {
	Bucket             string
	Object             string
	Size               int
	CacheControlMaxAge int // Pathから指定はできず、App側で指定する
}

func BuildImageOption

func BuildImageOption(path string) (*ImageOption, error)

BuildImageOption is Request URLからImageOptionを生成する App Engine Image Serviceと同じ雰囲気のURLを利用する時に使う

期待する形式 `/{bucket}/{object}` `/{bucket}/{object}/=sXXX`

type ImageService

type ImageService struct {
	// contains filtered or unexported fields
}

func NewImageService

func NewImageService(ctx context.Context, gcs *storage.Client, goma *goma.StorageService, options ...ServiceOption) (*ImageService, error)

func (*ImageService) BucketOfAlteredObject

func (s *ImageService) BucketOfAlteredObject(bucket string) string

BucketOfAlteredObject is 変換後Objectを保存するBucket

func (*ImageService) ExistObject

func (s *ImageService) ExistObject(ctx context.Context, o *ImageOption) (err error)

ExistObject is 指定した Object が Cloud Storage 上に存在するかをチェックする 存在する場合は nil を返し、存在しない場合は NotFound を返す

func (*ImageService) ObjectOfAltered

func (s *ImageService) ObjectOfAltered(object string, size int) string

ObjectOfAltered is 変換後Object Name

func (*ImageService) ReadAndWrite

func (s *ImageService) ReadAndWrite(ctx context.Context, w http.ResponseWriter, o *ImageOption) (err error)

ReadAndWrite is Cloud Storage から読み込んだImageをhttp.ResponseWriterに書き込む gaeimage.ImageOptionにより画像の変換が求められている場合、変換後Object保存用Bucketを参照し、すでにあればそれを書き込む 変換後Object保存用Bucketに変換されたObjectがない場合、変換したImageを作成し、変換後Object保存用Bucketに保存して、それを書き込む

func (*ImageService) ReadAndWriteWithoutResize

func (s *ImageService) ReadAndWriteWithoutResize(ctx context.Context, w http.ResponseWriter, o *ImageOption) (err error)

ReadAndWriteWithoutResize is Cloud Storage から読み込んだ Image を http.ResponseWriter に書き込む ただし、 Image を変換する必要がある場合は、 HOGE を返す そのため、Response に書き込むのはオリジナル画像を返す時か、すでに生成済みの画像を返す時のみ Image 変換処理はある程度メモリを食う処理なので、変換処理だけは別 Instance で行いたい時に使う

func (*ImageService) ResizeToGCS

func (s *ImageService) ResizeToGCS(ctx context.Context, o *ImageOption) (img image.Image, gt *goma.GomaType, err error)

ResizeToGCS is 画像をリサイズしてCloud Storageに保存する

type ServiceOption

type ServiceOption func(*serviceOptions)

func WithAlterBucket

func WithAlterBucket(alterBucket string) ServiceOption

WithAlterBucket is 変換後の画像を保存するBucketを任意の固定したBucketに設定する時に利用する 未指定の場合の default の命名規則は `alter-{original-bucket}`

Jump to

Keyboard shortcuts

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