github.com/TeaOSLab/EdgeNode@v1.3.8/internal/caches/utils.go (about)

     1  // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  
     3  package caches
     4  
     5  import (
     6  	"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
     7  	"net"
     8  	"strings"
     9  )
    10  
    11  func ParseHost(key string) string {
    12  	var schemeIndex = strings.Index(key, "://")
    13  	if schemeIndex <= 0 {
    14  		return ""
    15  	}
    16  
    17  	var firstSlashIndex = strings.Index(key[schemeIndex+3:], "/")
    18  	if firstSlashIndex <= 0 {
    19  		return ""
    20  	}
    21  
    22  	var host = key[schemeIndex+3 : schemeIndex+3+firstSlashIndex]
    23  
    24  	hostPart, _, err := net.SplitHostPort(host)
    25  	if err == nil && len(hostPart) > 0 {
    26  		host = configutils.QuoteIP(hostPart)
    27  	}
    28  
    29  	return host
    30  }