hashkey from inspecting raw

This commit is contained in:
Bel LaPointe
2026-02-04 09:02:28 -07:00
parent dd64e959c3
commit 9e0754d92f

View File

@@ -8,30 +8,44 @@ import (
"io"
"log"
"net"
"regexp"
"strconv"
)
func adapt(ctx context.Context, config Config, conn net.Conn) error {
reader := bufio.NewReader(conn)
alpha := regexp.MustCompile(`[a-zA-Z]`)
parts := regexp.MustCompile(`(.*?)\r\n*`)
for ctx.Err() == nil {
if done, err := func() (bool, error) {
raw, message, err := readMessage(reader)
raw, err := readMessage(reader)
if err != nil {
if err == io.EOF {
return true, nil
}
return true, err
}
log.Printf("routing: %q (%+v)", raw, message)
log.Printf("routing: %q", raw)
if len(message) > 0 && message[0].(string) == "COMMAND" {
fmt.Fprintf(conn, "*0\r\n")
} else if len(raw) > 0 && len(message) > 0 {
hashKey := message[0].(string)
if len(message) > 1 {
hashKey = message[1].(string)
if len(raw) > 0 {
hashKey := ""
if matches := parts.FindAllSubmatch(raw, 5); len(matches) > 0 {
for i := range matches {
if isTheCommand := alpha.Match(matches[i][0]); isTheCommand {
for j := i + 1; j < len(matches); j++ {
if matches[j][0][0] == byte('$') {
continue
}
hashKey = string(matches[j][1])
break
}
break
}
}
}
log.Printf("hashkey %q", hashKey)
if err := config.WithConn(hashKey, func(forwardConn net.Conn) error {
//log.Printf("forwarding %q", raw)