Browse Source

Add config checking; Remove compression config

DarthSim 7 years ago
parent
commit
63eecd3bd3
3 changed files with 29 additions and 6 deletions
  1. 1 2
      README.md
  2. 28 3
      config.go
  3. 0 1
      process.go

+ 1 - 2
README.md

@@ -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
 

+ 28 - 3
config.go

@@ -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)
+	}
 }

+ 0 - 1
process.go

@@ -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,