Documentation
¶
Index ¶
- type KimgBaseLogger
- type KimgBaseStorage
- type KimgCache
- type KimgConfig
- type KimgContext
- func (ctx *KimgContext) DeleteImage(md5Sum string) error
- func (ctx *KimgContext) GetImage(req *KimgRequest) ([]byte, error)
- func (ctx *KimgContext) InfoImage(req *KimgRequest) (*KimgResponse, error)
- func (ctx *KimgContext) Release()
- func (ctx *KimgContext) SaveImage(data []byte) (*KimgResponse, error)
- func (ctx *KimgContext) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type KimgImagick
- type KimgLogger
- type KimgRequest
- type KimgResponse
- type KimgStorage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KimgBaseLogger ¶
type KimgBaseLogger struct {
// contains filtered or unexported fields
}
KimgBaseLogger base logger struct hold golang logger.
func (*KimgBaseLogger) Debug ¶
func (logger *KimgBaseLogger) Debug(format string, v ...interface{})
Debug log
func (*KimgBaseLogger) Error ¶
func (logger *KimgBaseLogger) Error(format string, v ...interface{})
Error log
func (*KimgBaseLogger) Info ¶
func (logger *KimgBaseLogger) Info(format string, v ...interface{})
Info log
func (*KimgBaseLogger) Warn ¶
func (logger *KimgBaseLogger) Warn(format string, v ...interface{})
Warn log
type KimgBaseStorage ¶
type KimgBaseStorage struct {
// contains filtered or unexported fields
}
KimgBaseStorage base storage struct hold kimg context.
func (*KimgBaseStorage) Debug ¶
func (storage *KimgBaseStorage) Debug(format string, v ...interface{})
Debug log
func (*KimgBaseStorage) Error ¶
func (storage *KimgBaseStorage) Error(format string, v ...interface{})
Error log
func (*KimgBaseStorage) Info ¶
func (storage *KimgBaseStorage) Info(format string, v ...interface{})
Info log
func (*KimgBaseStorage) Warn ¶
func (storage *KimgBaseStorage) Warn(format string, v ...interface{})
Warn log
type KimgCache ¶
type KimgCache interface {
Set(key string, data []byte) error
Get(key string) ([]byte, error)
Del(key string) error
}
KimgCache is a interface to provide cache in kimg.
func NewKimgCache ¶
func NewKimgCache(config *KimgConfig) (KimgCache, error)
NewKimgCache create a cache instance according to cache mode in config.
func NewKimgMemcacheCache ¶
func NewKimgMemcacheCache(config *KimgConfig) (KimgCache, error)
NewKimgMemcacheCache create a memcache cache instance.
func NewKimgMemoryCache ¶ added in v0.2.0
func NewKimgMemoryCache(config *KimgConfig) (KimgCache, error)
NewKimgMemoryCache create a memory cache instance.
func NewKimgRedisCache ¶
func NewKimgRedisCache(config *KimgConfig) (KimgCache, error)
NewKimgRedisCache create a redis cache instance.
type KimgConfig ¶
type KimgConfig struct {
Httpd struct {
Bind string `yaml:"bind,omitempty"`
URL string `yaml:"url,omitempty"`
Headers map[string]string `yaml:"headers,omitempty"`
Etag bool `yaml:"etag,omitempty"`
MaxAge int `yaml:"maxAge,omitempty"`
FormName string `yaml:"formName,omitempty"`
MaxSize int64 `yaml:"maxSize,omitempty"`
EnableWeb bool `yaml:"enableWeb,omitempty"`
} `yaml:"httpd,omitempty"`
Image struct {
Format string `yaml:"format,omitempty"`
Quality int `yaml:"quality,omitempty"`
AllowedTypes []string `yaml:"allowedTypes,omitempty"`
} `yaml:"image,omitempty"`
Logger struct {
Mode string `yaml:"mode,omitempty"`
Level string `yaml:"level,omitempty"`
File string `yaml:"file,omitempty"`
} `yaml:"logger,omitempty"`
Cache struct {
Mode string `yaml:"mode,omitempty"`
MaxSize int `yaml:"maxSize,omitempty"`
Memcache struct {
URL string `yaml:"url,omitempty"`
} `yaml:"memcache,omitempty"`
Redis struct {
URL string `yaml:"url,omitempty"`
} `yaml:"redis,omitempty"`
Memory struct {
Capacity int64 `yaml:"capacity,omitempty"`
} `yaml:"memory,omitempty"`
} `yaml:"cache,omitempty"`
Storage struct {
Mode string `yaml:"mode,omitempty"`
SaveNew bool `yaml:"saveNew,omitempty"`
File struct {
Root string `yaml:"root,omitempty"`
} `yaml:"file,omitempty"`
Minio struct {
Endpoint string `yaml:"endpoint,omitempty"`
AccessKeyID string `yaml:"accessKeyId,omitempty"`
SecretAccessKey string `yaml:"secretAccessKey,omitempty"`
Bucket string `yaml:"bucket,omitempty"`
UseSSL bool `yaml:"useSSL,omitempty"`
} `yaml:"minio,omitempty"`
} `yaml:"storage,omitempty"`
Watermark struct {
Enable bool `yaml:"enable,omitempty"`
Gravity string `yaml:"gravity,omitempty"`
X int `yaml:"x,omitempty"`
Y int `yaml:"y,omitempty"`
Rotate int `yaml:"rotate,omitempty"`
Opacity int `yaml:"opacity,omitempty"`
Text struct {
Content string `yaml:"content,omitempty"`
FontName string `yaml:"fontName,omitempty"`
FontSize int `yaml:"fontSize,omitempty"`
FontColor string `yaml:"fontColor,omitempty"`
StrokeColor string `yaml:"strokeColor,omitempty"`
StrokeWidth int `yaml:"strokeWidth,omitempty"`
} `yaml:"text,omitempty"`
Logo struct {
File string `yaml:"file,omitempty"`
W int `yaml:"w,omitempty"`
H int `yaml:"h,omitempty"`
} `yaml:"logo,omitempty"`
} `yaml:"watermark,omitempty"`
}
KimgConfig is configuration of kimg.
func NewKimgConfig ¶
func NewKimgConfig(configFile string) (*KimgConfig, error)
NewKimgConfig create a config instance from config file.
type KimgContext ¶
type KimgContext struct {
Config *KimgConfig
Cache KimgCache
Logger KimgLogger
Storage KimgStorage
Image *KimgImagick
}
KimgContext context of kimg.
func NewKimgContext ¶
func NewKimgContext(configFile string) (*KimgContext, error)
NewKimgContext create a instance of kimg context.
func (*KimgContext) DeleteImage ¶
func (ctx *KimgContext) DeleteImage(md5Sum string) error
DeleteImage delete a image from kimg according the md5 key.
func (*KimgContext) GetImage ¶
func (ctx *KimgContext) GetImage(req *KimgRequest) ([]byte, error)
GetImage get a image data from kimg according to a image request.
func (*KimgContext) InfoImage ¶
func (ctx *KimgContext) InfoImage(req *KimgRequest) (*KimgResponse, error)
InfoImage get a image information according the md5 key and make a image response.
func (*KimgContext) Release ¶
func (ctx *KimgContext) Release()
Release release resource in kimg context.
func (*KimgContext) SaveImage ¶
func (ctx *KimgContext) SaveImage(data []byte) (*KimgResponse, error)
SaveImage save a image to kimg and make a kimg response.
func (*KimgContext) ServeHTTP ¶
func (ctx *KimgContext) ServeHTTP(w http.ResponseWriter, r *http.Request)
type KimgImagick ¶
type KimgImagick struct {
// contains filtered or unexported fields
}
KimgImagick image processor struct hold kimg context.
func NewKimgImagick ¶
func NewKimgImagick(ctx *KimgContext) *KimgImagick
NewKimgImagick create a image processor instance and initialize imagick.
func (*KimgImagick) Convert ¶
func (image *KimgImagick) Convert(data []byte, req KimgRequest) ([]byte, error)
Convert convert a image according kimg request and return new image data.
func (*KimgImagick) Info ¶
func (image *KimgImagick) Info(req *KimgRequest, data []byte) (*KimgResponse, error)
Info get a image information and return a kimg response.
type KimgLogger ¶
type KimgLogger interface {
Debug(format string, v ...interface{})
Info(format string, v ...interface{})
Warn(format string, v ...interface{})
Error(format string, v ...interface{})
}
KimgLogger is a interface to provide logger in kimg.
func NewKimgConsoleLogger ¶
func NewKimgConsoleLogger(config *KimgConfig) (KimgLogger, error)
NewKimgConsoleLogger create a console logger instance.
func NewKimgFileLogger ¶
func NewKimgFileLogger(config *KimgConfig) (KimgLogger, error)
NewKimgFileLogger create a file based logger instance.
func NewKimgLogger ¶
func NewKimgLogger(config *KimgConfig) (KimgLogger, error)
NewKimgLogger create a logger instance according to logger mode in config.
type KimgRequest ¶
type KimgRequest struct {
Md5 string `json:"-"`
Origin bool `json:"-"`
Style string `json:"-"`
Save bool `json:"-"`
// scale params
Scale bool `json:"scale,omitempty"`
ScaleM string `json:"scale_m,omitempty"`
ScaleW int `json:"scale_w,omitempty"`
ScaleH int `json:"scale_h,omitempty"`
ScaleWP int `json:"scale_wp,omitempty"`
ScaleHP int `json:"scale_hp,omitempty"`
ScaleP int `json:"scale_p,omitempty"`
// crop params
Crop bool `json:"crop,omitempty"`
Gravity string `json:"gravity,omitempty"`
CropW int `json:"crop_w,omitempty"`
CropH int `json:"crop_h,omitempty"`
Offset string `json:"offset,omitempty"`
OffsetX int `json:"offset_x,omitempty"`
OffsetY int `json:"offset_y,omitempty"`
Format string `json:"format,omitempty"`
Quality int `json:"quality,omitempty"`
Rotate int `json:"rotate,omitempty"`
BGColor string `json:"bg_color,omitempty"`
Gray bool `json:"gray,omitempty"`
AutoOrient bool `json:"auto_orient,omitempty"`
Strip bool `json:"strip,omitempty"`
}
KimgRequest define a image request.
func (*KimgRequest) Key ¶
func (req *KimgRequest) Key() string
Key generate a key according to image style request params.
type KimgResponse ¶
type KimgResponse struct {
Md5 string `json:"md5"`
URL string `json:"url"`
Style string `json:"style,omitempty"`
Size int `json:"size"`
Width int `json:"width"`
Height int `json:"height"`
Format string `json:"format"`
Orientation string `json:"orientation"`
Exif map[string]string `json:"exif"`
}
KimgResponse define a image response.
type KimgStorage ¶
type KimgStorage interface {
Set(req *KimgRequest, data []byte) error
Get(req *KimgRequest) ([]byte, error)
Del(req *KimgRequest) error
}
KimgStorage is a interface to provide storage in kimg.
func NewKimgFileStorage ¶
func NewKimgFileStorage(ctx *KimgContext) (KimgStorage, error)
NewKimgFileStorage create a file based storage instance.
func NewKimgMinioStorage ¶ added in v0.9.0
func NewKimgMinioStorage(ctx *KimgContext) (KimgStorage, error)
NewKimgMinioStorage create a minio based storage instance.
func NewKimgStorage ¶
func NewKimgStorage(ctx *KimgContext) (KimgStorage, error)
NewKimgStorage create a storage instance according to storage mode in config.