manager.go 762 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package nginx
  2. import (
  3. "nginx-ui/server/models"
  4. )
  5. var INSTANCES = map[int]*Instance{}
  6. func GetInstance(nginx *models.Nginx) *Instance {
  7. var instance *Instance = INSTANCES[nginx.Id]
  8. if instance != nil {
  9. old := instance.nginx
  10. if old.IpAddr != nginx.IpAddr || old.Port != nginx.Port || old.User != nginx.User || old.Password != nginx.Password {
  11. instance.Close(false)
  12. instance = nil
  13. INSTANCES[nginx.Id] = nil
  14. } else {
  15. instance.nginx = nginx
  16. instance.SetNginx(nginx)
  17. return instance
  18. }
  19. }
  20. if nginx.IsLocal {
  21. instance = &Instance{
  22. &LocalInstance{
  23. nginx: nginx,
  24. },
  25. nginx,
  26. }
  27. } else {
  28. instance = &Instance{
  29. &RemoteInstance{
  30. nginx: nginx,
  31. },
  32. nginx,
  33. }
  34. }
  35. INSTANCES[nginx.Id] = instance
  36. return instance
  37. }