modules.go 783 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package nginx
  2. import (
  3. "regexp"
  4. "strings"
  5. )
  6. const (
  7. ModuleStream = "stream_module"
  8. )
  9. func GetModules() (modules []string) {
  10. out := getNginxV()
  11. // Regular expression to find modules in nginx -V output
  12. r := regexp.MustCompile(`--with-([a-zA-Z0-9_-]+)(_module)?`)
  13. // Find all matches
  14. matches := r.FindAllStringSubmatch(out, -1)
  15. // Extract module names from matches
  16. for _, match := range matches {
  17. module := match[1]
  18. // If the module doesn't end with "_module", add it
  19. if !strings.HasSuffix(module, "_module") {
  20. module = module + "_module"
  21. }
  22. modules = append(modules, module)
  23. }
  24. return modules
  25. }
  26. func IsModuleLoaded(module string) bool {
  27. modules := GetModules()
  28. for _, m := range modules {
  29. if m == module {
  30. return true
  31. }
  32. }
  33. return false
  34. }