options.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package frankenphp
  2. import (
  3. "go.uber.org/zap"
  4. )
  5. // Option instances allow to configure FrankenPHP.
  6. type Option func(h *opt) error
  7. // opt contains the available options.
  8. //
  9. // If you change this, also update the Caddy module and the documentation.
  10. type opt struct {
  11. numThreads int
  12. workers []workerOpt
  13. logger *zap.Logger
  14. metrics Metrics
  15. }
  16. type workerOpt struct {
  17. fileName string
  18. num int
  19. env PreparedEnv
  20. watch []string
  21. }
  22. // WithNumThreads configures the number of PHP threads to start.
  23. func WithNumThreads(numThreads int) Option {
  24. return func(o *opt) error {
  25. o.numThreads = numThreads
  26. return nil
  27. }
  28. }
  29. func WithMetrics(m Metrics) Option {
  30. return func(o *opt) error {
  31. o.metrics = m
  32. return nil
  33. }
  34. }
  35. // WithWorkers configures the PHP workers to start.
  36. func WithWorkers(fileName string, num int, env map[string]string, watch []string) Option {
  37. return func(o *opt) error {
  38. o.workers = append(o.workers, workerOpt{fileName, num, PrepareEnv(env), watch})
  39. return nil
  40. }
  41. }
  42. // WithLogger configures the global logger to use.
  43. func WithLogger(l *zap.Logger) Option {
  44. return func(o *opt) error {
  45. o.logger = l
  46. return nil
  47. }
  48. }