gsvc_endpoints.go 1008 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. // Package gsvc provides service registry and discovery definition.
  7. package gsvc
  8. import (
  9. "github.com/gogf/gf/v2/text/gstr"
  10. )
  11. // NewEndpoints creates and returns Endpoints from multiple addresses like:
  12. // "192.168.1.100:80,192.168.1.101:80".
  13. func NewEndpoints(addresses string) Endpoints {
  14. endpoints := make([]Endpoint, 0)
  15. for _, address := range gstr.SplitAndTrim(addresses, endpointsDelimiter) {
  16. endpoints = append(endpoints, NewEndpoint(address))
  17. }
  18. return endpoints
  19. }
  20. // String formats and returns the Endpoints as a string like:
  21. // "192.168.1.100:80,192.168.1.101:80"
  22. func (es Endpoints) String() string {
  23. var s string
  24. for _, endpoint := range es {
  25. if s != "" {
  26. s += endpointsDelimiter
  27. }
  28. s += endpoint.String()
  29. }
  30. return s
  31. }