Documentation ¶
Index ¶
- Constants
- Variables
- func NotFound(w http.ResponseWriter, r *http.Request)
- func NotFoundHandler() http.Handler
- func Run(path string) error
- type Application
- func (a *Application) ImageFileFromRequest(req *Request, async bool, load bool) (*image.ImageFile, error)
- func (a *Application) IsValidSign(qs map[string]string) bool
- func (a *Application) ShardFilename(filename string) string
- func (a *Application) Store(i *image.ImageFile) error
- func (a *Application) WithPrefix(str string) string
- type Handler
- type Initializer
- type KVStoreParameter
- type Request
- type Shard
- type StorageParameter
Constants ¶
View Source
const DefaultContentType = "image/png"
View Source
const DefaultFormat = "png"
View Source
const DefaultPort = 3001
View Source
const DefaultShardDepth = 0
View Source
const DefaultShardWidth = 0
View Source
const Version = "0.1"
Current version of the picfit
Variables ¶
View Source
var App = NewApplication()
View Source
var Initializers = []Initializer{ KVStoreInitializer, StorageInitializer, ShardInitializer, BasicInitializer, SentryInitializer, }
View Source
var KVStores = map[string]KVStoreParameter{ "redis": RedisKVStoreParameter, "cache": CacheKVStoreParameter, }
View Source
var Storages = map[string]StorageParameter{ "http+s3": HTTPS3StorageParameter, "s3": S3StorageParameter, "http+fs": HTTPFileSystemStorageParameter, "fs": FileSystemStorageParameter, }
Functions ¶
func NotFoundHandler ¶
Types ¶
type Application ¶
type Application struct { Prefix string SecretKey string Format string KVStore gokvstores.KVStore SourceStorage gostorages.Storage DestStorage gostorages.Storage Router *mux.Router Shard Shard Raven *raven.Client Logger *logrus.Logger }
func NewApplication ¶
func NewApplication() *Application
func (*Application) ImageFileFromRequest ¶
func (*Application) IsValidSign ¶
func (a *Application) IsValidSign(qs map[string]string) bool
func (*Application) ShardFilename ¶
func (a *Application) ShardFilename(filename string) string
func (*Application) WithPrefix ¶
func (a *Application) WithPrefix(str string) string
type Handler ¶
var GetHandler Handler = func(res muxer.Response, req *Request) { file, err := App.ImageFileFromRequest(req, false, false) util.PanicIf(err) content, err := json.Marshal(map[string]string{ "filename": file.Filename(), "path": file.Path(), "url": file.URL(), }) util.PanicIf(err) res.ContentType("application/json") res.ResponseWriter.Write(content) }
type Initializer ¶
var BasicInitializer Initializer = func(jq *jsonq.JsonQuery) error { format, _ := jq.String("format") if format != "" { App.Format = format } else { App.Format = DefaultFormat } App.SecretKey, _ = jq.String("secret_key") return nil }
var KVStoreInitializer Initializer = func(jq *jsonq.JsonQuery) error { _, err := jq.Object("kvstore") if err != nil { App.KVStore = &dummy.DummyKVStore{} return nil } key, err := jq.String("kvstore", "type") if err != nil { return err } parameter, ok := KVStores[key] if !ok { return fmt.Errorf("KVStore %s does not exist", key) } config, err := jq.Object("kvstore") if err != nil { return err } params := util.MapInterfaceToMapString(config) store, err := parameter(params) if err != nil { return err } App.Prefix = params["prefix"] App.KVStore = store return nil }
var SentryInitializer Initializer = func(jq *jsonq.JsonQuery) error { dsn, err := jq.String("sentry", "dsn") if err != nil { return nil } results, err := jq.Object("sentry", "tags") var tags map[string]string if err != nil { tags = map[string]string{} } else { tags = util.MapInterfaceToMapString(results) } client, err := raven.NewClient(dsn, tags) if err != nil { return err } App.Raven = client return nil }
var ShardInitializer Initializer = func(jq *jsonq.JsonQuery) error { width, err := jq.Int("shard", "width") if err != nil { width = DefaultShardWidth } depth, err := jq.Int("shard", "depth") if err != nil { depth = DefaultShardDepth } App.Shard = Shard{Width: width, Depth: depth} return nil }
var StorageInitializer Initializer = func(jq *jsonq.JsonQuery) error { _, err := jq.Object("storage") if err != nil { App.SourceStorage = &dummy.DummyStorage{} App.DestStorage = &dummy.DummyStorage{} return nil } sourceStorage, err := getStorageFromConfig("src", jq) if err != nil { return err } App.SourceStorage = sourceStorage destStorage, err := getStorageFromConfig("dst", jq) if err != nil { App.DestStorage = sourceStorage } else { App.DestStorage = destStorage } return nil }
type KVStoreParameter ¶
type KVStoreParameter func(params map[string]string) (gokvstores.KVStore, error)
var CacheKVStoreParameter KVStoreParameter = func(params map[string]string) (gokvstores.KVStore, error) { value, ok := params["max_entries"] var maxEntries int if !ok { maxEntries = -1 } else { maxEntries, _ = strconv.Atoi(value) } return gokvstores.NewCacheKVStore(maxEntries), nil }
var RedisKVStoreParameter KVStoreParameter = func(params map[string]string) (gokvstores.KVStore, error) { host := params["host"] password := params["password"] port, _ := strconv.Atoi(params["port"]) db, _ := strconv.Atoi(params["db"]) return gokvstores.NewRedisKVStore(host, port, password, db), nil }
type StorageParameter ¶
type StorageParameter func(params map[string]string) (gostorages.Storage, error)
var FileSystemStorageParameter StorageParameter = func(params map[string]string) (gostorages.Storage, error) { return gostorages.NewFileSystemStorage(params["location"], params["base_url"]), nil }
var HTTPFileSystemStorageParameter StorageParameter = func(params map[string]string) (gostorages.Storage, error) { storage, err := FileSystemStorageParameter(params) if err != nil { return nil, err } if _, ok := params["base_url"]; !ok { return nil, fmt.Errorf("You can't use the http wrapper without setting *base_url* in your config file") } return &http.HTTPStorage{storage}, nil }
var HTTPS3StorageParameter StorageParameter = func(params map[string]string) (gostorages.Storage, error) { storage, err := S3StorageParameter(params) if err != nil { return nil, err } if _, ok := params["base_url"]; !ok { return nil, fmt.Errorf("You can't use the http wrapper without setting *base_url* in your config file") } return &http.HTTPStorage{storage}, nil }
var S3StorageParameter StorageParameter = func(params map[string]string) (gostorages.Storage, error) { ACL, ok := gostorages.ACLs[params["acl"]] if !ok { return nil, fmt.Errorf("The ACL %s does not exist", params["acl"]) } Region, ok := aws.Regions[params["region"]] if !ok { return nil, fmt.Errorf("The Region %s does not exist", params["region"]) } return gostorages.NewS3Storage( params["access_key_id"], params["secret_access_key"], params["bucket_name"], params["location"], Region, ACL, params["base_url"], ), nil }
Click to show internal directories.
Click to hide internal directories.