1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-03 10:43:58 +02:00

Add config checking; Remove compression config

This commit is contained in:
DarthSim 2017-06-27 11:52:54 +03:00
parent e267c0f4ec
commit 63eecd3bd3
3 changed files with 29 additions and 6 deletions

View File

@ -28,8 +28,7 @@ Imgproxy is 12factor-ready and can be configured with env variables:
* IMGPROXY_WRITE_TIMEOUT - the maximum duration (seconds) for writing the response. Default: 10;
* IMGPROXY_MAX_SRC_DIMENSION - the maximum dimension of source image. Images with larger size will be rejected. Default: 4096;
* IMGPROXY_QUALITY - quality of a result image. Default: 80;
* IMGPROXY_COMPRESSION - compression of a result image. Default: 6;
* IMGPROXY_COMPRESSION - GZip compression level. Default: 5;
* IMGPROXY_GZIP_COMPRESSION - GZip compression level. Default: 5;
* IMGPROXY_KEY - hex-encoded key
* IMGPROXY_SALT - hex-encoded salt

View File

@ -66,7 +66,6 @@ type config struct {
MaxSrcDimension int
Quality int
Compression int
GZipCompression int
Key []byte
@ -79,7 +78,6 @@ var conf = config{
WriteTimeout: 10,
MaxSrcDimension: 4096,
Quality: 80,
Compression: 6,
GZipCompression: 5,
}
@ -95,7 +93,6 @@ func init() {
intEnvConfig(&conf.MaxSrcDimension, "IMGPROXY_MAX_SRC_DIMENSION")
intEnvConfig(&conf.Quality, "IMGPROXY_QUALITY")
intEnvConfig(&conf.Compression, "IMGPROXY_COMPRESSION")
intEnvConfig(&conf.GZipCompression, "IMGPROXY_GZIP_COMPRESSION")
hexEnvConfig(&conf.Key, "IMGPROXY_KEY")
@ -110,4 +107,32 @@ func init() {
if len(conf.Salt) == 0 {
log.Fatalln("Salt is not defined")
}
if len(conf.Bind) == 0 {
log.Fatalln("Bind address is not defined")
}
if conf.ReadTimeout <= 0 {
log.Fatalf("Read timeout should be greater than 0, now - %d\n", conf.ReadTimeout)
}
if conf.WriteTimeout <= 0 {
log.Fatalf("Write timeout should be greater than 0, now - %d\n", conf.WriteTimeout)
}
if conf.MaxSrcDimension <= 0 {
log.Fatalf("Max src dimension should be greater than 0, now - %d\n", conf.MaxSrcDimension)
}
if conf.Quality <= 0 {
log.Fatalf("Quality should be greater than 0, now - %d\n", conf.Quality)
} else if conf.Quality > 100 {
log.Fatalf("Quality can't be greater than 100, now - %d\n", conf.Quality)
}
if conf.GZipCompression < 0 {
log.Fatalf("GZip compression should be greater than or quual to 0, now - %d\n", conf.GZipCompression)
} else if conf.GZipCompression > 9 {
log.Fatalf("GZip compression can't be greater than 9, now - %d\n", conf.GZipCompression)
}
}

View File

@ -67,7 +67,6 @@ func processImage(p []byte, po processingOptions) ([]byte, error) {
opts := bimg.Options{
Interpolator: bimg.Bicubic,
Quality: conf.Quality,
Compression: conf.Compression,
Gravity: po.gravity,
Enlarge: po.enlarge,
Type: po.format,