<commit_before>package fabric

import (
	"context"
	"errors"
	"strings"

	"go.uber.org/zap"
)

var (
	// ErrNoSuchRoute when requests route does not exist
	ErrNoSuchRoute = errors.New("No such route")
	// ErrInvalidCommand when our router doesn't know about this command
	ErrInvalidCommand = errors.New("Invalid command")
)

// RouterProtocol is the selector protocol
type RouterProtocol struct {
	routes map[string][]Protocol
}

// NewRouter returns a new router protocol
func NewRouter() *RouterProtocol {
	return &RouterProtocol{
		routes: map[string][]Protocol{},
	}
}

// Name of the protocol
func (m *RouterProtocol) Name() string {
	return "router"
}

// Handle is the protocol handler for the server
func (m *RouterProtocol) Handle(fn HandlerFunc) HandlerFunc {
	// one time scope setup area for middleware
	return func(ctx context.Context, c Conn) error {
		addr := c.GetAddress()
		lgr := Logger(ctx).With(
			zap.Namespace("protocol:router"),
			zap.String("addr.current", addr.Current()),
			zap.String("addr.params", addr.CurrentParams()),
		)
		lgr.Debug("Reading token")

		// we need to negotiate what they need from us
		// read the next token, which is the request for the next protocol
		pr, err := c.ReadToken()
		if err != nil {
			return err
		}
		lgr.Debug("Read token", zap.String("pr", string(pr)))

		pf := strings.Split(string(pr), " ")
		if len(pf) != 2 {
			return ErrInvalidCommand
		}

		cm := pf[0]
		pm := pf[1]

		switch cm {
		case "SEL":
			lgr.Debug("Handling SEL", zap.String("cm", cm), zap.String("pm", pm))
			return m.handleGet(ctx, c, pm)
		default:
			lgr.Debug("Invalid command", zap.String("cm", cm), zap.String("pm", pm))
			c.Close()
			return ErrInvalidCommand
		}
	}<commit_msg>Add missing pop in router handler<commit_after>package fabric

import (
	"context"
	"errors"
	"strings"

	"go.uber.org/zap"
)

var (
	// ErrNoSuchRoute when requests route does not exist
	ErrNoSuchRoute = errors.New("No such route")
	// ErrInvalidCommand when our router doesn't know about this command
	ErrInvalidCommand = errors.New("Invalid command")
)

// RouterProtocol is the selector protocol
type RouterProtocol struct {
	routes map[string][]Protocol
}

// NewRouter returns a new router protocol
func NewRouter() *RouterProtocol {
	return &RouterProtocol{
		routes: map[string][]Protocol{},
	}
}

// Name of the protocol
func (m *RouterProtocol) Name() string {
	return "router"
}

// Handle is the protocol handler for the server
func (m *RouterProtocol) Handle(fn HandlerFunc) HandlerFunc {
	// one time scope setup area for middleware
	return func(ctx context.Context, c Conn) error {
		addr := c.GetAddress()
		lgr := Logger(ctx).With(
			zap.Namespace("protocol:router"),
			zap.String("addr.current", addr.Current()),
			zap.String("addr.params", addr.CurrentParams()),
		)
		lgr.Debug("Reading token")

		// we need to negotiate what they need from us
		// read the next token, which is the request for the next protocol
		pr, err := c.ReadToken()
		if err != nil {
			return err
		}
		lgr.Debug("Read token", zap.String("pr", string(pr)))

		pf := strings.Split(string(pr), " ")
		if len(pf) != 2 {
			return ErrInvalidCommand
		}

		cm := pf[0]
		pm := pf[1]

		c.GetAddress().Pop()
		switch cm {
		case "SEL":
			lgr.Debug("Handling SEL", zap.String("cm", cm), zap.String("pm", pm))
			return m.handleGet(ctx, c, pm)
		default:
			lgr.Debug("Invalid command", zap.String("cm", cm), zap.String("pm", pm))
			c.Close()
			return ErrInvalidCommand
		}
	}
{'fraction_non_alphanumeric': 0.13840434658278525, 'fraction_numerical': 0.0017157563625965113, 'mean_word_length': 3.8650904033379696, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7276051', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1139, 'n_words': 348}