github.com/gogf/gf/v2@v2.7.4/net/gsvc/gsvc_endpoints.go (about)

     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  
     7  // Package gsvc provides service registry and discovery definition.
     8  package gsvc
     9  
    10  import (
    11  	"github.com/gogf/gf/v2/text/gstr"
    12  )
    13  
    14  // NewEndpoints creates and returns Endpoints from multiple addresses like:
    15  // "192.168.1.100:80,192.168.1.101:80".
    16  func NewEndpoints(addresses string) Endpoints {
    17  	endpoints := make([]Endpoint, 0)
    18  	for _, address := range gstr.SplitAndTrim(addresses, EndpointsDelimiter) {
    19  		endpoints = append(endpoints, NewEndpoint(address))
    20  	}
    21  	return endpoints
    22  }
    23  
    24  // String formats and returns the Endpoints as a string like:
    25  // "192.168.1.100:80,192.168.1.101:80"
    26  func (es Endpoints) String() string {
    27  	var s string
    28  	for _, endpoint := range es {
    29  		if s != "" {
    30  			s += EndpointsDelimiter
    31  		}
    32  		s += endpoint.String()
    33  	}
    34  	return s
    35  }