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: 12 Imported by: 0

Documentation

Index

Constants

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

Variables

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

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

Functions

func ContentTypeToImagingFormat

func ContentTypeToImagingFormat(contentType string) (imaging.Format, error)

func NewErrInvalidArgument

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

NewErrInvalidArgument is return InvalidArgument

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 FormatType

type FormatType int
const (
	Default FormatType = iota
	PNG
	JPEG
)

func (FormatType) ImagingFormat

func (ft FormatType) ImagingFormat() imaging.Format

type ImageMeta

type ImageMeta struct {
	FormatType  FormatType
	ContentType string
}

type ImageService

type ImageService struct {
	GCS *storage.Client
}

func NewImageService

func NewImageService(ctx context.Context, gcs *storage.Client) (*ImageService, error)

func (*ImageService) Read

func (s *ImageService) Read(ctx context.Context, bucket string, object string) (img image.Image, attrs *storage.ObjectAttrs, err error)

func (*ImageService) ResizeToFitLongSide

func (s *ImageService) ResizeToFitLongSide(ctx context.Context, src image.Image, size int) (dst image.Image, err error)

ResizeToFitLongSide is 長辺が指定したサイズになるようにアスペクト比を維持してリサイズする

func (*ImageService) Write

func (s *ImageService) Write(ctx context.Context, bucket string, object string, img image.Image, attrs *storage.ObjectAttrs) (err error)

Write is Cloud Storageに指定したImageを書き込む storage.ObjectAttrsは指定したいものがなければ、ほとんど空で構わないが、ContentTypeは必須

type ResizeHandlers

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

func NewResizeHandlers

func NewResizeHandlers(ctx context.Context, basePath string, alterBucket string, imageService *ImageService) *ResizeHandlers

func (*ResizeHandlers) ResizeHandler

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

ResizeHandler is Pathで指定したCloud Storage上のObjectを指定したサイズにResizeして返す このまま使うこともできるが、Exampleの意味合いが強い

type ResizeRequest

type ResizeRequest struct {
	Bucket string
	Object string
	Size   int
}

func BuildResizeRequest

func BuildResizeRequest(path string) (*ResizeRequest, error)

BuildResizeRequest is Request URLからResizeに必要な情報を生成する App Engine Image Serviceと同じ雰囲気のURLを利用する時に使う

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

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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