mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 12:12:40 +02:00
44 lines
971 B
Go
44 lines
971 B
Go
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
|
|
}
|