mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-09 19:52:30 +02:00
processing_handler.go -> handlers/processing
This commit is contained in:
committed by
Sergei Aleksandrovich
parent
7aec46f146
commit
8bc70491fb
43
semaphores/config.go
Normal file
43
semaphores/config.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package semaphores
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
)
|
||||
|
||||
// Config represents handler config
|
||||
type Config struct {
|
||||
RequestsQueueSize int // Request queue size
|
||||
Workers int // Number of workers
|
||||
}
|
||||
|
||||
// NewDefaultConfig creates a new configuration with defaults
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
RequestsQueueSize: 0,
|
||||
Workers: runtime.GOMAXPROCS(0) * 2,
|
||||
}
|
||||
}
|
||||
|
||||
// LoadFromEnv loads config from environment variables
|
||||
func LoadFromEnv(c *Config) (*Config, error) {
|
||||
c.RequestsQueueSize = config.RequestsQueueSize
|
||||
c.Workers = config.Workers
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Validate checks configuration values
|
||||
func (c *Config) Validate() error {
|
||||
if c.RequestsQueueSize < 0 {
|
||||
return fmt.Errorf("requests queue size should be greater than or equal 0, now - %d", c.RequestsQueueSize)
|
||||
}
|
||||
|
||||
if c.Workers <= 0 {
|
||||
return fmt.Errorf("workers number should be greater than 0, now - %d", c.Workers)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user