Documentation ¶
Index ¶
- Variables
- func AirbrakeRecoverer(apiKey string) func(http.Handler) http.Handler
- func BucketAddItems(w http.ResponseWriter, r *http.Request)
- func BucketDeleteItem(w http.ResponseWriter, r *http.Request)
- func BucketFetchItem(w http.ResponseWriter, r *http.Request)
- func BucketGetIndex(w http.ResponseWriter, r *http.Request)
- func BucketGetItem(w http.ResponseWriter, r *http.Request)
- func BucketImageUpload(w http.ResponseWriter, r *http.Request)
- func GetImageInfo(w http.ResponseWriter, r *http.Request)
- type Bucket
- func (b *Bucket) AddImage(ctx context.Context, i *Image) (err error)
- func (b *Bucket) AddImages(ctx context.Context, images []*Image) (err error)
- func (b *Bucket) AddImagesFromUrls(ctx context.Context, urls []string) ([]*Image, error)
- func (b *Bucket) DbDelImage(ctx context.Context, key string) (err error)
- func (b *Bucket) DbFindImage(ctx context.Context, key string, optSizing ...*imgry.Sizing) (*Image, error)
- func (b *Bucket) DbIndexKey(imageKey string, optSizing ...*imgry.Sizing) string
- func (b *Bucket) DbSaveImage(ctx context.Context, im *Image, sizing *imgry.Sizing) (err error)
- func (b *Bucket) GetImageSize(ctx context.Context, key string, sizing *imgry.Sizing) (*Image, error)
- func (b *Bucket) ValidID() (bool, error)
- type Config
- type DB
- func (db *DB) Close()
- func (db *DB) Del(key string) (err error)
- func (db *DB) Exists(key string) (bool, error)
- func (db *DB) Get(key string) (val []byte, err error)
- func (db *DB) HGet(key string, dest interface{}) error
- func (db *DB) HSet(key string, src interface{}) error
- func (db *DB) Ping() error
- func (db *DB) Set(key string, obj []byte, expireIn ...time.Duration) (err error)
- type Fetcher
- type FetcherResponse
- type Image
- func (im *Image) IsValidImage() bool
- func (im *Image) LoadImage() (err error)
- func (im *Image) MakeSize(sizing *imgry.Sizing) (*Image, error)
- func (im *Image) MimeType() string
- func (im *Image) Release()
- func (im *Image) SizeIt(sizing *imgry.Sizing) error
- func (im *Image) SrcFileExtension() string
- func (im *Image) SrcFilename() string
- func (im *Image) ValidateKey() error
- type Responder
- type Server
Constants ¶
This section is empty.
Variables ¶
var ( ErrImageNotFound = errors.New("image not found") ErrInvalidBucketID = errors.New("invalid bucket id - must be: [a-z0-9_:-] max-length: 40") BucketIDInvalidator = regexp.MustCompile(`(i?)[^a-z0-9\/_\-:\.]`) )
var ( ErrNoConfigFile = errors.New("no configuration file specified") DefaultConfig = Config{} )
var ( DefaultFetcherThroughput = 100 DefaultFetcherReqNumAttempts = 2 // DefaultFetcherReqTimeout = 60 * time.Second DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0" )
var ( MimeTypes = map[string]string{ "png": "image/png", "jpeg": "image/jpeg", "jpg": "image/jpeg", "bmp": "image/bmp", "bm": "image/bmp", "gif": "image/gif", "ico": "image/x-icon", } ErrInvalidURL = errors.New("invalid url") )
var ( EmptyImageKey = sha1Hash("") ErrInvalidImageKey = errors.New("invalid image key") )
var (
ErrDBGetKey = errors.New("DB: Unable to get the key")
)
Functions ¶
func AirbrakeRecoverer ¶
Airbrake recoverer middleware to capture and report any panics to airbrake.io.
func BucketAddItems ¶
func BucketAddItems(w http.ResponseWriter, r *http.Request)
func BucketDeleteItem ¶
func BucketDeleteItem(w http.ResponseWriter, r *http.Request)
func BucketFetchItem ¶
func BucketFetchItem(w http.ResponseWriter, r *http.Request)
func BucketGetIndex ¶
func BucketGetIndex(w http.ResponseWriter, r *http.Request)
func BucketGetItem ¶
func BucketGetItem(w http.ResponseWriter, r *http.Request)
func BucketImageUpload ¶
func BucketImageUpload(w http.ResponseWriter, r *http.Request)
Image upload to an s3 bucket, respond with a direct url to the uploaded image. Avoid using respond.ApiError() here to prevent any of the responses from being cached.
func GetImageInfo ¶
func GetImageInfo(w http.ResponseWriter, r *http.Request)
TODO: this can be optimized significantly.......... Ping / DecodeConfig ... do we have to use image magick.......?
Types ¶
type Bucket ¶
type Bucket struct {
ID string
}
func (*Bucket) AddImages ¶
TODO: .. how do handle errors here... ? each image would have it's own error .. should we put an Err on each image object...? or return an errList ..
func (*Bucket) AddImagesFromUrls ¶
func (*Bucket) DbDelImage ¶
TODO: should delete on *
func (*Bucket) DbFindImage ¶
func (b *Bucket) DbFindImage(ctx context.Context, key string, optSizing ...*imgry.Sizing) (*Image, error)
Loads the image from our table+data store with optional sizing
func (*Bucket) DbIndexKey ¶
func (*Bucket) DbSaveImage ¶
Persists the image blob in our data store
func (*Bucket) GetImageSize ¶
type Config ¶
type Config struct { Bind string `toml:"bind"` MaxProcs int `toml:"max_procs"` LogLevel string `toml:"log_level"` CacheMaxAge int `toml:"cache_max_age"` TmpDir string `toml:"tmp_dir"` Profiler bool `toml:"profiler"` // [cluster] Cluster struct { LocalNode string `toml:"local_node"` Nodes []string `toml:"nodes"` } `toml:"cluster"` // [limits] Limits struct { // Throttler settings MaxRequests int `toml:"max_requests"` BacklogSize int `toml:"backlog_size"` BacklogTimeoutStr string `toml:"backlog_timeout"` BacklogTimeout time.Duration // Global request timeout RequestTimeoutStr string `toml:"request_timeout"` RequestTimeout time.Duration // Imgry limits MaxFetchers int `toml:"max_fetchers"` MaxImageSizers int `toml:"max_image_sizers"` } `toml:"limits"` // [db] DB struct { RedisUri string `toml:"redis_uri"` } `toml:"db"` // [airbrake] Airbrake struct { ApiKey string `toml:"api_key"` } `toml:"airbrake"` // [chainstore] Chainstore struct { Path string `toml:"path"` MemCacheSize int64 `toml:"mem_cache_size"` DiskCacheSize int64 `toml:"disk_cache_size"` S3Bucket string `toml:"s3_bucket"` S3AccessKey string `toml:"s3_access_key"` S3SecretKey string `toml:"s3_secret_key"` } `toml:"chainstore"` // [statsd] StatsD struct { Enabled bool `toml:"enabled"` Address string `toml:"address"` ServiceName string `toml:"service_name"` } }
func (*Config) GetChainstore ¶
func (cf *Config) GetChainstore() (chainstore.Store, error)
func (*Config) SetupStatsD ¶
type Fetcher ¶
type Fetcher struct { Client *http.Client Transport *http.Transport Throughput int // TODO ReqNumAttempts int HostKeepAlive time.Duration }
func NewFetcher ¶
func NewFetcher() *Fetcher
type FetcherResponse ¶
type Image ¶
type Image struct { Key string `json:"key" redis:"key"` SrcUrl string `json:"src_url" redis:"src"` Width int `json:"width" redis:"w"` Height int `json:"height" redis:"h"` Format string `json:"format" redis:"f"` SizingQuery string `json:"-" redis:"q"` // query from below, for saving Sizing *imgry.Sizing `json:"-" redis:"-"` Data []byte `json:"-" redis:"-"` // contains filtered or unexported fields }
func NewImageFromKey ¶
Hrmm.. how will we generate a Uid if we just have a blob and no srcurl..? perhaps we allow the uid to be like "something.jpg" if they want..? unlikely to be collisions anyways... how to dedupe those..? guess we cant.. only if it was based on blob..
func NewImageFromSrcUrl ¶
func (*Image) IsValidImage ¶
func (*Image) SrcFileExtension ¶
func (*Image) SrcFilename ¶
func (*Image) ValidateKey ¶
type Responder ¶
func NewResponder ¶
func NewResponder() *Responder
func (*Responder) ApiError ¶
func (r *Responder) ApiError(w http.ResponseWriter, status int, err error)
func (*Responder) ImageError ¶
func (r *Responder) ImageError(w http.ResponseWriter, status int, err error)