<commit_before>package tori

import "log"
import "github.com/shiroyuki/re"

type Router struct {
    PriorityList *RecordList
    // the route id-to-route map
    IdToRouteMap map[string](*Route)
    DebugMode    bool
}

func NewRouter() *Router {
    priorityList := &RecordList{}
    idToRouteMap := make(map[string]*Route)

    return &Router{
        PriorityList: priorityList,
        IdToRouteMap: idToRouteMap,
        DebugMode:    false,
    }
}

func (self *Router) Handle(
    id         string,
    method     string,
    pattern    string,
    action     Action,
    reversible bool,
    cacheable  bool,
) {
    _, ok := self.IdToRouteMap[pattern]

    if !ok {
        route := NewRoute(pattern, reversible)

        self.IdToRouteMap[pattern] = route
    }

    self.PriorityList.Append(&Record{
        Id:        id,
        Method:    method,
        Action:    &action,
        Cacheable: cacheable,
    })
}

func (self *Router) Find(method string, path string) (*Record, *re.MultipleResult) {
    if self.DebugMode {
        log.Printf("Incomming request for %s %s\n", method, path)
    }

    r, p := self.PriorityList.Find(method, path)

    if self.DebugMode {
        if r == nil {
            log.Printf("Unable to find the request handler for %s %s\n", method, path)
        }
    }

    return r, p
}<commit_msg>Updated according to the sandbox project.<commit_after>package tori

import "fmt"
import "log"
import "github.com/shiroyuki/re"

type Router struct {
    PriorityList *RecordList
    // the route id-to-route map
    IdToRouteMap map[string](*Route)
    DebugMode    bool
}

func NewRouter() *Router {
    priorityList := &RecordList{}
    idToRouteMap := make(map[string]*Route)

    return &Router{
        PriorityList: priorityList,
        IdToRouteMap: idToRouteMap,
        DebugMode:    false,
    }
}

func (self *Router) Handle(
    id         string,
    method     string,
    pattern    string,
    action     Action,
    reversible bool,
    cacheable  bool,
) {
    self.log(fmt.Sprintf("Preparing to handle route #%s (%s %s)", id, method, pattern))

    _, ok := self.IdToRouteMap[pattern]

    if !ok {
        route := NewRoute(pattern, reversible)

        self.IdToRouteMap[pattern] = route
    }

    self.PriorityList.Append(&Record{
        Id:        id,
        Method:    method,
        Action:    &action,
        Cacheable: cacheable,
    })
}

func (self *Router) Find(method string, path string) (*Record, *re.MultipleResult) {
    self.log(fmt.Sprintf("Incomming request for %s %s\n", method, path))

    r, p := self.PriorityList.Find(method, path)

    if r == nil {
        self.log(fmt.Sprintf("Unable to find the request handler for %s %s\n", method, path))
    }

    return r, p
}

func (self *Router) log(message) {
    if !self.DebugMode {
        return
    }

    log.Println(message)
}
{'fraction_non_alphanumeric': 0.11498257839721254, 'fraction_numerical': 0.0, 'mean_word_length': 2.369718309859155, 'pattern_counts': {'":': 0, '<': 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': '4682049', 'n_tokens_mistral': 931, 'n_tokens_neox': 906, 'n_words': 239}