package node

import (
	"fmt"
	"regexp"
)

const defaultScheme = "etcd:///com.gateway"

var findServerCodeRegexp = regexp.MustCompile(`.*/(.*)@(.*)`)

// createServerRegisterKey 创建ectd注册key内容
func createServerRegisterKey(scheme, serverCode, serverAddr string) string {
	return fmt.Sprintf("%s/%s@%s", scheme, serverCode, serverAddr)
}

// getServerCodeFromKey 从etcd ServerRegisterKey中获取服务code
func getServerCodeFromKey(key string) (serverCode, serverAddr string) {
	strArr := findServerCodeRegexp.FindStringSubmatch(key)
	if len(strArr) == 3 {
		serverCode = strArr[1]
		serverAddr = strArr[2]
	}
	return
}
