processing_handler.go -> handlers/processing

This commit is contained in:
Viktor Sokolov
2025-08-26 16:19:41 +02:00
committed by Sergei Aleksandrovich
parent 7aec46f146
commit 8bc70491fb
30 changed files with 1489 additions and 546 deletions

43
semaphores/config.go Normal file
View 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
}