1
0

proxyEndpoint.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package dynamicproxy
  2. import "errors"
  3. /*
  4. ProxyEndpoint.go
  5. author: tobychui
  6. This script handle the proxy endpoint object actions
  7. so proxyEndpoint can be handled like a proper oop object
  8. Most of the functions are implemented in dynamicproxy.go
  9. */
  10. //Get the string version of proxy type
  11. func (ep *ProxyEndpoint) GetProxyTypeString() string {
  12. if ep.ProxyType == ProxyType_Subdomain {
  13. return "subd"
  14. } else if ep.ProxyType == ProxyType_Vdir {
  15. return "vdir"
  16. }
  17. return "unknown"
  18. }
  19. //Update change in the current running proxy endpoint config
  20. func (ep *ProxyEndpoint) UpdateToRuntime() {
  21. if ep.IsVdir() {
  22. ep.parent.ProxyEndpoints.Store(ep.RootOrMatchingDomain, ep)
  23. } else if ep.IsSubDomain() {
  24. ep.parent.SubdomainEndpoint.Store(ep.RootOrMatchingDomain, ep)
  25. }
  26. }
  27. //Return true if the endpoint type is virtual directory
  28. func (ep *ProxyEndpoint) IsVdir() bool {
  29. return ep.ProxyType == ProxyType_Vdir
  30. }
  31. //Return true if the endpoint type is subdomain
  32. func (ep *ProxyEndpoint) IsSubDomain() bool {
  33. return ep.ProxyType == ProxyType_Subdomain
  34. }
  35. //Remove this proxy endpoint from running proxy endpoint list
  36. func (ep *ProxyEndpoint) Remove() error {
  37. //fmt.Println(ptype, key)
  38. if ep.IsVdir() {
  39. ep.parent.ProxyEndpoints.Delete(ep.RootOrMatchingDomain)
  40. return nil
  41. } else if ep.IsSubDomain() {
  42. ep.parent.SubdomainEndpoint.Delete(ep.RootOrMatchingDomain)
  43. return nil
  44. }
  45. return errors.New("invalid or unsupported type")
  46. }
  47. //ProxyEndpoint remove provide global access by key
  48. func (router *Router) RemoveProxyEndpointByRootname(proxyType string, rootnameOrMatchingDomain string) error {
  49. targetEpt, err := router.LoadProxy(proxyType, rootnameOrMatchingDomain)
  50. if err != nil {
  51. return err
  52. }
  53. return targetEpt.Remove()
  54. }