// BuildUrl builds the target host string taking into account region and edge configurations.
BuildUrl builds the target host string taking into account region and edge configurations.
// BuildUrl builds the target host string taking into account region and edge configurations .
func (c *RequestHandler) BuildUrl(rawURL string) string {
	u, _ := url.Parse(rawURL)
	var (
		edge    = ""
		region  = ""
		pieces  = strings.Split(u.Host, ".")
		product = pieces[0]
		result  []string
	)
	suffix := ""
	if len(pieces) >= 3 {
		suffix = strings.Join(pieces[len(pieces)-2:], ".")
	} else {
		return u.String()
	}
	if len(pieces) == 4 {
		region = pieces[1]
	} else if len(pieces) == 5 {
		edge = pieces[1]
		region = pieces[2]
	}
	if c.Edge != "" {
		edge = c.Edge
	}
	if c.Region != "" {
		region = c.Region
	} else if region == "" && edge != "" {
		region = "us1"
	}
	for _, item := range []string{product, edge, region, suffix} {
		if item != "" {
			result = append(result, item)
		}
	}
	u.Host = strings.Join(result, ".")
	return u.String()
}
func ( c * RequestHandler ) BuildUrl ( rawURL string ) string { u , _ := url . Parse ( rawURL ) var ( edge = " " region = " " pieces = strings . Split ( u . Host , " " ) product = pieces [ 0 ] result [ ] string ) suffix := " " if len ( pieces ) >= 3 { suffix = strings . Join ( pieces [ len ( pieces ) - 2 : ] , " " ) } else { return u . String ( ) } if len ( pieces ) == 4 { region = pieces [ 1 ] } else if len ( pieces ) == 5 { edge = pieces [ 1 ] region = pieces [ 2 ] } if c . Edge != " " { edge = c . Edge } if c . Region != " " { region = c . Region } else if region == " " && edge != " " { region = " " } for _ , item := range [ ] string { product , edge , region , suffix } { if item != " " { result = append ( result , item ) } } u . Host = strings . Join ( result , " " ) return u . String ( ) }
BuildUrl builds the target host string taking into account region and edge configurations.
BuildUrl builds the target host string taking into account region and edge configurations .
// product.region.twilio.com // product.edge.region.twilio.com