|
|
|
@ -25,19 +25,14 @@ func formatName(name string) string {
|
|
|
|
|
// formatSelector formats a gopher line selector string
|
|
|
|
|
func formatSelector(selector string) string {
|
|
|
|
|
if len(selector) > maxSelectorLen {
|
|
|
|
|
return errorSelector + "\t"
|
|
|
|
|
return errorSelector
|
|
|
|
|
}
|
|
|
|
|
return selector + "\t"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// formatHostPort formats a gopher line host + port
|
|
|
|
|
func formatHostPort(host, port string) string {
|
|
|
|
|
return host + "\t" + port
|
|
|
|
|
return selector
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// replacePlacementStrs replaces any placement strings found in the line (e.g $hostname, $port)
|
|
|
|
|
func replacePlacementStrs(line string) string {
|
|
|
|
|
split := strings.Split(line, "\t")
|
|
|
|
|
split := strings.SplitN(line, "\t", 4)
|
|
|
|
|
|
|
|
|
|
// Either invalid line, or information line without host + port
|
|
|
|
|
if len(split) != 4 {
|
|
|
|
@ -53,12 +48,12 @@ func replacePlacementStrs(line string) string {
|
|
|
|
|
|
|
|
|
|
// buildLine builds a gopher line string
|
|
|
|
|
func buildLine(t ItemType, name, selector, host, port string) []byte {
|
|
|
|
|
return []byte(string(t) + formatName(name) + formatSelector(selector) + formatHostPort(host, port) + "\r\n")
|
|
|
|
|
return []byte(string(t) + formatName(name) + formatSelector(selector) + "\t" + host + "\t" + port + "\r\n")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// buildInfoLine builds a gopher info line string
|
|
|
|
|
func buildInfoLine(line string) []byte {
|
|
|
|
|
return []byte(string(typeInfo) + formatName(line) + formatHostPort(nullHost, nullPort) + "\r\n")
|
|
|
|
|
return []byte(string(typeInfo) + formatName(line) + "\t" + nullHost + "\t" + nullPort + "\r\n")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// buildErrorLine builds a gopher error line string
|
|
|
|
|